Upstream version 7.35.139.0
[platform/framework/web/crosswalk.git] / src / v8 / src / runtime.h
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 //     * Redistributions of source code must retain the above copyright
7 //       notice, this list of conditions and the following disclaimer.
8 //     * Redistributions in binary form must reproduce the above
9 //       copyright notice, this list of conditions and the following
10 //       disclaimer in the documentation and/or other materials provided
11 //       with the distribution.
12 //     * Neither the name of Google Inc. nor the names of its
13 //       contributors may be used to endorse or promote products derived
14 //       from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 #ifndef V8_RUNTIME_H_
29 #define V8_RUNTIME_H_
30
31 #include "allocation.h"
32 #include "zone.h"
33
34 namespace v8 {
35 namespace internal {
36
37 // The interface to C++ runtime functions.
38
39 // ----------------------------------------------------------------------------
40 // RUNTIME_FUNCTION_LIST_ALWAYS defines runtime calls available in both
41 // release and debug mode.
42 // This macro should only be used by the macro RUNTIME_FUNCTION_LIST.
43
44 // WARNING: RUNTIME_FUNCTION_LIST_ALWAYS_* is a very large macro that caused
45 // MSVC Intellisense to crash.  It was broken into two macros to work around
46 // this problem. Please avoid large recursive macros whenever possible.
47 #define RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
48   /* Property access */ \
49   F(GetProperty, 2, 1) \
50   F(KeyedGetProperty, 2, 1) \
51   F(DeleteProperty, 3, 1) \
52   F(HasLocalProperty, 2, 1) \
53   F(HasProperty, 2, 1) \
54   F(HasElement, 2, 1) \
55   F(IsPropertyEnumerable, 2, 1) \
56   F(GetPropertyNames, 1, 1) \
57   F(GetPropertyNamesFast, 1, 1) \
58   F(GetLocalPropertyNames, 2, 1) \
59   F(GetLocalElementNames, 1, 1) \
60   F(GetInterceptorInfo, 1, 1) \
61   F(GetNamedInterceptorPropertyNames, 1, 1) \
62   F(GetIndexedInterceptorElementNames, 1, 1) \
63   F(GetArgumentsProperty, 1, 1) \
64   F(ToFastProperties, 1, 1) \
65   F(FinishArrayPrototypeSetup, 1, 1) \
66   F(SpecialArrayFunctions, 1, 1) \
67   F(IsSloppyModeFunction, 1, 1) \
68   F(GetDefaultReceiver, 1, 1) \
69   \
70   F(GetPrototype, 1, 1) \
71   F(SetPrototype, 2, 1) \
72   F(IsInPrototypeChain, 2, 1) \
73   \
74   F(GetOwnProperty, 2, 1) \
75   \
76   F(IsExtensible, 1, 1) \
77   F(PreventExtensions, 1, 1)\
78   \
79   /* Utilities */ \
80   F(CheckIsBootstrapping, 0, 1) \
81   F(GetRootNaN, 0, 1) \
82   F(Call, -1 /* >= 2 */, 1) \
83   F(Apply, 5, 1) \
84   F(GetFunctionDelegate, 1, 1) \
85   F(GetConstructorDelegate, 1, 1) \
86   F(DeoptimizeFunction, 1, 1) \
87   F(ClearFunctionTypeFeedback, 1, 1) \
88   F(RunningInSimulator, 0, 1) \
89   F(IsConcurrentRecompilationSupported, 0, 1) \
90   F(OptimizeFunctionOnNextCall, -1, 1) \
91   F(NeverOptimizeFunction, 1, 1) \
92   F(GetOptimizationStatus, -1, 1) \
93   F(GetOptimizationCount, 1, 1) \
94   F(UnblockConcurrentRecompilation, 0, 1) \
95   F(CompileForOnStackReplacement, 1, 1) \
96   F(SetAllocationTimeout, -1 /* 2 || 3 */, 1) \
97   F(SetNativeFlag, 1, 1) \
98   F(SetInlineBuiltinFlag, 1, 1) \
99   F(StoreArrayLiteralElement, 5, 1) \
100   F(DebugCallbackSupportsStepping, 1, 1) \
101   F(DebugPrepareStepInIfStepping, 1, 1) \
102   F(FlattenString, 1, 1) \
103   F(TryMigrateInstance, 1, 1) \
104   F(NotifyContextDisposed, 0, 1) \
105   \
106   /* Array join support */ \
107   F(PushIfAbsent, 2, 1) \
108   F(ArrayConcat, 1, 1) \
109   \
110   /* Conversions */ \
111   F(ToBool, 1, 1) \
112   F(Typeof, 1, 1) \
113   \
114   F(StringToNumber, 1, 1) \
115   F(StringParseInt, 2, 1) \
116   F(StringParseFloat, 1, 1) \
117   F(StringToLowerCase, 1, 1) \
118   F(StringToUpperCase, 1, 1) \
119   F(StringSplit, 3, 1) \
120   F(CharFromCode, 1, 1) \
121   F(URIEscape, 1, 1) \
122   F(URIUnescape, 1, 1) \
123   \
124   F(NumberToInteger, 1, 1) \
125   F(NumberToIntegerMapMinusZero, 1, 1) \
126   F(NumberToJSUint32, 1, 1) \
127   F(NumberToJSInt32, 1, 1) \
128   \
129   /* Arithmetic operations */ \
130   F(NumberAdd, 2, 1) \
131   F(NumberSub, 2, 1) \
132   F(NumberMul, 2, 1) \
133   F(NumberDiv, 2, 1) \
134   F(NumberMod, 2, 1) \
135   F(NumberUnaryMinus, 1, 1) \
136   F(NumberAlloc, 0, 1) \
137   F(NumberImul, 2, 1) \
138   \
139   F(StringBuilderConcat, 3, 1) \
140   F(StringBuilderJoin, 3, 1) \
141   F(SparseJoinWithSeparator, 3, 1) \
142   \
143   /* Bit operations */ \
144   F(NumberOr, 2, 1) \
145   F(NumberAnd, 2, 1) \
146   F(NumberXor, 2, 1) \
147   \
148   F(NumberShl, 2, 1) \
149   F(NumberShr, 2, 1) \
150   F(NumberSar, 2, 1) \
151   \
152   /* Comparisons */ \
153   F(NumberEquals, 2, 1) \
154   F(StringEquals, 2, 1) \
155   \
156   F(NumberCompare, 3, 1) \
157   F(SmiLexicographicCompare, 2, 1) \
158   \
159   /* Math */ \
160   F(Math_acos, 1, 1) \
161   F(Math_asin, 1, 1) \
162   F(Math_atan, 1, 1) \
163   F(Math_log, 1, 1) \
164   F(Math_sqrt, 1, 1) \
165   F(Math_exp, 1, 1) \
166   F(Math_floor, 1, 1) \
167   F(Math_pow, 2, 1) \
168   F(Math_pow_cfunction, 2, 1) \
169   F(Math_atan2, 2, 1) \
170   F(RoundNumber, 1, 1) \
171   F(Math_fround, 1, 1) \
172   \
173   /* Float32x4 and Int32x4 */ \
174   F(AllocateFloat32x4, 0, 1) \
175   F(AllocateInt32x4, 0, 1) \
176   \
177   /* SIMD */ \
178   F(Float32x4Abs, 1, 1) \
179   F(Float32x4BitsToInt32x4, 1, 1) \
180   F(Float32x4Neg, 1, 1) \
181   F(Float32x4Reciprocal, 1, 1) \
182   F(Float32x4ReciprocalSqrt, 1, 1) \
183   F(Float32x4Sqrt, 1, 1) \
184   F(Float32x4ToInt32x4, 1, 1) \
185   F(Float32x4Add, 2, 1) \
186   F(Float32x4Div, 2, 1) \
187   F(Float32x4Max, 2, 1) \
188   F(Float32x4Min, 2, 1) \
189   F(Float32x4Mul, 2, 1) \
190   F(Float32x4Sub, 2, 1) \
191   F(Float32x4Equal, 2, 1) \
192   F(Float32x4NotEqual, 2, 1) \
193   F(Float32x4GreaterThanOrEqual, 2, 1) \
194   F(Float32x4GreaterThan, 2, 1) \
195   F(Float32x4LessThan, 2, 1) \
196   F(Float32x4LessThanOrEqual, 2, 1) \
197   F(Float32x4Shuffle, 2, 1) \
198   F(Float32x4Scale, 2, 1) \
199   F(Float32x4WithX, 2, 1) \
200   F(Float32x4WithY, 2, 1) \
201   F(Float32x4WithZ, 2, 1) \
202   F(Float32x4WithW, 2, 1) \
203   F(Float32x4Clamp, 3, 1) \
204   F(Float32x4ShuffleMix, 3, 1) \
205   F(Int32x4BitsToFloat32x4, 1, 1) \
206   F(Int32x4Neg, 1, 1) \
207   F(Int32x4Not, 1, 1) \
208   F(Int32x4ToFloat32x4, 1, 1) \
209   F(Int32x4And, 2, 1) \
210   F(Int32x4Or, 2, 1) \
211   F(Int32x4Xor, 2, 1) \
212   F(Int32x4Add, 2, 1) \
213   F(Int32x4Sub, 2, 1) \
214   F(Int32x4Mul, 2, 1) \
215   F(Int32x4Shuffle, 2, 1) \
216   F(Int32x4WithX, 2, 1) \
217   F(Int32x4WithY, 2, 1) \
218   F(Int32x4WithZ, 2, 1) \
219   F(Int32x4WithW, 2, 1) \
220   F(Int32x4WithFlagX, 2, 1) \
221   F(Int32x4WithFlagY, 2, 1) \
222   F(Int32x4WithFlagZ, 2, 1) \
223   F(Int32x4WithFlagW, 2, 1) \
224   F(Int32x4GreaterThan, 2, 1) \
225   F(Int32x4Equal, 2, 1) \
226   F(Int32x4LessThan, 2, 1) \
227   F(Int32x4Select, 3, 1) \
228   \
229   /* Regular expressions */ \
230   F(RegExpCompile, 3, 1) \
231   F(RegExpExecMultiple, 4, 1) \
232   F(RegExpInitializeObject, 5, 1) \
233   \
234   /* JSON */ \
235   F(ParseJson, 1, 1) \
236   F(BasicJSONStringify, 1, 1) \
237   F(QuoteJSONString, 1, 1) \
238   \
239   /* Strings */ \
240   F(StringIndexOf, 3, 1) \
241   F(StringLastIndexOf, 3, 1) \
242   F(StringLocaleCompare, 2, 1) \
243   F(StringReplaceGlobalRegExpWithString, 4, 1) \
244   F(StringReplaceOneCharWithString, 3, 1) \
245   F(StringMatch, 3, 1) \
246   F(StringTrim, 3, 1) \
247   F(StringToArray, 2, 1) \
248   F(NewStringWrapper, 1, 1) \
249   F(NewString, 2, 1) \
250   F(TruncateString, 2, 1) \
251   \
252   /* Numbers */ \
253   F(NumberToRadixString, 2, 1) \
254   F(NumberToFixed, 2, 1) \
255   F(NumberToExponential, 2, 1) \
256   F(NumberToPrecision, 2, 1) \
257   F(IsValidSmi, 1, 1)
258
259
260 #define RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
261   /* Reflection */ \
262   F(FunctionSetInstanceClassName, 2, 1) \
263   F(FunctionSetLength, 2, 1) \
264   F(FunctionSetPrototype, 2, 1) \
265   F(FunctionSetReadOnlyPrototype, 1, 1) \
266   F(FunctionGetName, 1, 1) \
267   F(FunctionSetName, 2, 1) \
268   F(FunctionNameShouldPrintAsAnonymous, 1, 1) \
269   F(FunctionMarkNameShouldPrintAsAnonymous, 1, 1) \
270   F(FunctionIsGenerator, 1, 1) \
271   F(FunctionBindArguments, 4, 1) \
272   F(BoundFunctionGetBindings, 1, 1) \
273   F(FunctionRemovePrototype, 1, 1) \
274   F(FunctionGetSourceCode, 1, 1) \
275   F(FunctionGetScript, 1, 1) \
276   F(FunctionGetScriptSourcePosition, 1, 1) \
277   F(FunctionGetPositionForOffset, 2, 1) \
278   F(FunctionIsAPIFunction, 1, 1) \
279   F(FunctionIsBuiltin, 1, 1) \
280   F(GetScript, 1, 1) \
281   F(CollectStackTrace, 3, 1) \
282   F(GetAndClearOverflowedStackTrace, 1, 1) \
283   F(GetV8Version, 0, 1) \
284   \
285   F(SetCode, 2, 1) \
286   F(SetExpectedNumberOfProperties, 2, 1) \
287   \
288   F(CreateApiFunction, 1, 1) \
289   F(IsTemplate, 1, 1) \
290   F(GetTemplateField, 2, 1) \
291   F(DisableAccessChecks, 1, 1) \
292   F(EnableAccessChecks, 1, 1) \
293   F(SetAccessorProperty, 6, 1) \
294   \
295   /* Dates */ \
296   F(DateCurrentTime, 0, 1) \
297   F(DateParseString, 2, 1) \
298   F(DateLocalTimezone, 1, 1) \
299   F(DateToUTC, 1, 1) \
300   F(DateMakeDay, 2, 1) \
301   F(DateSetValue, 3, 1) \
302   F(DateCacheVersion, 0, 1) \
303   \
304   /* Float32x4 and Int32x4 */ \
305   F(CreateFloat32x4, 4, 1) \
306   F(Float32x4GetX, 1, 1) \
307   F(Float32x4GetY, 1, 1) \
308   F(Float32x4GetZ, 1, 1) \
309   F(Float32x4GetW, 1, 1) \
310   F(Float32x4GetSignMask, 1, 1) \
311   F(CreateInt32x4, 4, 1) \
312   F(Int32x4GetX, 1, 1) \
313   F(Int32x4GetY, 1, 1) \
314   F(Int32x4GetZ, 1, 1) \
315   F(Int32x4GetW, 1, 1) \
316   F(Int32x4GetFlagX, 1, 1) \
317   F(Int32x4GetFlagY, 1, 1) \
318   F(Int32x4GetFlagZ, 1, 1) \
319   F(Int32x4GetFlagW, 1, 1) \
320   F(Int32x4GetSignMask, 1, 1) \
321   \
322   /* Globals */ \
323   F(CompileString, 2, 1) \
324   \
325   /* Eval */ \
326   F(GlobalReceiver, 1, 1) \
327   F(IsAttachedGlobal, 1, 1) \
328   \
329   F(SetProperty, -1 /* 4 or 5 */, 1) \
330   F(DefineOrRedefineDataProperty, 4, 1) \
331   F(DefineOrRedefineAccessorProperty, 5, 1) \
332   F(IgnoreAttributesAndSetProperty, -1 /* 3 or 4 */, 1) \
333   F(GetDataProperty, 2, 1) \
334   F(SetHiddenProperty, 3, 1) \
335   \
336   /* Arrays */ \
337   F(RemoveArrayHoles, 2, 1) \
338   F(GetArrayKeys, 2, 1) \
339   F(MoveArrayContents, 2, 1) \
340   F(EstimateNumberOfElements, 1, 1) \
341   \
342   /* Getters and Setters */ \
343   F(LookupAccessor, 3, 1) \
344   \
345   /* ES5 */ \
346   F(ObjectFreeze, 1, 1) \
347   \
348   /* Harmony microtasks */ \
349   F(GetMicrotaskState, 0, 1) \
350   \
351   /* Harmony modules */ \
352   F(IsJSModule, 1, 1) \
353   \
354   /* Harmony symbols */ \
355   F(CreateSymbol, 1, 1) \
356   F(CreatePrivateSymbol, 1, 1) \
357   F(CreateGlobalPrivateSymbol, 1, 1) \
358   F(NewSymbolWrapper, 1, 1) \
359   F(SymbolDescription, 1, 1) \
360   F(SymbolRegistry, 0, 1) \
361   F(SymbolIsPrivate, 1, 1) \
362   \
363   /* Harmony proxies */ \
364   F(CreateJSProxy, 2, 1) \
365   F(CreateJSFunctionProxy, 4, 1) \
366   F(IsJSProxy, 1, 1) \
367   F(IsJSFunctionProxy, 1, 1) \
368   F(GetHandler, 1, 1) \
369   F(GetCallTrap, 1, 1) \
370   F(GetConstructTrap, 1, 1) \
371   F(Fix, 1, 1) \
372   \
373   /* Harmony sets */ \
374   F(SetInitialize, 1, 1) \
375   F(SetAdd, 2, 1) \
376   F(SetHas, 2, 1) \
377   F(SetDelete, 2, 1) \
378   F(SetGetSize, 1, 1) \
379   \
380   /* Harmony maps */ \
381   F(MapInitialize, 1, 1) \
382   F(MapGet, 2, 1) \
383   F(MapHas, 2, 1) \
384   F(MapDelete, 2, 1) \
385   F(MapSet, 3, 1) \
386   F(MapGetSize, 1, 1) \
387   \
388   /* Harmony weak maps and sets */ \
389   F(WeakCollectionInitialize, 1, 1) \
390   F(WeakCollectionGet, 2, 1) \
391   F(WeakCollectionHas, 2, 1) \
392   F(WeakCollectionDelete, 2, 1) \
393   F(WeakCollectionSet, 3, 1) \
394   \
395   /* Harmony events */ \
396   F(SetMicrotaskPending, 1, 1) \
397   F(RunMicrotasks, 0, 1) \
398   \
399   /* Harmony observe */ \
400   F(IsObserved, 1, 1) \
401   F(SetIsObserved, 1, 1) \
402   F(GetObservationState, 0, 1) \
403   F(ObservationWeakMapCreate, 0, 1) \
404   F(UnwrapGlobalProxy, 1, 1) \
405   F(IsAccessAllowedForObserver, 3, 1) \
406   \
407   /* Harmony typed arrays */ \
408   F(ArrayBufferInitialize, 2, 1)\
409   F(ArrayBufferGetByteLength, 1, 1)\
410   F(ArrayBufferSliceImpl, 3, 1) \
411   F(ArrayBufferIsView, 1, 1) \
412   F(ArrayBufferNeuter, 1, 1) \
413   \
414   F(TypedArrayInitializeFromArrayLike, 4, 1) \
415   F(TypedArrayGetBuffer, 1, 1) \
416   F(TypedArrayGetByteLength, 1, 1) \
417   F(TypedArrayGetByteOffset, 1, 1) \
418   F(TypedArrayGetLength, 1, 1) \
419   F(TypedArraySetFastCases, 3, 1) \
420   \
421   F(DataViewGetBuffer, 1, 1) \
422   F(DataViewGetByteLength, 1, 1) \
423   F(DataViewGetByteOffset, 1, 1) \
424   F(DataViewGetInt8, 3, 1) \
425   F(DataViewGetUint8, 3, 1) \
426   F(DataViewGetInt16, 3, 1) \
427   F(DataViewGetUint16, 3, 1) \
428   F(DataViewGetInt32, 3, 1) \
429   F(DataViewGetUint32, 3, 1) \
430   F(DataViewGetFloat32, 3, 1) \
431   F(DataViewGetFloat64, 3, 1) \
432   \
433   F(DataViewSetInt8, 4, 1) \
434   F(DataViewSetUint8, 4, 1) \
435   F(DataViewSetInt16, 4, 1) \
436   F(DataViewSetUint16, 4, 1) \
437   F(DataViewSetInt32, 4, 1) \
438   F(DataViewSetUint32, 4, 1) \
439   F(DataViewSetFloat32, 4, 1) \
440   F(DataViewSetFloat64, 4, 1) \
441   \
442   /* Statements */ \
443   F(NewObjectFromBound, 1, 1) \
444   \
445   /* Declarations and initialization */ \
446   F(InitializeVarGlobal, -1 /* 2 or 3 */, 1) \
447   F(OptimizeObjectForAddingMultipleProperties, 2, 1) \
448   \
449   /* Debugging */ \
450   F(DebugPrint, 1, 1) \
451   F(GlobalPrint, 1, 1) \
452   F(DebugTrace, 0, 1) \
453   F(TraceEnter, 0, 1) \
454   F(TraceExit, 1, 1) \
455   F(Abort, 1, 1) \
456   F(AbortJS, 1, 1) \
457   /* ES5 */ \
458   F(LocalKeys, 1, 1) \
459   \
460   /* Message objects */ \
461   F(MessageGetStartPosition, 1, 1) \
462   F(MessageGetScript, 1, 1) \
463   \
464   /* Pseudo functions - handled as macros by parser */ \
465   F(IS_VAR, 1, 1) \
466   \
467   /* expose boolean functions from objects-inl.h */ \
468   F(HasFastSmiElements, 1, 1) \
469   F(HasFastSmiOrObjectElements, 1, 1) \
470   F(HasFastObjectElements, 1, 1) \
471   F(HasFastDoubleElements, 1, 1) \
472   F(HasFastHoleyElements, 1, 1) \
473   F(HasDictionaryElements, 1, 1) \
474   F(HasSloppyArgumentsElements, 1, 1) \
475   F(HasExternalUint8ClampedElements, 1, 1) \
476   F(HasExternalArrayElements, 1, 1) \
477   F(HasExternalInt8Elements, 1, 1) \
478   F(HasExternalUint8Elements, 1, 1) \
479   F(HasExternalInt16Elements, 1, 1) \
480   F(HasExternalUint16Elements, 1, 1) \
481   F(HasExternalInt32Elements, 1, 1) \
482   F(HasExternalUint32Elements, 1, 1) \
483   F(HasExternalFloat32Elements, 1, 1) \
484   F(HasExternalFloat32x4Elements, 1, 1) \
485   F(HasExternalInt32x4Elements, 1, 1) \
486   F(HasExternalFloat64Elements, 1, 1) \
487   F(HasFixedUint8ClampedElements, 1, 1) \
488   F(HasFixedInt8Elements, 1, 1) \
489   F(HasFixedUint8Elements, 1, 1) \
490   F(HasFixedInt16Elements, 1, 1) \
491   F(HasFixedUint16Elements, 1, 1) \
492   F(HasFixedInt32Elements, 1, 1) \
493   F(HasFixedUint32Elements, 1, 1) \
494   F(HasFixedFloat32Elements, 1, 1) \
495   F(HasFixedFloat64Elements, 1, 1) \
496   F(HasFastProperties, 1, 1) \
497   F(TransitionElementsKind, 2, 1) \
498   F(HaveSameMap, 2, 1) \
499   F(IsAccessCheckNeeded, 1, 1)
500
501
502 #ifdef ENABLE_DEBUGGER_SUPPORT
503 #define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \
504   /* Debugger support*/ \
505   F(DebugBreak, 0, 1) \
506   F(SetDebugEventListener, 2, 1) \
507   F(Break, 0, 1) \
508   F(DebugGetPropertyDetails, 2, 1) \
509   F(DebugGetProperty, 2, 1) \
510   F(DebugPropertyTypeFromDetails, 1, 1) \
511   F(DebugPropertyAttributesFromDetails, 1, 1) \
512   F(DebugPropertyIndexFromDetails, 1, 1) \
513   F(DebugNamedInterceptorPropertyValue, 2, 1) \
514   F(DebugIndexedInterceptorElementValue, 2, 1) \
515   F(CheckExecutionState, 1, 1) \
516   F(GetFrameCount, 1, 1) \
517   F(GetFrameDetails, 2, 1) \
518   F(GetScopeCount, 2, 1) \
519   F(GetStepInPositions, 2, 1) \
520   F(GetScopeDetails, 4, 1) \
521   F(GetAllScopesDetails, 4, 1) \
522   F(GetFunctionScopeCount, 1, 1) \
523   F(GetFunctionScopeDetails, 2, 1) \
524   F(SetScopeVariableValue, 6, 1) \
525   F(DebugPrintScopes, 0, 1) \
526   F(GetThreadCount, 1, 1) \
527   F(GetThreadDetails, 2, 1) \
528   F(SetDisableBreak, 1, 1) \
529   F(GetBreakLocations, 2, 1) \
530   F(SetFunctionBreakPoint, 3, 1) \
531   F(SetScriptBreakPoint, 4, 1) \
532   F(ClearBreakPoint, 1, 1) \
533   F(ChangeBreakOnException, 2, 1) \
534   F(IsBreakOnException, 1, 1) \
535   F(PrepareStep, 4, 1) \
536   F(ClearStepping, 0, 1) \
537   F(DebugEvaluate, 6, 1) \
538   F(DebugEvaluateGlobal, 4, 1) \
539   F(DebugGetLoadedScripts, 0, 1) \
540   F(DebugReferencedBy, 3, 1) \
541   F(DebugConstructedBy, 2, 1) \
542   F(DebugGetPrototype, 1, 1) \
543   F(DebugSetScriptSource, 2, 1) \
544   F(SystemBreak, 0, 1) \
545   F(DebugDisassembleFunction, 1, 1) \
546   F(DebugDisassembleConstructor, 1, 1) \
547   F(FunctionGetInferredName, 1, 1) \
548   F(LiveEditFindSharedFunctionInfosForScript, 1, 1) \
549   F(LiveEditGatherCompileInfo, 2, 1) \
550   F(LiveEditReplaceScript, 3, 1) \
551   F(LiveEditReplaceFunctionCode, 2, 1) \
552   F(LiveEditFunctionSourceUpdated, 1, 1) \
553   F(LiveEditFunctionSetScript, 2, 1) \
554   F(LiveEditReplaceRefToNestedFunction, 3, 1) \
555   F(LiveEditPatchFunctionPositions, 2, 1) \
556   F(LiveEditCheckAndDropActivations, 2, 1) \
557   F(LiveEditCompareStrings, 2, 1) \
558   F(LiveEditRestartFrame, 2, 1) \
559   F(GetFunctionCodePositionFromSource, 2, 1) \
560   F(ExecuteInDebugContext, 2, 1) \
561   \
562   F(SetFlags, 1, 1) \
563   F(CollectGarbage, 1, 1) \
564   F(GetHeapUsage, 0, 1) \
565
566 #else
567 #define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F)
568 #endif
569
570
571 #ifdef V8_I18N_SUPPORT
572 #define RUNTIME_FUNCTION_LIST_I18N_SUPPORT(F) \
573   /* i18n support */ \
574   /* Standalone, helper methods. */ \
575   F(CanonicalizeLanguageTag, 1, 1) \
576   F(AvailableLocalesOf, 1, 1) \
577   F(GetDefaultICULocale, 0, 1) \
578   F(GetLanguageTagVariants, 1, 1) \
579   F(IsInitializedIntlObject, 1, 1) \
580   F(IsInitializedIntlObjectOfType, 2, 1) \
581   F(MarkAsInitializedIntlObjectOfType, 3, 1) \
582   F(GetImplFromInitializedIntlObject, 1, 1) \
583   \
584   /* Date format and parse. */ \
585   F(CreateDateTimeFormat, 3, 1) \
586   F(InternalDateFormat, 2, 1) \
587   F(InternalDateParse, 2, 1) \
588   \
589   /* Number format and parse. */ \
590   F(CreateNumberFormat, 3, 1) \
591   F(InternalNumberFormat, 2, 1) \
592   F(InternalNumberParse, 2, 1) \
593   \
594   /* Collator. */ \
595   F(CreateCollator, 3, 1) \
596   F(InternalCompare, 3, 1) \
597   \
598   /* String.prototype.normalize. */ \
599   F(StringNormalize, 2, 1) \
600   \
601   /* Break iterator. */ \
602   F(CreateBreakIterator, 3, 1) \
603   F(BreakIteratorAdoptText, 2, 1) \
604   F(BreakIteratorFirst, 1, 1) \
605   F(BreakIteratorNext, 1, 1) \
606   F(BreakIteratorCurrent, 1, 1) \
607   F(BreakIteratorBreakType, 1, 1) \
608
609 #else
610 #define RUNTIME_FUNCTION_LIST_I18N_SUPPORT(F)
611 #endif
612
613
614 #ifdef DEBUG
615 #define RUNTIME_FUNCTION_LIST_DEBUG(F) \
616   /* Testing */ \
617   F(ListNatives, 0, 1)
618 #else
619 #define RUNTIME_FUNCTION_LIST_DEBUG(F)
620 #endif
621
622 // ----------------------------------------------------------------------------
623 // RUNTIME_FUNCTION_LIST defines all runtime functions accessed
624 // either directly by id (via the code generator), or indirectly
625 // via a native call by name (from within JS code).
626 // Entries have the form F(name, number of arguments, number of return values).
627
628 #define RUNTIME_FUNCTION_LIST(F) \
629   RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
630   RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
631   RUNTIME_FUNCTION_LIST_DEBUG(F) \
632   RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \
633   RUNTIME_FUNCTION_LIST_I18N_SUPPORT(F)
634
635 // RUNTIME_HIDDEN_FUNCTION_LIST defines all runtime functions accessed
636 // by id from code generator, but not via native call by name.
637 // Entries have the form F(name, number of arguments, number of return values).
638 #define RUNTIME_HIDDEN_FUNCTION_LIST(F) \
639   F(NumberToString, 1, 1) \
640   F(RegExpConstructResult, 3, 1) \
641   F(RegExpExec, 4, 1) \
642   F(StringAdd, 2, 1)  \
643   F(SubString, 3, 1) \
644   F(StringCompare, 2, 1) \
645   F(StringCharCodeAt, 2, 1) \
646   F(Log, 3, 1) \
647   F(GetFromCache, 2, 1) \
648   \
649   /* Compilation */ \
650   F(CompileUnoptimized, 1, 1) \
651   F(CompileOptimized, 2, 1) \
652   F(TryInstallOptimizedCode, 1, 1) \
653   F(NotifyDeoptimized, 1, 1) \
654   F(NotifyStubFailure, 0, 1) \
655   \
656   /* Utilities */ \
657   F(AllocateInNewSpace, 1, 1) \
658   F(AllocateInTargetSpace, 2, 1) \
659   F(AllocateHeapNumber, 0, 1) \
660   F(NumberToSmi, 1, 1) \
661   F(NumberToStringSkipCache, 1, 1) \
662   \
663   F(NewArgumentsFast, 3, 1) \
664   F(NewStrictArgumentsFast, 3, 1) \
665   \
666   /* Harmony generators */ \
667   F(CreateJSGeneratorObject, 0, 1) \
668   F(SuspendJSGeneratorObject, 1, 1) \
669   F(ResumeJSGeneratorObject, 3, 1) \
670   F(ThrowGeneratorStateError, 1, 1) \
671   \
672   /* Arrays */ \
673   F(ArrayConstructor, -1, 1) \
674   F(InternalArrayConstructor, -1, 1) \
675   \
676   /* Literals */ \
677   F(MaterializeRegExpLiteral, 4, 1)\
678   F(CreateObjectLiteral, 4, 1) \
679   F(CreateArrayLiteral, 4, 1) \
680   F(CreateArrayLiteralStubBailout, 3, 1) \
681   \
682   /* Statements */ \
683   F(NewClosure, 3, 1) \
684   F(NewClosureFromStubFailure, 1, 1) \
685   F(NewObject, 1, 1) \
686   F(NewObjectWithAllocationSite, 2, 1) \
687   F(FinalizeInstanceSize, 1, 1) \
688   F(Throw, 1, 1) \
689   F(ReThrow, 1, 1) \
690   F(ThrowReferenceError, 1, 1) \
691   F(ThrowNotDateError, 0, 1) \
692   F(ThrowMessage, 1, 1) \
693   F(StackGuard, 0, 1) \
694   F(Interrupt, 0, 1) \
695   F(PromoteScheduledException, 0, 1) \
696   \
697   /* Contexts */ \
698   F(NewGlobalContext, 2, 1) \
699   F(NewFunctionContext, 1, 1) \
700   F(PushWithContext, 2, 1) \
701   F(PushCatchContext, 3, 1) \
702   F(PushBlockContext, 2, 1) \
703   F(PushModuleContext, 2, 1) \
704   F(DeleteContextSlot, 2, 1) \
705   F(LoadContextSlot, 2, 2) \
706   F(LoadContextSlotNoReferenceError, 2, 2) \
707   F(StoreContextSlot, 4, 1) \
708   \
709   /* Declarations and initialization */ \
710   F(DeclareGlobals, 3, 1) \
711   F(DeclareModules, 1, 1) \
712   F(DeclareContextSlot, 4, 1) \
713   F(InitializeConstGlobal, 2, 1) \
714   F(InitializeConstContextSlot, 3, 1) \
715   \
716   /* Eval */ \
717   F(ResolvePossiblyDirectEval, 5, 2)
718
719 // ----------------------------------------------------------------------------
720 // INLINE_FUNCTION_LIST defines all inlined functions accessed
721 // with a native call of the form %_name from within JS code.
722 // Entries have the form F(name, number of arguments, number of return values).
723 #define INLINE_FUNCTION_LIST(F) \
724   F(IsSmi, 1, 1)                                                             \
725   F(IsNonNegativeSmi, 1, 1)                                                  \
726   F(IsArray, 1, 1)                                                           \
727   F(IsRegExp, 1, 1)                                                          \
728   F(IsConstructCall, 0, 1)                                                   \
729   F(CallFunction, -1 /* receiver + n args + function */, 1)                  \
730   F(ArgumentsLength, 0, 1)                                                   \
731   F(Arguments, 1, 1)                                                         \
732   F(ValueOf, 1, 1)                                                           \
733   F(SetValueOf, 2, 1)                                                        \
734   F(DateField, 2 /* date object, field index */, 1)                          \
735   F(StringCharFromCode, 1, 1)                                                \
736   F(StringCharAt, 2, 1)                                                      \
737   F(OneByteSeqStringSetChar, 3, 1)                                           \
738   F(TwoByteSeqStringSetChar, 3, 1)                                           \
739   F(ObjectEquals, 2, 1)                                                      \
740   F(IsObject, 1, 1)                                                          \
741   F(IsFunction, 1, 1)                                                        \
742   F(IsUndetectableObject, 1, 1)                                              \
743   F(IsSpecObject, 1, 1)                                                      \
744   F(IsStringWrapperSafeForDefaultValueOf, 1, 1)                              \
745   F(MathPow, 2, 1)                                                           \
746   F(MathSqrt, 1, 1)                                                          \
747   F(MathLog, 1, 1)                                                           \
748   F(IsMinusZero, 1, 1)                                                       \
749   F(HasCachedArrayIndex, 1, 1)                                               \
750   F(GetCachedArrayIndex, 1, 1)                                               \
751   F(FastAsciiArrayJoin, 2, 1)                                                \
752   F(GeneratorNext, 2, 1)                                                     \
753   F(GeneratorThrow, 2, 1)                                                    \
754   F(DebugBreakInOptimizedCode, 0, 1)                                         \
755   F(ClassOf, 1, 1)                                                           \
756   F(StringCharCodeAt, 2, 1)                                                  \
757   F(Log, 3, 1)                                                               \
758   F(StringAdd, 2, 1)                                                         \
759   F(SubString, 3, 1)                                                         \
760   F(StringCompare, 2, 1)                                                     \
761   F(RegExpExec, 4, 1)                                                        \
762   F(RegExpConstructResult, 3, 1)                                             \
763   F(GetFromCache, 2, 1)                                                      \
764   F(NumberToString, 1, 1)
765
766
767 // ----------------------------------------------------------------------------
768 // INLINE_OPTIMIZED_FUNCTION_LIST defines all inlined functions accessed
769 // with a native call of the form %_name from within JS code that also have
770 // a corresponding runtime function, that is called from non-optimized code.
771 // Entries have the form F(name, number of arguments, number of return values).
772 #define INLINE_OPTIMIZED_FUNCTION_LIST(F) \
773   F(DoubleHi, 1, 1)                                                          \
774   F(DoubleLo, 1, 1)                                                          \
775   F(ConstructDouble, 2, 1)                                                   \
776   F(TypedArrayInitialize, 5, 1)                                              \
777   F(DataViewInitialize, 4, 1)                                                \
778   F(MaxSmi, 0, 1)                                                            \
779   F(TypedArrayMaxSizeInHeap, 0, 1)
780
781
782 //---------------------------------------------------------------------------
783 // Runtime provides access to all C++ runtime functions.
784
785 class RuntimeState {
786  public:
787   StaticResource<ConsStringIteratorOp>* string_iterator() {
788     return &string_iterator_;
789   }
790   unibrow::Mapping<unibrow::ToUppercase, 128>* to_upper_mapping() {
791     return &to_upper_mapping_;
792   }
793   unibrow::Mapping<unibrow::ToLowercase, 128>* to_lower_mapping() {
794     return &to_lower_mapping_;
795   }
796   ConsStringIteratorOp* string_iterator_compare_x() {
797     return &string_iterator_compare_x_;
798   }
799   ConsStringIteratorOp* string_iterator_compare_y() {
800     return &string_iterator_compare_y_;
801   }
802   ConsStringIteratorOp* string_locale_compare_it1() {
803     return &string_locale_compare_it1_;
804   }
805   ConsStringIteratorOp* string_locale_compare_it2() {
806     return &string_locale_compare_it2_;
807   }
808
809  private:
810   RuntimeState() {}
811   // Non-reentrant string buffer for efficient general use in the runtime.
812   StaticResource<ConsStringIteratorOp> string_iterator_;
813   unibrow::Mapping<unibrow::ToUppercase, 128> to_upper_mapping_;
814   unibrow::Mapping<unibrow::ToLowercase, 128> to_lower_mapping_;
815   ConsStringIteratorOp string_iterator_compare_x_;
816   ConsStringIteratorOp string_iterator_compare_y_;
817   ConsStringIteratorOp string_locale_compare_it1_;
818   ConsStringIteratorOp string_locale_compare_it2_;
819
820   friend class Isolate;
821   friend class Runtime;
822
823   DISALLOW_COPY_AND_ASSIGN(RuntimeState);
824 };
825
826
827 class Runtime : public AllStatic {
828  public:
829   enum FunctionId {
830 #define F(name, nargs, ressize) k##name,
831     RUNTIME_FUNCTION_LIST(F)
832 #undef F
833 #define F(name, nargs, ressize) kHidden##name,
834     RUNTIME_HIDDEN_FUNCTION_LIST(F)
835 #undef F
836 #define F(name, nargs, ressize) kInline##name,
837     INLINE_FUNCTION_LIST(F)
838 #undef F
839 #define F(name, nargs, ressize) kInlineOptimized##name,
840     INLINE_OPTIMIZED_FUNCTION_LIST(F)
841 #undef F
842     kNumFunctions,
843     kFirstInlineFunction = kInlineIsSmi
844   };
845
846   enum IntrinsicType {
847     RUNTIME,
848     RUNTIME_HIDDEN,
849     INLINE,
850     INLINE_OPTIMIZED
851   };
852
853   // Intrinsic function descriptor.
854   struct Function {
855     FunctionId function_id;
856     IntrinsicType intrinsic_type;
857     // The JS name of the function.
858     const char* name;
859
860     // The C++ (native) entry point.  NULL if the function is inlined.
861     byte* entry;
862
863     // The number of arguments expected. nargs is -1 if the function takes
864     // a variable number of arguments.
865     int nargs;
866     // Size of result.  Most functions return a single pointer, size 1.
867     int result_size;
868   };
869
870   static const int kNotFound = -1;
871
872   // Add internalized strings for all the intrinsic function names to a
873   // StringDictionary.
874   // Returns failure if an allocation fails.  In this case, it must be
875   // retried with a new, empty StringDictionary, not with the same one.
876   // Alternatively, heap initialization can be completely restarted.
877   MUST_USE_RESULT static MaybeObject* InitializeIntrinsicFunctionNames(
878       Heap* heap, Object* dictionary);
879
880   // Get the intrinsic function with the given name, which must be internalized.
881   static const Function* FunctionForName(Handle<String> name);
882
883   // Get the intrinsic function with the given FunctionId.
884   static const Function* FunctionForId(FunctionId id);
885
886   // General-purpose helper functions for runtime system.
887   static int StringMatch(Isolate* isolate,
888                          Handle<String> sub,
889                          Handle<String> pat,
890                          int index);
891
892   static bool IsUpperCaseChar(RuntimeState* runtime_state, uint16_t ch);
893
894   // TODO(1240886): Some of the following methods are *not* handle safe, but
895   // accept handle arguments. This seems fragile.
896
897   // Support getting the characters in a string using [] notation as
898   // in Firefox/SpiderMonkey, Safari and Opera.
899   static Handle<Object> GetElementOrCharAt(Isolate* isolate,
900                                            Handle<Object> object,
901                                            uint32_t index);
902
903   static Handle<Object> SetObjectProperty(
904       Isolate* isolate,
905       Handle<Object> object,
906       Handle<Object> key,
907       Handle<Object> value,
908       PropertyAttributes attr,
909       StrictMode strict_mode);
910
911   static Handle<Object> ForceSetObjectProperty(
912       Isolate* isolate,
913       Handle<JSObject> object,
914       Handle<Object> key,
915       Handle<Object> value,
916       PropertyAttributes attr);
917
918   MUST_USE_RESULT static MaybeObject* DeleteObjectProperty(
919       Isolate* isolate,
920       Handle<JSReceiver> object,
921       Handle<Object> key,
922       JSReceiver::DeleteMode mode);
923
924   MUST_USE_RESULT static MaybeObject* HasObjectProperty(
925       Isolate* isolate,
926       Handle<JSReceiver> object,
927       Handle<Object> key);
928
929   MUST_USE_RESULT static MaybeObject* GetObjectProperty(
930       Isolate* isolate,
931       Handle<Object> object,
932       Handle<Object> key);
933
934   MUST_USE_RESULT static MaybeObject* GetObjectPropertyOrFail(
935       Isolate* isolate,
936       Handle<Object> object,
937       Handle<Object> key);
938
939   static void SetupArrayBuffer(Isolate* isolate,
940                                Handle<JSArrayBuffer> array_buffer,
941                                bool is_external,
942                                void* data,
943                                size_t allocated_length);
944
945   static bool SetupArrayBufferAllocatingData(
946       Isolate* isolate,
947       Handle<JSArrayBuffer> array_buffer,
948       size_t allocated_length,
949       bool initialize = true);
950
951   static void NeuterArrayBuffer(Handle<JSArrayBuffer> array_buffer);
952
953   static void FreeArrayBuffer(
954       Isolate* isolate,
955       JSArrayBuffer* phantom_array_buffer);
956
957   enum TypedArrayId {
958     // arrayIds below should be synchromized with typedarray.js natives.
959     ARRAY_ID_UINT8 = 1,
960     ARRAY_ID_INT8 = 2,
961     ARRAY_ID_UINT16 = 3,
962     ARRAY_ID_INT16 = 4,
963     ARRAY_ID_UINT32 = 5,
964     ARRAY_ID_INT32 = 6,
965     ARRAY_ID_FLOAT32 = 7,
966     ARRAY_ID_FLOAT64 = 8,
967     ARRAY_ID_UINT8_CLAMPED = 9,
968     ARRAY_ID_FLOAT32x4 = 10,
969     ARRAY_ID_INT32x4 = 11
970   };
971
972   static void ArrayIdToTypeAndSize(int array_id,
973       ExternalArrayType *type,
974       ElementsKind* external_elements_kind,
975       ElementsKind* fixed_elements_kind,
976       size_t *element_size);
977
978   // Helper functions used stubs.
979   static void PerformGC(Object* result, Isolate* isolate);
980
981   // Used in runtime.cc and hydrogen's VisitArrayLiteral.
982   static Handle<Object> CreateArrayLiteralBoilerplate(
983       Isolate* isolate,
984       Handle<FixedArray> literals,
985       Handle<FixedArray> elements);
986 };
987
988
989 //---------------------------------------------------------------------------
990 // Constants used by interface to runtime functions.
991
992 class AllocateDoubleAlignFlag:  public BitField<bool,            0, 1> {};
993 class AllocateTargetSpace:      public BitField<AllocationSpace, 1, 3> {};
994
995 class DeclareGlobalsEvalFlag:   public BitField<bool,       0, 1> {};
996 class DeclareGlobalsNativeFlag: public BitField<bool,       1, 1> {};
997 class DeclareGlobalsStrictMode: public BitField<StrictMode, 2, 1> {};
998
999 } }  // namespace v8::internal
1000
1001 #endif  // V8_RUNTIME_H_