93185cc82fc12c431ede306b7210a277be587134
[platform/framework/web/crosswalk.git] / src / v8 / src / runtime.h
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef V8_RUNTIME_H_
6 #define V8_RUNTIME_H_
7
8 #include "src/allocation.h"
9 #include "src/zone.h"
10
11 namespace v8 {
12 namespace internal {
13
14 // The interface to C++ runtime functions.
15
16 // ----------------------------------------------------------------------------
17 // RUNTIME_FUNCTION_LIST_ALWAYS defines runtime calls available in both
18 // release and debug mode.
19 // This macro should only be used by the macro RUNTIME_FUNCTION_LIST.
20
21 // WARNING: RUNTIME_FUNCTION_LIST_ALWAYS_* is a very large macro that caused
22 // MSVC Intellisense to crash.  It was broken into two macros to work around
23 // this problem. Please avoid large recursive macros whenever possible.
24 #define RUNTIME_FUNCTION_LIST_ALWAYS_1(F)                   \
25   /* Property access */                                     \
26   F(GetProperty, 2, 1)                                      \
27   F(KeyedGetProperty, 2, 1)                                 \
28   F(DeleteProperty, 3, 1)                                   \
29   F(HasOwnProperty, 2, 1)                                   \
30   F(HasProperty, 2, 1)                                      \
31   F(HasElement, 2, 1)                                       \
32   F(IsPropertyEnumerable, 2, 1)                             \
33   F(GetPropertyNames, 1, 1)                                 \
34   F(GetPropertyNamesFast, 1, 1)                             \
35   F(GetOwnPropertyNames, 2, 1)                              \
36   F(GetOwnElementNames, 1, 1)                               \
37   F(GetInterceptorInfo, 1, 1)                               \
38   F(GetNamedInterceptorPropertyNames, 1, 1)                 \
39   F(GetIndexedInterceptorElementNames, 1, 1)                \
40   F(GetArgumentsProperty, 1, 1)                             \
41   F(ToFastProperties, 1, 1)                                 \
42   F(FinishArrayPrototypeSetup, 1, 1)                        \
43   F(SpecialArrayFunctions, 0, 1)                            \
44   F(IsSloppyModeFunction, 1, 1)                             \
45   F(GetDefaultReceiver, 1, 1)                               \
46                                                             \
47   F(GetPrototype, 1, 1)                                     \
48   F(SetPrototype, 2, 1)                                     \
49   F(InternalSetPrototype, 2, 1)                             \
50   F(IsInPrototypeChain, 2, 1)                               \
51                                                             \
52   F(GetOwnProperty, 2, 1)                                   \
53                                                             \
54   F(IsExtensible, 1, 1)                                     \
55   F(PreventExtensions, 1, 1)                                \
56                                                             \
57   /* Utilities */                                           \
58   F(CheckIsBootstrapping, 0, 1)                             \
59   F(GetRootNaN, 0, 1)                                       \
60   F(Call, -1 /* >= 2 */, 1)                                 \
61   F(Apply, 5, 1)                                            \
62   F(GetFunctionDelegate, 1, 1)                              \
63   F(GetConstructorDelegate, 1, 1)                           \
64   F(DeoptimizeFunction, 1, 1)                               \
65   F(ClearFunctionTypeFeedback, 1, 1)                        \
66   F(RunningInSimulator, 0, 1)                               \
67   F(IsConcurrentRecompilationSupported, 0, 1)               \
68   F(OptimizeFunctionOnNextCall, -1, 1)                      \
69   F(NeverOptimizeFunction, 1, 1)                            \
70   F(GetOptimizationStatus, -1, 1)                           \
71   F(IsOptimized, 0, 1) /* TODO(turbofan): Only temporary */ \
72   F(GetOptimizationCount, 1, 1)                             \
73   F(UnblockConcurrentRecompilation, 0, 1)                   \
74   F(CompileForOnStackReplacement, 1, 1)                     \
75   F(SetAllocationTimeout, -1 /* 2 || 3 */, 1)               \
76   F(SetNativeFlag, 1, 1)                                    \
77   F(SetInlineBuiltinFlag, 1, 1)                             \
78   F(StoreArrayLiteralElement, 5, 1)                         \
79   F(DebugPrepareStepInIfStepping, 1, 1)                     \
80   F(DebugPushPromise, 1, 1)                                 \
81   F(DebugPopPromise, 0, 1)                                  \
82   F(DebugPromiseEvent, 1, 1)                                \
83   F(DebugPromiseRejectEvent, 2, 1)                          \
84   F(DebugAsyncTaskEvent, 1, 1)                              \
85   F(FlattenString, 1, 1)                                    \
86   F(LoadMutableDouble, 2, 1)                                \
87   F(TryMigrateInstance, 1, 1)                               \
88   F(NotifyContextDisposed, 0, 1)                            \
89                                                             \
90   /* Array join support */                                  \
91   F(PushIfAbsent, 2, 1)                                     \
92   F(ArrayConcat, 1, 1)                                      \
93                                                             \
94   /* Conversions */                                         \
95   F(ToBool, 1, 1)                                           \
96   F(Typeof, 1, 1)                                           \
97                                                             \
98   F(Booleanize, 2, 1) /* TODO(turbofan): Only temporary */  \
99                                                             \
100   F(StringToNumber, 1, 1)                                   \
101   F(StringParseInt, 2, 1)                                   \
102   F(StringParseFloat, 1, 1)                                 \
103   F(StringToLowerCase, 1, 1)                                \
104   F(StringToUpperCase, 1, 1)                                \
105   F(StringSplit, 3, 1)                                      \
106   F(CharFromCode, 1, 1)                                     \
107   F(URIEscape, 1, 1)                                        \
108   F(URIUnescape, 1, 1)                                      \
109                                                             \
110   F(NumberToInteger, 1, 1)                                  \
111   F(NumberToIntegerMapMinusZero, 1, 1)                      \
112   F(NumberToJSUint32, 1, 1)                                 \
113   F(NumberToJSInt32, 1, 1)                                  \
114                                                             \
115   /* Arithmetic operations */                               \
116   F(NumberAdd, 2, 1)                                        \
117   F(NumberSub, 2, 1)                                        \
118   F(NumberMul, 2, 1)                                        \
119   F(NumberDiv, 2, 1)                                        \
120   F(NumberMod, 2, 1)                                        \
121   F(NumberUnaryMinus, 1, 1)                                 \
122   F(NumberImul, 2, 1)                                       \
123                                                             \
124   F(StringBuilderConcat, 3, 1)                              \
125   F(StringBuilderJoin, 3, 1)                                \
126   F(SparseJoinWithSeparator, 3, 1)                          \
127                                                             \
128   /* Bit operations */                                      \
129   F(NumberOr, 2, 1)                                         \
130   F(NumberAnd, 2, 1)                                        \
131   F(NumberXor, 2, 1)                                        \
132                                                             \
133   F(NumberShl, 2, 1)                                        \
134   F(NumberShr, 2, 1)                                        \
135   F(NumberSar, 2, 1)                                        \
136                                                             \
137   /* Comparisons */                                         \
138   F(NumberEquals, 2, 1)                                     \
139   F(StringEquals, 2, 1)                                     \
140                                                             \
141   F(NumberCompare, 3, 1)                                    \
142   F(SmiLexicographicCompare, 2, 1)                          \
143                                                             \
144   /* Math */                                                \
145   F(MathAcos, 1, 1)                                         \
146   F(MathAsin, 1, 1)                                         \
147   F(MathAtan, 1, 1)                                         \
148   F(MathFloorRT, 1, 1)                                      \
149   F(MathAtan2, 2, 1)                                        \
150   F(MathExpRT, 1, 1)                                        \
151   F(RoundNumber, 1, 1)                                      \
152   F(MathFround, 1, 1)                                       \
153   F(RemPiO2, 1, 1)                                          \
154                                                             \
155   /* Regular expressions */                                 \
156   F(RegExpCompile, 3, 1)                                    \
157   F(RegExpExecMultiple, 4, 1)                               \
158   F(RegExpInitializeObject, 5, 1)                           \
159                                                             \
160   /* JSON */                                                \
161   F(ParseJson, 1, 1)                                        \
162   F(BasicJSONStringify, 1, 1)                               \
163   F(QuoteJSONString, 1, 1)                                  \
164                                                             \
165   /* Strings */                                             \
166   F(StringIndexOf, 3, 1)                                    \
167   F(StringLastIndexOf, 3, 1)                                \
168   F(StringLocaleCompare, 2, 1)                              \
169   F(StringReplaceGlobalRegExpWithString, 4, 1)              \
170   F(StringReplaceOneCharWithString, 3, 1)                   \
171   F(StringMatch, 3, 1)                                      \
172   F(StringTrim, 3, 1)                                       \
173   F(StringToArray, 2, 1)                                    \
174   F(NewStringWrapper, 1, 1)                                 \
175   F(NewString, 2, 1)                                        \
176   F(TruncateString, 2, 1)                                   \
177                                                             \
178   /* Numbers */                                             \
179   F(NumberToRadixString, 2, 1)                              \
180   F(NumberToFixed, 2, 1)                                    \
181   F(NumberToExponential, 2, 1)                              \
182   F(NumberToPrecision, 2, 1)                                \
183   F(IsValidSmi, 1, 1)
184
185
186 #define RUNTIME_FUNCTION_LIST_ALWAYS_2(F)                             \
187   /* Reflection */                                                    \
188   F(FunctionSetInstanceClassName, 2, 1)                               \
189   F(FunctionSetLength, 2, 1)                                          \
190   F(FunctionSetPrototype, 2, 1)                                       \
191   F(FunctionGetName, 1, 1)                                            \
192   F(FunctionSetName, 2, 1)                                            \
193   F(FunctionNameShouldPrintAsAnonymous, 1, 1)                         \
194   F(FunctionMarkNameShouldPrintAsAnonymous, 1, 1)                     \
195   F(FunctionIsGenerator, 1, 1)                                        \
196   F(FunctionIsArrow, 1, 1)                                            \
197   F(FunctionBindArguments, 4, 1)                                      \
198   F(BoundFunctionGetBindings, 1, 1)                                   \
199   F(FunctionRemovePrototype, 1, 1)                                    \
200   F(FunctionGetSourceCode, 1, 1)                                      \
201   F(FunctionGetScript, 1, 1)                                          \
202   F(FunctionGetScriptSourcePosition, 1, 1)                            \
203   F(FunctionGetPositionForOffset, 2, 1)                               \
204   F(FunctionIsAPIFunction, 1, 1)                                      \
205   F(FunctionIsBuiltin, 1, 1)                                          \
206   F(GetScript, 1, 1)                                                  \
207   F(CollectStackTrace, 2, 1)                                          \
208   F(GetV8Version, 0, 1)                                               \
209                                                                       \
210   F(SetCode, 2, 1)                                                    \
211                                                                       \
212   F(CreateApiFunction, 2, 1)                                          \
213   F(IsTemplate, 1, 1)                                                 \
214   F(GetTemplateField, 2, 1)                                           \
215   F(DisableAccessChecks, 1, 1)                                        \
216   F(EnableAccessChecks, 1, 1)                                         \
217                                                                       \
218   /* Dates */                                                         \
219   F(DateCurrentTime, 0, 1)                                            \
220   F(DateParseString, 2, 1)                                            \
221   F(DateLocalTimezone, 1, 1)                                          \
222   F(DateToUTC, 1, 1)                                                  \
223   F(DateMakeDay, 2, 1)                                                \
224   F(DateSetValue, 3, 1)                                               \
225   F(DateCacheVersion, 0, 1)                                           \
226                                                                       \
227   /* Globals */                                                       \
228   F(CompileString, 2, 1)                                              \
229                                                                       \
230   /* Eval */                                                          \
231   F(GlobalProxy, 1, 1)                                                \
232   F(IsAttachedGlobal, 1, 1)                                           \
233                                                                       \
234   F(AddNamedProperty, 4, 1)                                           \
235   F(AddPropertyForTemplate, 4, 1)                                     \
236   F(SetProperty, 4, 1)                                                \
237   F(DefineApiAccessorProperty, 5, 1)                                  \
238   F(DefineDataPropertyUnchecked, 4, 1)                                \
239   F(DefineAccessorPropertyUnchecked, 5, 1)                            \
240   F(GetDataProperty, 2, 1)                                            \
241   F(SetHiddenProperty, 3, 1)                                          \
242                                                                       \
243   /* Arrays */                                                        \
244   F(RemoveArrayHoles, 2, 1)                                           \
245   F(GetArrayKeys, 2, 1)                                               \
246   F(MoveArrayContents, 2, 1)                                          \
247   F(EstimateNumberOfElements, 1, 1)                                   \
248   F(NormalizeElements, 1, 1)                                          \
249                                                                       \
250   /* Getters and Setters */                                           \
251   F(LookupAccessor, 3, 1)                                             \
252                                                                       \
253   /* ES5 */                                                           \
254   F(ObjectFreeze, 1, 1)                                               \
255                                                                       \
256   /* Harmony modules */                                               \
257   F(IsJSModule, 1, 1)                                                 \
258                                                                       \
259   /* Harmony symbols */                                               \
260   F(CreateSymbol, 1, 1)                                               \
261   F(CreatePrivateSymbol, 1, 1)                                        \
262   F(CreateGlobalPrivateSymbol, 1, 1)                                  \
263   F(NewSymbolWrapper, 1, 1)                                           \
264   F(SymbolDescription, 1, 1)                                          \
265   F(SymbolRegistry, 0, 1)                                             \
266   F(SymbolIsPrivate, 1, 1)                                            \
267                                                                       \
268   /* Harmony proxies */                                               \
269   F(CreateJSProxy, 2, 1)                                              \
270   F(CreateJSFunctionProxy, 4, 1)                                      \
271   F(IsJSProxy, 1, 1)                                                  \
272   F(IsJSFunctionProxy, 1, 1)                                          \
273   F(GetHandler, 1, 1)                                                 \
274   F(GetCallTrap, 1, 1)                                                \
275   F(GetConstructTrap, 1, 1)                                           \
276   F(Fix, 1, 1)                                                        \
277                                                                       \
278   /* Harmony sets */                                                  \
279   F(SetInitialize, 1, 1)                                              \
280   F(SetAdd, 2, 1)                                                     \
281   F(SetHas, 2, 1)                                                     \
282   F(SetDelete, 2, 1)                                                  \
283   F(SetClear, 1, 1)                                                   \
284   F(SetGetSize, 1, 1)                                                 \
285                                                                       \
286   F(SetIteratorInitialize, 3, 1)                                      \
287   F(SetIteratorNext, 2, 1)                                            \
288                                                                       \
289   /* Harmony maps */                                                  \
290   F(MapInitialize, 1, 1)                                              \
291   F(MapGet, 2, 1)                                                     \
292   F(MapHas, 2, 1)                                                     \
293   F(MapDelete, 2, 1)                                                  \
294   F(MapClear, 1, 1)                                                   \
295   F(MapSet, 3, 1)                                                     \
296   F(MapGetSize, 1, 1)                                                 \
297                                                                       \
298   F(MapIteratorInitialize, 3, 1)                                      \
299   F(MapIteratorNext, 2, 1)                                            \
300                                                                       \
301   /* Harmony weak maps and sets */                                    \
302   F(WeakCollectionInitialize, 1, 1)                                   \
303   F(WeakCollectionGet, 2, 1)                                          \
304   F(WeakCollectionHas, 2, 1)                                          \
305   F(WeakCollectionDelete, 2, 1)                                       \
306   F(WeakCollectionSet, 3, 1)                                          \
307                                                                       \
308   F(GetWeakMapEntries, 1, 1)                                          \
309   F(GetWeakSetValues, 1, 1)                                           \
310                                                                       \
311   /* Harmony events */                                                \
312   F(EnqueueMicrotask, 1, 1)                                           \
313   F(RunMicrotasks, 0, 1)                                              \
314                                                                       \
315   /* Harmony observe */                                               \
316   F(IsObserved, 1, 1)                                                 \
317   F(SetIsObserved, 1, 1)                                              \
318   F(GetObservationState, 0, 1)                                        \
319   F(ObservationWeakMapCreate, 0, 1)                                   \
320   F(ObserverObjectAndRecordHaveSameOrigin, 3, 1)                      \
321   F(ObjectWasCreatedInCurrentOrigin, 1, 1)                            \
322   F(GetObjectContextObjectObserve, 1, 1)                              \
323   F(GetObjectContextObjectGetNotifier, 1, 1)                          \
324   F(GetObjectContextNotifierPerformChange, 1, 1)                      \
325                                                                       \
326   /* Harmony typed arrays */                                          \
327   F(ArrayBufferInitialize, 2, 1)                                      \
328   F(ArrayBufferSliceImpl, 3, 1)                                       \
329   F(ArrayBufferIsView, 1, 1)                                          \
330   F(ArrayBufferNeuter, 1, 1)                                          \
331                                                                       \
332   F(TypedArrayInitializeFromArrayLike, 4, 1)                          \
333   F(TypedArrayGetBuffer, 1, 1)                                        \
334   F(TypedArraySetFastCases, 3, 1)                                     \
335                                                                       \
336   F(DataViewGetBuffer, 1, 1)                                          \
337   F(DataViewGetInt8, 3, 1)                                            \
338   F(DataViewGetUint8, 3, 1)                                           \
339   F(DataViewGetInt16, 3, 1)                                           \
340   F(DataViewGetUint16, 3, 1)                                          \
341   F(DataViewGetInt32, 3, 1)                                           \
342   F(DataViewGetUint32, 3, 1)                                          \
343   F(DataViewGetFloat32, 3, 1)                                         \
344   F(DataViewGetFloat64, 3, 1)                                         \
345                                                                       \
346   F(DataViewSetInt8, 4, 1)                                            \
347   F(DataViewSetUint8, 4, 1)                                           \
348   F(DataViewSetInt16, 4, 1)                                           \
349   F(DataViewSetUint16, 4, 1)                                          \
350   F(DataViewSetInt32, 4, 1)                                           \
351   F(DataViewSetUint32, 4, 1)                                          \
352   F(DataViewSetFloat32, 4, 1)                                         \
353   F(DataViewSetFloat64, 4, 1)                                         \
354                                                                       \
355   /* Statements */                                                    \
356   F(NewObjectFromBound, 1, 1)                                         \
357                                                                       \
358   /* Declarations and initialization */                               \
359   F(InitializeVarGlobal, 3, 1)                                        \
360   F(OptimizeObjectForAddingMultipleProperties, 2, 1)                  \
361                                                                       \
362   /* Debugging */                                                     \
363   F(DebugPrint, 1, 1)                                                 \
364   F(GlobalPrint, 1, 1)                                                \
365   F(DebugTrace, 0, 1)                                                 \
366   F(TraceEnter, 0, 1)                                                 \
367   F(TraceExit, 1, 1)                                                  \
368   F(Abort, 1, 1)                                                      \
369   F(AbortJS, 1, 1)                                                    \
370   /* ES5 */                                                           \
371   F(OwnKeys, 1, 1)                                                    \
372                                                                       \
373   /* Message objects */                                               \
374   F(MessageGetStartPosition, 1, 1)                                    \
375   F(MessageGetScript, 1, 1)                                           \
376                                                                       \
377   /* Pseudo functions - handled as macros by parser */                \
378   F(IS_VAR, 1, 1)                                                     \
379                                                                       \
380   /* expose boolean functions from objects-inl.h */                   \
381   F(HasFastSmiElements, 1, 1)                                         \
382   F(HasFastSmiOrObjectElements, 1, 1)                                 \
383   F(HasFastObjectElements, 1, 1)                                      \
384   F(HasFastDoubleElements, 1, 1)                                      \
385   F(HasFastHoleyElements, 1, 1)                                       \
386   F(HasDictionaryElements, 1, 1)                                      \
387   F(HasSloppyArgumentsElements, 1, 1)                                 \
388   F(HasExternalUint8ClampedElements, 1, 1)                            \
389   F(HasExternalArrayElements, 1, 1)                                   \
390   F(HasExternalInt8Elements, 1, 1)                                    \
391   F(HasExternalUint8Elements, 1, 1)                                   \
392   F(HasExternalInt16Elements, 1, 1)                                   \
393   F(HasExternalUint16Elements, 1, 1)                                  \
394   F(HasExternalInt32Elements, 1, 1)                                   \
395   F(HasExternalUint32Elements, 1, 1)                                  \
396   F(HasExternalFloat32Elements, 1, 1)                                 \
397   F(HasExternalFloat64Elements, 1, 1)                                 \
398   F(HasFixedUint8ClampedElements, 1, 1)                               \
399   F(HasFixedInt8Elements, 1, 1)                                       \
400   F(HasFixedUint8Elements, 1, 1)                                      \
401   F(HasFixedInt16Elements, 1, 1)                                      \
402   F(HasFixedUint16Elements, 1, 1)                                     \
403   F(HasFixedInt32Elements, 1, 1)                                      \
404   F(HasFixedUint32Elements, 1, 1)                                     \
405   F(HasFixedFloat32Elements, 1, 1)                                    \
406   F(HasFixedFloat64Elements, 1, 1)                                    \
407   F(HasFastProperties, 1, 1)                                          \
408   F(TransitionElementsKind, 2, 1)                                     \
409   F(HaveSameMap, 2, 1)                                                \
410   F(IsJSGlobalProxy, 1, 1)                                            \
411   F(ForInInit, 2, 2)             /* TODO(turbofan): Only temporary */ \
412   F(ForInNext, 4, 2)             /* TODO(turbofan): Only temporary */ \
413   F(ForInCacheArrayLength, 2, 1) /* TODO(turbofan): Only temporary */
414
415
416 #define RUNTIME_FUNCTION_LIST_ALWAYS_3(F)                            \
417   /* String and Regexp */                                            \
418   F(NumberToStringRT, 1, 1)                                          \
419   F(RegExpConstructResult, 3, 1)                                     \
420   F(RegExpExecRT, 4, 1)                                              \
421   F(StringAdd, 2, 1)                                                 \
422   F(SubString, 3, 1)                                                 \
423   F(InternalizeString, 1, 1)                                         \
424   F(StringCompare, 2, 1)                                             \
425   F(StringCharCodeAtRT, 2, 1)                                        \
426   F(GetFromCache, 2, 1)                                              \
427                                                                      \
428   /* Compilation */                                                  \
429   F(CompileUnoptimized, 1, 1)                                        \
430   F(CompileOptimized, 2, 1)                                          \
431   F(TryInstallOptimizedCode, 1, 1)                                   \
432   F(NotifyDeoptimized, 1, 1)                                         \
433   F(NotifyStubFailure, 0, 1)                                         \
434                                                                      \
435   /* Utilities */                                                    \
436   F(AllocateInNewSpace, 1, 1)                                        \
437   F(AllocateInTargetSpace, 2, 1)                                     \
438   F(AllocateHeapNumber, 0, 1)                                        \
439   F(NumberToSmi, 1, 1)                                               \
440   F(NumberToStringSkipCache, 1, 1)                                   \
441                                                                      \
442   F(NewArguments, 1, 1) /* TODO(turbofan): Only temporary */         \
443   F(NewSloppyArguments, 3, 1)                                        \
444   F(NewStrictArguments, 3, 1)                                        \
445                                                                      \
446   /* Harmony generators */                                           \
447   F(CreateJSGeneratorObject, 0, 1)                                   \
448   F(SuspendJSGeneratorObject, 1, 1)                                  \
449   F(ResumeJSGeneratorObject, 3, 1)                                   \
450   F(ThrowGeneratorStateError, 1, 1)                                  \
451                                                                      \
452   /* Arrays */                                                       \
453   F(ArrayConstructor, -1, 1)                                         \
454   F(InternalArrayConstructor, -1, 1)                                 \
455                                                                      \
456   /* Literals */                                                     \
457   F(MaterializeRegExpLiteral, 4, 1)                                  \
458   F(CreateObjectLiteral, 4, 1)                                       \
459   F(CreateArrayLiteral, 4, 1)                                        \
460   F(CreateArrayLiteralStubBailout, 3, 1)                             \
461                                                                      \
462   /* Statements */                                                   \
463   F(NewClosure, 3, 1)                                                \
464   F(NewClosureFromStubFailure, 1, 1)                                 \
465   F(NewObject, 1, 1)                                                 \
466   F(NewObjectWithAllocationSite, 2, 1)                               \
467   F(FinalizeInstanceSize, 1, 1)                                      \
468   F(Throw, 1, 1)                                                     \
469   F(ReThrow, 1, 1)                                                   \
470   F(ThrowReferenceError, 1, 1)                                       \
471   F(ThrowNotDateError, 0, 1)                                         \
472   F(StackGuard, 0, 1)                                                \
473   F(Interrupt, 0, 1)                                                 \
474   F(PromoteScheduledException, 0, 1)                                 \
475                                                                      \
476   /* Contexts */                                                     \
477   F(NewGlobalContext, 2, 1)                                          \
478   F(NewFunctionContext, 1, 1)                                        \
479   F(PushWithContext, 2, 1)                                           \
480   F(PushCatchContext, 3, 1)                                          \
481   F(PushBlockContext, 2, 1)                                          \
482   F(PushModuleContext, 2, 1)                                         \
483   F(DeleteLookupSlot, 2, 1)                                          \
484   F(LoadLookupSlot, 2, 2)                                            \
485   F(LoadLookupSlotNoReferenceError, 2, 2)                            \
486   F(StoreLookupSlot, 4, 1)                                           \
487                                                                      \
488   /* Declarations and initialization */                              \
489   F(DeclareGlobals, 3, 1)                                            \
490   F(DeclareModules, 1, 1)                                            \
491   F(DeclareLookupSlot, 4, 1)                                         \
492   F(InitializeConstGlobal, 2, 1)                                     \
493   F(InitializeLegacyConstLookupSlot, 3, 1)                           \
494                                                                      \
495   /* Eval */                                                         \
496   F(ResolvePossiblyDirectEval, 5, 2)                                 \
497                                                                      \
498   /* Maths */                                                        \
499   F(MathPowSlow, 2, 1)                                               \
500   F(MathPowRT, 2, 1)
501
502
503 #define RUNTIME_FUNCTION_LIST_DEBUGGER(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(DebugCallbackSupportsStepping, 1, 1) \
545   F(SystemBreak, 0, 1) \
546   F(DebugDisassembleFunction, 1, 1) \
547   F(DebugDisassembleConstructor, 1, 1) \
548   F(FunctionGetInferredName, 1, 1) \
549   F(LiveEditFindSharedFunctionInfosForScript, 1, 1) \
550   F(LiveEditGatherCompileInfo, 2, 1) \
551   F(LiveEditReplaceScript, 3, 1) \
552   F(LiveEditReplaceFunctionCode, 2, 1) \
553   F(LiveEditFunctionSourceUpdated, 1, 1) \
554   F(LiveEditFunctionSetScript, 2, 1) \
555   F(LiveEditReplaceRefToNestedFunction, 3, 1) \
556   F(LiveEditPatchFunctionPositions, 2, 1) \
557   F(LiveEditCheckAndDropActivations, 2, 1) \
558   F(LiveEditCompareStrings, 2, 1) \
559   F(LiveEditRestartFrame, 2, 1) \
560   F(GetFunctionCodePositionFromSource, 2, 1) \
561   F(ExecuteInDebugContext, 2, 1) \
562   \
563   F(SetFlags, 1, 1) \
564   F(CollectGarbage, 1, 1) \
565   F(GetHeapUsage, 0, 1) \
566
567
568 #ifdef V8_I18N_SUPPORT
569 #define RUNTIME_FUNCTION_LIST_I18N_SUPPORT(F) \
570   /* i18n support */ \
571   /* Standalone, helper methods. */ \
572   F(CanonicalizeLanguageTag, 1, 1) \
573   F(AvailableLocalesOf, 1, 1) \
574   F(GetDefaultICULocale, 0, 1) \
575   F(GetLanguageTagVariants, 1, 1) \
576   F(IsInitializedIntlObject, 1, 1) \
577   F(IsInitializedIntlObjectOfType, 2, 1) \
578   F(MarkAsInitializedIntlObjectOfType, 3, 1) \
579   F(GetImplFromInitializedIntlObject, 1, 1) \
580   \
581   /* Date format and parse. */ \
582   F(CreateDateTimeFormat, 3, 1) \
583   F(InternalDateFormat, 2, 1) \
584   F(InternalDateParse, 2, 1) \
585   \
586   /* Number format and parse. */ \
587   F(CreateNumberFormat, 3, 1) \
588   F(InternalNumberFormat, 2, 1) \
589   F(InternalNumberParse, 2, 1) \
590   \
591   /* Collator. */ \
592   F(CreateCollator, 3, 1) \
593   F(InternalCompare, 3, 1) \
594   \
595   /* String.prototype.normalize. */ \
596   F(StringNormalize, 2, 1) \
597   \
598   /* Break iterator. */ \
599   F(CreateBreakIterator, 3, 1) \
600   F(BreakIteratorAdoptText, 2, 1) \
601   F(BreakIteratorFirst, 1, 1) \
602   F(BreakIteratorNext, 1, 1) \
603   F(BreakIteratorCurrent, 1, 1) \
604   F(BreakIteratorBreakType, 1, 1) \
605
606 #else
607 #define RUNTIME_FUNCTION_LIST_I18N_SUPPORT(F)
608 #endif
609
610
611 #ifdef DEBUG
612 #define RUNTIME_FUNCTION_LIST_DEBUG(F) \
613   /* Testing */ \
614   F(ListNatives, 0, 1)
615 #else
616 #define RUNTIME_FUNCTION_LIST_DEBUG(F)
617 #endif
618
619 // ----------------------------------------------------------------------------
620 // RUNTIME_FUNCTION_LIST defines all runtime functions accessed
621 // either directly by id (via the code generator), or indirectly
622 // via a native call by name (from within JS code).
623 // Entries have the form F(name, number of arguments, number of return values).
624
625 #define RUNTIME_FUNCTION_LIST(F) \
626   RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
627   RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
628   RUNTIME_FUNCTION_LIST_ALWAYS_3(F) \
629   RUNTIME_FUNCTION_LIST_DEBUG(F) \
630   RUNTIME_FUNCTION_LIST_DEBUGGER(F) \
631   RUNTIME_FUNCTION_LIST_I18N_SUPPORT(F)
632
633 // ----------------------------------------------------------------------------
634 // INLINE_FUNCTION_LIST defines all inlined functions accessed
635 // with a native call of the form %_name from within JS code.
636 // Entries have the form F(name, number of arguments, number of return values).
637 #define INLINE_FUNCTION_LIST(F) \
638   F(IsSmi, 1, 1)                                                             \
639   F(IsNonNegativeSmi, 1, 1)                                                  \
640   F(IsArray, 1, 1)                                                           \
641   F(IsRegExp, 1, 1)                                                          \
642   F(IsConstructCall, 0, 1)                                                   \
643   F(CallFunction, -1 /* receiver + n args + function */, 1)                  \
644   F(ArgumentsLength, 0, 1)                                                   \
645   F(Arguments, 1, 1)                                                         \
646   F(ValueOf, 1, 1)                                                           \
647   F(SetValueOf, 2, 1)                                                        \
648   F(DateField, 2 /* date object, field index */, 1)                          \
649   F(StringCharFromCode, 1, 1)                                                \
650   F(StringCharAt, 2, 1)                                                      \
651   F(OneByteSeqStringSetChar, 3, 1)                                           \
652   F(TwoByteSeqStringSetChar, 3, 1)                                           \
653   F(ObjectEquals, 2, 1)                                                      \
654   F(IsObject, 1, 1)                                                          \
655   F(IsFunction, 1, 1)                                                        \
656   F(IsUndetectableObject, 1, 1)                                              \
657   F(IsSpecObject, 1, 1)                                                      \
658   F(IsStringWrapperSafeForDefaultValueOf, 1, 1)                              \
659   F(MathPow, 2, 1)                                                           \
660   F(IsMinusZero, 1, 1)                                                       \
661   F(HasCachedArrayIndex, 1, 1)                                               \
662   F(GetCachedArrayIndex, 1, 1)                                               \
663   F(FastAsciiArrayJoin, 2, 1)                                                \
664   F(GeneratorNext, 2, 1)                                                     \
665   F(GeneratorThrow, 2, 1)                                                    \
666   F(DebugBreakInOptimizedCode, 0, 1)                                         \
667   F(ClassOf, 1, 1)                                                           \
668   F(StringCharCodeAt, 2, 1)                                                  \
669   F(StringAdd, 2, 1)                                                         \
670   F(SubString, 3, 1)                                                         \
671   F(StringCompare, 2, 1)                                                     \
672   F(RegExpExec, 4, 1)                                                        \
673   F(RegExpConstructResult, 3, 1)                                             \
674   F(GetFromCache, 2, 1)                                                      \
675   F(NumberToString, 1, 1)                                                    \
676   F(DebugIsActive, 0, 1)
677
678
679 // ----------------------------------------------------------------------------
680 // INLINE_OPTIMIZED_FUNCTION_LIST defines all inlined functions accessed
681 // with a native call of the form %_name from within JS code that also have
682 // a corresponding runtime function, that is called from non-optimized code.
683 // For the benefit of (fuzz) tests, the runtime version can also be called
684 // directly as %name (i.e. without the leading underscore).
685 // Entries have the form F(name, number of arguments, number of return values).
686 #define INLINE_OPTIMIZED_FUNCTION_LIST(F) \
687   /* Typed Arrays */                                                         \
688   F(TypedArrayInitialize, 5, 1)                                              \
689   F(DataViewInitialize, 4, 1)                                                \
690   F(MaxSmi, 0, 1)                                                            \
691   F(TypedArrayMaxSizeInHeap, 0, 1)                                           \
692   F(ArrayBufferViewGetByteLength, 1, 1)                                      \
693   F(ArrayBufferViewGetByteOffset, 1, 1)                                      \
694   F(TypedArrayGetLength, 1, 1)                                               \
695   /* ArrayBuffer */                                                          \
696   F(ArrayBufferGetByteLength, 1, 1)                                          \
697   /* Maths */                                                                \
698   F(ConstructDouble, 2, 1)                                                   \
699   F(DoubleHi, 1, 1)                                                          \
700   F(DoubleLo, 1, 1)                                                          \
701   F(MathSqrtRT, 1, 1)                                                        \
702   F(MathLogRT, 1, 1)
703
704
705 //---------------------------------------------------------------------------
706 // Runtime provides access to all C++ runtime functions.
707
708 class RuntimeState {
709  public:
710   StaticResource<ConsStringIteratorOp>* string_iterator() {
711     return &string_iterator_;
712   }
713   unibrow::Mapping<unibrow::ToUppercase, 128>* to_upper_mapping() {
714     return &to_upper_mapping_;
715   }
716   unibrow::Mapping<unibrow::ToLowercase, 128>* to_lower_mapping() {
717     return &to_lower_mapping_;
718   }
719   ConsStringIteratorOp* string_iterator_compare_x() {
720     return &string_iterator_compare_x_;
721   }
722   ConsStringIteratorOp* string_iterator_compare_y() {
723     return &string_iterator_compare_y_;
724   }
725   ConsStringIteratorOp* string_locale_compare_it1() {
726     return &string_locale_compare_it1_;
727   }
728   ConsStringIteratorOp* string_locale_compare_it2() {
729     return &string_locale_compare_it2_;
730   }
731
732  private:
733   RuntimeState() {}
734   // Non-reentrant string buffer for efficient general use in the runtime.
735   StaticResource<ConsStringIteratorOp> string_iterator_;
736   unibrow::Mapping<unibrow::ToUppercase, 128> to_upper_mapping_;
737   unibrow::Mapping<unibrow::ToLowercase, 128> to_lower_mapping_;
738   ConsStringIteratorOp string_iterator_compare_x_;
739   ConsStringIteratorOp string_iterator_compare_y_;
740   ConsStringIteratorOp string_locale_compare_it1_;
741   ConsStringIteratorOp string_locale_compare_it2_;
742
743   friend class Isolate;
744   friend class Runtime;
745
746   DISALLOW_COPY_AND_ASSIGN(RuntimeState);
747 };
748
749
750 class Runtime : public AllStatic {
751  public:
752   enum FunctionId {
753 #define F(name, nargs, ressize) k##name,
754     RUNTIME_FUNCTION_LIST(F)
755     INLINE_OPTIMIZED_FUNCTION_LIST(F)
756 #undef F
757 #define F(name, nargs, ressize) kInline##name,
758     INLINE_FUNCTION_LIST(F)
759 #undef F
760 #define F(name, nargs, ressize) kInlineOptimized##name,
761     INLINE_OPTIMIZED_FUNCTION_LIST(F)
762 #undef F
763     kNumFunctions,
764     kFirstInlineFunction = kInlineIsSmi
765   };
766
767   enum IntrinsicType {
768     RUNTIME,
769     INLINE,
770     INLINE_OPTIMIZED
771   };
772
773   // Intrinsic function descriptor.
774   struct Function {
775     FunctionId function_id;
776     IntrinsicType intrinsic_type;
777     // The JS name of the function.
778     const char* name;
779
780     // The C++ (native) entry point.  NULL if the function is inlined.
781     byte* entry;
782
783     // The number of arguments expected. nargs is -1 if the function takes
784     // a variable number of arguments.
785     int nargs;
786     // Size of result.  Most functions return a single pointer, size 1.
787     int result_size;
788   };
789
790   static const int kNotFound = -1;
791
792   // Add internalized strings for all the intrinsic function names to a
793   // StringDictionary.
794   static void InitializeIntrinsicFunctionNames(Isolate* isolate,
795                                                Handle<NameDictionary> dict);
796
797   // Get the intrinsic function with the given name, which must be internalized.
798   static const Function* FunctionForName(Handle<String> name);
799
800   // Get the intrinsic function with the given FunctionId.
801   static const Function* FunctionForId(FunctionId id);
802
803   // Get the intrinsic function with the given function entry address.
804   static const Function* FunctionForEntry(Address ref);
805
806   // General-purpose helper functions for runtime system.
807   static int StringMatch(Isolate* isolate,
808                          Handle<String> sub,
809                          Handle<String> pat,
810                          int index);
811
812   static bool IsUpperCaseChar(RuntimeState* runtime_state, uint16_t ch);
813
814   // TODO(1240886): Some of the following methods are *not* handle safe, but
815   // accept handle arguments. This seems fragile.
816
817   // Support getting the characters in a string using [] notation as
818   // in Firefox/SpiderMonkey, Safari and Opera.
819   MUST_USE_RESULT static MaybeHandle<Object> GetElementOrCharAt(
820       Isolate* isolate,
821       Handle<Object> object,
822       uint32_t index);
823
824   MUST_USE_RESULT static MaybeHandle<Object> SetObjectProperty(
825       Isolate* isolate, Handle<Object> object, Handle<Object> key,
826       Handle<Object> value, StrictMode strict_mode);
827
828   MUST_USE_RESULT static MaybeHandle<Object> DefineObjectProperty(
829       Handle<JSObject> object,
830       Handle<Object> key,
831       Handle<Object> value,
832       PropertyAttributes attr,
833       JSReceiver::StoreFromKeyed store_from_keyed =
834           JSReceiver::MAY_BE_STORE_FROM_KEYED);
835
836   MUST_USE_RESULT static MaybeHandle<Object> DeleteObjectProperty(
837       Isolate* isolate,
838       Handle<JSReceiver> object,
839       Handle<Object> key,
840       JSReceiver::DeleteMode mode);
841
842   MUST_USE_RESULT static MaybeHandle<Object> HasObjectProperty(
843       Isolate* isolate,
844       Handle<JSReceiver> object,
845       Handle<Object> key);
846
847   MUST_USE_RESULT static MaybeHandle<Object> GetObjectProperty(
848       Isolate* isolate,
849       Handle<Object> object,
850       Handle<Object> key);
851
852   static void SetupArrayBuffer(Isolate* isolate,
853                                Handle<JSArrayBuffer> array_buffer,
854                                bool is_external,
855                                void* data,
856                                size_t allocated_length);
857
858   static bool SetupArrayBufferAllocatingData(
859       Isolate* isolate,
860       Handle<JSArrayBuffer> array_buffer,
861       size_t allocated_length,
862       bool initialize = true);
863
864   static void NeuterArrayBuffer(Handle<JSArrayBuffer> array_buffer);
865
866   static void FreeArrayBuffer(
867       Isolate* isolate,
868       JSArrayBuffer* phantom_array_buffer);
869
870   enum TypedArrayId {
871     // arrayIds below should be synchromized with typedarray.js natives.
872     ARRAY_ID_UINT8 = 1,
873     ARRAY_ID_INT8 = 2,
874     ARRAY_ID_UINT16 = 3,
875     ARRAY_ID_INT16 = 4,
876     ARRAY_ID_UINT32 = 5,
877     ARRAY_ID_INT32 = 6,
878     ARRAY_ID_FLOAT32 = 7,
879     ARRAY_ID_FLOAT64 = 8,
880     ARRAY_ID_UINT8_CLAMPED = 9,
881
882     ARRAY_ID_FIRST = ARRAY_ID_UINT8,
883     ARRAY_ID_LAST = ARRAY_ID_UINT8_CLAMPED
884   };
885
886   static void ArrayIdToTypeAndSize(int array_id,
887       ExternalArrayType *type,
888       ElementsKind* external_elements_kind,
889       ElementsKind* fixed_elements_kind,
890       size_t *element_size);
891
892   // Used in runtime.cc and hydrogen's VisitArrayLiteral.
893   MUST_USE_RESULT static MaybeHandle<Object> CreateArrayLiteralBoilerplate(
894       Isolate* isolate,
895       Handle<FixedArray> literals,
896       Handle<FixedArray> elements);
897 };
898
899
900 //---------------------------------------------------------------------------
901 // Constants used by interface to runtime functions.
902
903 class AllocateDoubleAlignFlag:  public BitField<bool,            0, 1> {};
904 class AllocateTargetSpace:      public BitField<AllocationSpace, 1, 3> {};
905
906 class DeclareGlobalsEvalFlag:   public BitField<bool,       0, 1> {};
907 class DeclareGlobalsNativeFlag: public BitField<bool,       1, 1> {};
908 class DeclareGlobalsStrictMode: public BitField<StrictMode, 2, 1> {};
909
910 } }  // namespace v8::internal
911
912 #endif  // V8_RUNTIME_H_