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