Upstream version 7.36.149.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 "allocation.h"
9 #include "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(HasLocalProperty, 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(GetLocalPropertyNames, 2, 1) \
36   F(GetLocalElementNames, 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, 1, 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(MathFloor, 1, 1) \
142   F(MathAtan2, 2, 1) \
143   F(MathExp, 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(FunctionSetReadOnlyPrototype, 1, 1) \
254   F(FunctionGetName, 1, 1) \
255   F(FunctionSetName, 2, 1) \
256   F(FunctionNameShouldPrintAsAnonymous, 1, 1) \
257   F(FunctionMarkNameShouldPrintAsAnonymous, 1, 1) \
258   F(FunctionIsGenerator, 1, 1) \
259   F(FunctionBindArguments, 4, 1) \
260   F(BoundFunctionGetBindings, 1, 1) \
261   F(FunctionRemovePrototype, 1, 1) \
262   F(FunctionGetSourceCode, 1, 1) \
263   F(FunctionGetScript, 1, 1) \
264   F(FunctionGetScriptSourcePosition, 1, 1) \
265   F(FunctionGetPositionForOffset, 2, 1) \
266   F(FunctionIsAPIFunction, 1, 1) \
267   F(FunctionIsBuiltin, 1, 1) \
268   F(GetScript, 1, 1) \
269   F(CollectStackTrace, 3, 1) \
270   F(GetAndClearOverflowedStackTrace, 1, 1) \
271   F(GetV8Version, 0, 1) \
272   \
273   F(SetCode, 2, 1) \
274   F(SetExpectedNumberOfProperties, 2, 1) \
275   \
276   F(CreateApiFunction, 2, 1) \
277   F(IsTemplate, 1, 1) \
278   F(GetTemplateField, 2, 1) \
279   F(DisableAccessChecks, 1, 1) \
280   F(EnableAccessChecks, 1, 1) \
281   F(SetAccessorProperty, 6, 1) \
282   \
283   /* Dates */ \
284   F(DateCurrentTime, 0, 1) \
285   F(DateParseString, 2, 1) \
286   F(DateLocalTimezone, 1, 1) \
287   F(DateToUTC, 1, 1) \
288   F(DateMakeDay, 2, 1) \
289   F(DateSetValue, 3, 1) \
290   F(DateCacheVersion, 0, 1) \
291   \
292   /* Float32x4 and Int32x4 */ \
293   F(CreateFloat32x4, 4, 1) \
294   F(Float32x4GetX, 1, 1) \
295   F(Float32x4GetY, 1, 1) \
296   F(Float32x4GetZ, 1, 1) \
297   F(Float32x4GetW, 1, 1) \
298   F(Float32x4GetSignMask, 1, 1) \
299   F(CreateFloat64x2, 2, 1) \
300   F(Float64x2GetX, 1, 1) \
301   F(Float64x2GetY, 1, 1) \
302   F(Float64x2GetSignMask, 1, 1) \
303   F(CreateInt32x4, 4, 1) \
304   F(Int32x4GetX, 1, 1) \
305   F(Int32x4GetY, 1, 1) \
306   F(Int32x4GetZ, 1, 1) \
307   F(Int32x4GetW, 1, 1) \
308   F(Int32x4GetFlagX, 1, 1) \
309   F(Int32x4GetFlagY, 1, 1) \
310   F(Int32x4GetFlagZ, 1, 1) \
311   F(Int32x4GetFlagW, 1, 1) \
312   F(Int32x4GetSignMask, 1, 1) \
313   \
314   /* Globals */ \
315   F(CompileString, 2, 1) \
316   \
317   /* Eval */ \
318   F(GlobalReceiver, 1, 1) \
319   F(IsAttachedGlobal, 1, 1) \
320   \
321   F(SetProperty, -1 /* 4 or 5 */, 1) \
322   F(DefineOrRedefineDataProperty, 4, 1) \
323   F(DefineOrRedefineAccessorProperty, 5, 1) \
324   F(IgnoreAttributesAndSetProperty, -1 /* 3 or 4 */, 1) \
325   F(GetDataProperty, 2, 1) \
326   F(SetHiddenProperty, 3, 1) \
327   \
328   /* Arrays */ \
329   F(RemoveArrayHoles, 2, 1) \
330   F(GetArrayKeys, 2, 1) \
331   F(MoveArrayContents, 2, 1) \
332   F(EstimateNumberOfElements, 1, 1) \
333   \
334   /* Getters and Setters */ \
335   F(LookupAccessor, 3, 1) \
336   \
337   /* ES5 */ \
338   F(ObjectFreeze, 1, 1) \
339   \
340   /* Harmony microtasks */ \
341   F(GetMicrotaskState, 0, 1) \
342   \
343   /* Harmony modules */ \
344   F(IsJSModule, 1, 1) \
345   \
346   /* Harmony symbols */ \
347   F(CreateSymbol, 1, 1) \
348   F(CreatePrivateSymbol, 1, 1) \
349   F(CreateGlobalPrivateSymbol, 1, 1) \
350   F(NewSymbolWrapper, 1, 1) \
351   F(SymbolDescription, 1, 1) \
352   F(SymbolRegistry, 0, 1) \
353   F(SymbolIsPrivate, 1, 1) \
354   \
355   /* Harmony proxies */ \
356   F(CreateJSProxy, 2, 1) \
357   F(CreateJSFunctionProxy, 4, 1) \
358   F(IsJSProxy, 1, 1) \
359   F(IsJSFunctionProxy, 1, 1) \
360   F(GetHandler, 1, 1) \
361   F(GetCallTrap, 1, 1) \
362   F(GetConstructTrap, 1, 1) \
363   F(Fix, 1, 1) \
364   \
365   /* Harmony sets */ \
366   F(SetInitialize, 1, 1) \
367   F(SetAdd, 2, 1) \
368   F(SetHas, 2, 1) \
369   F(SetDelete, 2, 1) \
370   F(SetClear, 1, 1) \
371   F(SetGetSize, 1, 1) \
372   F(SetCreateIterator, 2, 1) \
373   \
374   F(SetIteratorNext, 1, 1) \
375   F(SetIteratorClose, 1, 1) \
376   \
377   /* Harmony maps */ \
378   F(MapInitialize, 1, 1) \
379   F(MapGet, 2, 1) \
380   F(MapHas, 2, 1) \
381   F(MapDelete, 2, 1) \
382   F(MapClear, 1, 1) \
383   F(MapSet, 3, 1) \
384   F(MapGetSize, 1, 1) \
385   F(MapCreateIterator, 2, 1) \
386   \
387   F(MapIteratorNext, 1, 1) \
388   F(MapIteratorClose, 1, 1) \
389   \
390   /* Harmony weak maps and sets */ \
391   F(WeakCollectionInitialize, 1, 1) \
392   F(WeakCollectionGet, 2, 1) \
393   F(WeakCollectionHas, 2, 1) \
394   F(WeakCollectionDelete, 2, 1) \
395   F(WeakCollectionSet, 3, 1) \
396   \
397   /* Harmony events */ \
398   F(SetMicrotaskPending, 1, 1) \
399   F(RunMicrotasks, 0, 1) \
400   \
401   /* Harmony observe */ \
402   F(IsObserved, 1, 1) \
403   F(SetIsObserved, 1, 1) \
404   F(GetObservationState, 0, 1) \
405   F(ObservationWeakMapCreate, 0, 1) \
406   F(ObserverObjectAndRecordHaveSameOrigin, 3, 1) \
407   F(ObjectWasCreatedInCurrentOrigin, 1, 1) \
408   F(ObjectObserveInObjectContext, 3, 1) \
409   F(ObjectGetNotifierInObjectContext, 1, 1) \
410   F(ObjectNotifierPerformChangeInObjectContext, 3, 1) \
411   \
412   /* Harmony typed arrays */ \
413   F(ArrayBufferInitialize, 2, 1)\
414   F(ArrayBufferSliceImpl, 3, 1) \
415   F(ArrayBufferIsView, 1, 1) \
416   F(ArrayBufferNeuter, 1, 1) \
417   \
418   F(TypedArrayInitializeFromArrayLike, 4, 1) \
419   F(TypedArrayGetBuffer, 1, 1) \
420   F(TypedArraySetFastCases, 3, 1) \
421   \
422   F(DataViewGetBuffer, 1, 1) \
423   F(DataViewGetInt8, 3, 1) \
424   F(DataViewGetUint8, 3, 1) \
425   F(DataViewGetInt16, 3, 1) \
426   F(DataViewGetUint16, 3, 1) \
427   F(DataViewGetInt32, 3, 1) \
428   F(DataViewGetUint32, 3, 1) \
429   F(DataViewGetFloat32, 3, 1) \
430   F(DataViewGetFloat64, 3, 1) \
431   \
432   F(DataViewSetInt8, 4, 1) \
433   F(DataViewSetUint8, 4, 1) \
434   F(DataViewSetInt16, 4, 1) \
435   F(DataViewSetUint16, 4, 1) \
436   F(DataViewSetInt32, 4, 1) \
437   F(DataViewSetUint32, 4, 1) \
438   F(DataViewSetFloat32, 4, 1) \
439   F(DataViewSetFloat64, 4, 1) \
440   \
441   /* Statements */ \
442   F(NewObjectFromBound, 1, 1) \
443   \
444   /* Declarations and initialization */ \
445   F(InitializeVarGlobal, -1 /* 2 or 3 */, 1) \
446   F(OptimizeObjectForAddingMultipleProperties, 2, 1) \
447   \
448   /* Debugging */ \
449   F(DebugPrint, 1, 1) \
450   F(GlobalPrint, 1, 1) \
451   F(DebugTrace, 0, 1) \
452   F(TraceEnter, 0, 1) \
453   F(TraceExit, 1, 1) \
454   F(Abort, 1, 1) \
455   F(AbortJS, 1, 1) \
456   /* ES5 */ \
457   F(LocalKeys, 1, 1) \
458   \
459   /* Message objects */ \
460   F(MessageGetStartPosition, 1, 1) \
461   F(MessageGetScript, 1, 1) \
462   \
463   /* Pseudo functions - handled as macros by parser */ \
464   F(IS_VAR, 1, 1) \
465   \
466   /* expose boolean functions from objects-inl.h */ \
467   F(HasFastSmiElements, 1, 1) \
468   F(HasFastSmiOrObjectElements, 1, 1) \
469   F(HasFastObjectElements, 1, 1) \
470   F(HasFastDoubleElements, 1, 1) \
471   F(HasFastHoleyElements, 1, 1) \
472   F(HasDictionaryElements, 1, 1) \
473   F(HasSloppyArgumentsElements, 1, 1) \
474   F(HasExternalUint8ClampedElements, 1, 1) \
475   F(HasExternalArrayElements, 1, 1) \
476   F(HasExternalInt8Elements, 1, 1) \
477   F(HasExternalUint8Elements, 1, 1) \
478   F(HasExternalInt16Elements, 1, 1) \
479   F(HasExternalUint16Elements, 1, 1) \
480   F(HasExternalInt32Elements, 1, 1) \
481   F(HasExternalUint32Elements, 1, 1) \
482   F(HasExternalFloat32Elements, 1, 1) \
483   F(HasExternalFloat32x4Elements, 1, 1) \
484   F(HasExternalInt32x4Elements, 1, 1) \
485   F(HasExternalFloat64Elements, 1, 1) \
486   F(HasExternalFloat64x2Elements, 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(IsJSGlobalProxy, 1, 1)
500
501
502 #define RUNTIME_FUNCTION_LIST_DEBUGGER(F) \
503   /* Debugger support*/ \
504   F(DebugBreak, 0, 1) \
505   F(SetDebugEventListener, 2, 1) \
506   F(Break, 0, 1) \
507   F(DebugGetPropertyDetails, 2, 1) \
508   F(DebugGetProperty, 2, 1) \
509   F(DebugPropertyTypeFromDetails, 1, 1) \
510   F(DebugPropertyAttributesFromDetails, 1, 1) \
511   F(DebugPropertyIndexFromDetails, 1, 1) \
512   F(DebugNamedInterceptorPropertyValue, 2, 1) \
513   F(DebugIndexedInterceptorElementValue, 2, 1) \
514   F(CheckExecutionState, 1, 1) \
515   F(GetFrameCount, 1, 1) \
516   F(GetFrameDetails, 2, 1) \
517   F(GetScopeCount, 2, 1) \
518   F(GetStepInPositions, 2, 1) \
519   F(GetScopeDetails, 4, 1) \
520   F(GetAllScopesDetails, 4, 1) \
521   F(GetFunctionScopeCount, 1, 1) \
522   F(GetFunctionScopeDetails, 2, 1) \
523   F(SetScopeVariableValue, 6, 1) \
524   F(DebugPrintScopes, 0, 1) \
525   F(GetThreadCount, 1, 1) \
526   F(GetThreadDetails, 2, 1) \
527   F(SetDisableBreak, 1, 1) \
528   F(GetBreakLocations, 2, 1) \
529   F(SetFunctionBreakPoint, 3, 1) \
530   F(SetScriptBreakPoint, 4, 1) \
531   F(ClearBreakPoint, 1, 1) \
532   F(ChangeBreakOnException, 2, 1) \
533   F(IsBreakOnException, 1, 1) \
534   F(PrepareStep, 4, 1) \
535   F(ClearStepping, 0, 1) \
536   F(DebugEvaluate, 6, 1) \
537   F(DebugEvaluateGlobal, 4, 1) \
538   F(DebugGetLoadedScripts, 0, 1) \
539   F(DebugReferencedBy, 3, 1) \
540   F(DebugConstructedBy, 2, 1) \
541   F(DebugGetPrototype, 1, 1) \
542   F(DebugSetScriptSource, 2, 1) \
543   F(SystemBreak, 0, 1) \
544   F(DebugDisassembleFunction, 1, 1) \
545   F(DebugDisassembleConstructor, 1, 1) \
546   F(FunctionGetInferredName, 1, 1) \
547   F(LiveEditFindSharedFunctionInfosForScript, 1, 1) \
548   F(LiveEditGatherCompileInfo, 2, 1) \
549   F(LiveEditReplaceScript, 3, 1) \
550   F(LiveEditReplaceFunctionCode, 2, 1) \
551   F(LiveEditFunctionSourceUpdated, 1, 1) \
552   F(LiveEditFunctionSetScript, 2, 1) \
553   F(LiveEditReplaceRefToNestedFunction, 3, 1) \
554   F(LiveEditPatchFunctionPositions, 2, 1) \
555   F(LiveEditCheckAndDropActivations, 2, 1) \
556   F(LiveEditCompareStrings, 2, 1) \
557   F(LiveEditRestartFrame, 2, 1) \
558   F(GetFunctionCodePositionFromSource, 2, 1) \
559   F(ExecuteInDebugContext, 2, 1) \
560   \
561   F(SetFlags, 1, 1) \
562   F(CollectGarbage, 1, 1) \
563   F(GetHeapUsage, 0, 1) \
564
565
566 #ifdef V8_I18N_SUPPORT
567 #define RUNTIME_FUNCTION_LIST_I18N_SUPPORT(F) \
568   /* i18n support */ \
569   /* Standalone, helper methods. */ \
570   F(CanonicalizeLanguageTag, 1, 1) \
571   F(AvailableLocalesOf, 1, 1) \
572   F(GetDefaultICULocale, 0, 1) \
573   F(GetLanguageTagVariants, 1, 1) \
574   F(IsInitializedIntlObject, 1, 1) \
575   F(IsInitializedIntlObjectOfType, 2, 1) \
576   F(MarkAsInitializedIntlObjectOfType, 3, 1) \
577   F(GetImplFromInitializedIntlObject, 1, 1) \
578   \
579   /* Date format and parse. */ \
580   F(CreateDateTimeFormat, 3, 1) \
581   F(InternalDateFormat, 2, 1) \
582   F(InternalDateParse, 2, 1) \
583   \
584   /* Number format and parse. */ \
585   F(CreateNumberFormat, 3, 1) \
586   F(InternalNumberFormat, 2, 1) \
587   F(InternalNumberParse, 2, 1) \
588   \
589   /* Collator. */ \
590   F(CreateCollator, 3, 1) \
591   F(InternalCompare, 3, 1) \
592   \
593   /* String.prototype.normalize. */ \
594   F(StringNormalize, 2, 1) \
595   \
596   /* Break iterator. */ \
597   F(CreateBreakIterator, 3, 1) \
598   F(BreakIteratorAdoptText, 2, 1) \
599   F(BreakIteratorFirst, 1, 1) \
600   F(BreakIteratorNext, 1, 1) \
601   F(BreakIteratorCurrent, 1, 1) \
602   F(BreakIteratorBreakType, 1, 1) \
603
604 #else
605 #define RUNTIME_FUNCTION_LIST_I18N_SUPPORT(F)
606 #endif
607
608
609 #ifdef DEBUG
610 #define RUNTIME_FUNCTION_LIST_DEBUG(F) \
611   /* Testing */ \
612   F(ListNatives, 0, 1)
613 #else
614 #define RUNTIME_FUNCTION_LIST_DEBUG(F)
615 #endif
616
617 // ----------------------------------------------------------------------------
618 // RUNTIME_FUNCTION_LIST defines all runtime functions accessed
619 // either directly by id (via the code generator), or indirectly
620 // via a native call by name (from within JS code).
621 // Entries have the form F(name, number of arguments, number of return values).
622
623 #define RUNTIME_FUNCTION_LIST(F) \
624   RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
625   RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
626   RUNTIME_FUNCTION_LIST_DEBUG(F) \
627   RUNTIME_FUNCTION_LIST_DEBUGGER(F) \
628   RUNTIME_FUNCTION_LIST_I18N_SUPPORT(F)
629
630 // RUNTIME_HIDDEN_FUNCTION_LIST defines all runtime functions accessed
631 // by id from code generator, but not via native call by name.
632 // Entries have the form F(name, number of arguments, number of return values).
633 #define RUNTIME_HIDDEN_FUNCTION_LIST(F) \
634   /* String and Regexp */ \
635   F(NumberToString, 1, 1) \
636   F(RegExpConstructResult, 3, 1) \
637   F(RegExpExec, 4, 1) \
638   F(StringAdd, 2, 1)  \
639   F(SubString, 3, 1) \
640   F(StringCompare, 2, 1) \
641   F(StringCharCodeAt, 2, 1) \
642   F(Log, 3, 1) \
643   F(GetFromCache, 2, 1) \
644   \
645   /* Compilation */ \
646   F(CompileUnoptimized, 1, 1) \
647   F(CompileOptimized, 2, 1) \
648   F(TryInstallOptimizedCode, 1, 1) \
649   F(NotifyDeoptimized, 1, 1) \
650   F(NotifyStubFailure, 0, 1) \
651   \
652   /* Utilities */ \
653   F(AllocateInNewSpace, 1, 1) \
654   F(AllocateInTargetSpace, 2, 1) \
655   F(AllocateHeapNumber, 0, 1) \
656   F(NumberToSmi, 1, 1) \
657   F(NumberToStringSkipCache, 1, 1) \
658   \
659   F(NewArgumentsFast, 3, 1) \
660   F(NewStrictArgumentsFast, 3, 1) \
661   \
662   /* Harmony generators */ \
663   F(CreateJSGeneratorObject, 0, 1) \
664   F(SuspendJSGeneratorObject, 1, 1) \
665   F(ResumeJSGeneratorObject, 3, 1) \
666   F(ThrowGeneratorStateError, 1, 1) \
667   \
668   /* Arrays */ \
669   F(ArrayConstructor, -1, 1) \
670   F(InternalArrayConstructor, -1, 1) \
671   \
672   /* Literals */ \
673   F(MaterializeRegExpLiteral, 4, 1)\
674   F(CreateObjectLiteral, 4, 1) \
675   F(CreateArrayLiteral, 4, 1) \
676   F(CreateArrayLiteralStubBailout, 3, 1) \
677   \
678   /* Statements */ \
679   F(NewClosure, 3, 1) \
680   F(NewClosureFromStubFailure, 1, 1) \
681   F(NewObject, 1, 1) \
682   F(NewObjectWithAllocationSite, 2, 1) \
683   F(FinalizeInstanceSize, 1, 1) \
684   F(Throw, 1, 1) \
685   F(ReThrow, 1, 1) \
686   F(ThrowReferenceError, 1, 1) \
687   F(ThrowNotDateError, 0, 1) \
688   F(ThrowMessage, 1, 1) \
689   F(StackGuard, 0, 1) \
690   F(Interrupt, 0, 1) \
691   F(PromoteScheduledException, 0, 1) \
692   \
693   /* Contexts */ \
694   F(NewGlobalContext, 2, 1) \
695   F(NewFunctionContext, 1, 1) \
696   F(PushWithContext, 2, 1) \
697   F(PushCatchContext, 3, 1) \
698   F(PushBlockContext, 2, 1) \
699   F(PushModuleContext, 2, 1) \
700   F(DeleteContextSlot, 2, 1) \
701   F(LoadContextSlot, 2, 2) \
702   F(LoadContextSlotNoReferenceError, 2, 2) \
703   F(StoreContextSlot, 4, 1) \
704   \
705   /* Declarations and initialization */ \
706   F(DeclareGlobals, 3, 1) \
707   F(DeclareModules, 1, 1) \
708   F(DeclareContextSlot, 4, 1) \
709   F(InitializeConstGlobal, 2, 1) \
710   F(InitializeConstContextSlot, 3, 1) \
711   \
712   /* Eval */ \
713   F(ResolvePossiblyDirectEval, 5, 2) \
714   \
715   /* Maths */ \
716   F(MathPowSlow, 2, 1) \
717   F(MathPow, 2, 1)
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(IsMinusZero, 1, 1)                                                       \
747   F(HasCachedArrayIndex, 1, 1)                                               \
748   F(GetCachedArrayIndex, 1, 1)                                               \
749   F(FastAsciiArrayJoin, 2, 1)                                                \
750   F(GeneratorNext, 2, 1)                                                     \
751   F(GeneratorThrow, 2, 1)                                                    \
752   F(DebugBreakInOptimizedCode, 0, 1)                                         \
753   F(ClassOf, 1, 1)                                                           \
754   F(StringCharCodeAt, 2, 1)                                                  \
755   F(Log, 3, 1)                                                               \
756   F(StringAdd, 2, 1)                                                         \
757   F(SubString, 3, 1)                                                         \
758   F(StringCompare, 2, 1)                                                     \
759   F(RegExpExec, 4, 1)                                                        \
760   F(RegExpConstructResult, 3, 1)                                             \
761   F(GetFromCache, 2, 1)                                                      \
762   F(NumberToString, 1, 1)
763
764
765 // ----------------------------------------------------------------------------
766 // INLINE_OPTIMIZED_FUNCTION_LIST defines all inlined functions accessed
767 // with a native call of the form %_name from within JS code that also have
768 // a corresponding runtime function, that is called from non-optimized code.
769 // Entries have the form F(name, number of arguments, number of return values).
770 #define INLINE_OPTIMIZED_FUNCTION_LIST(F) \
771   /* Typed Arrays */                                                         \
772   F(TypedArrayInitialize, 5, 1)                                              \
773   F(DataViewInitialize, 4, 1)                                                \
774   F(MaxSmi, 0, 1)                                                            \
775   F(TypedArrayMaxSizeInHeap, 0, 1)                                           \
776   F(ArrayBufferViewGetByteLength, 1, 1)                                      \
777   F(ArrayBufferViewGetByteOffset, 1, 1)                                      \
778   F(TypedArrayGetLength, 1, 1)                                               \
779   /* ArrayBuffer */                                                          \
780   F(ArrayBufferGetByteLength, 1, 1)                                          \
781   /* Maths */                                                                \
782   F(ConstructDouble, 2, 1)                                                   \
783   F(DoubleHi, 1, 1)                                                          \
784   F(DoubleLo, 1, 1)                                                          \
785   F(MathSqrt, 1, 1)                                                          \
786   F(MathLog, 1, 1)                                                           \
787   /* Debugger */                                                             \
788   F(DebugCallbackSupportsStepping, 1, 1)
789
790
791 //---------------------------------------------------------------------------
792 // Runtime provides access to all C++ runtime functions.
793
794 class RuntimeState {
795  public:
796   StaticResource<ConsStringIteratorOp>* string_iterator() {
797     return &string_iterator_;
798   }
799   unibrow::Mapping<unibrow::ToUppercase, 128>* to_upper_mapping() {
800     return &to_upper_mapping_;
801   }
802   unibrow::Mapping<unibrow::ToLowercase, 128>* to_lower_mapping() {
803     return &to_lower_mapping_;
804   }
805   ConsStringIteratorOp* string_iterator_compare_x() {
806     return &string_iterator_compare_x_;
807   }
808   ConsStringIteratorOp* string_iterator_compare_y() {
809     return &string_iterator_compare_y_;
810   }
811   ConsStringIteratorOp* string_locale_compare_it1() {
812     return &string_locale_compare_it1_;
813   }
814   ConsStringIteratorOp* string_locale_compare_it2() {
815     return &string_locale_compare_it2_;
816   }
817
818  private:
819   RuntimeState() {}
820   // Non-reentrant string buffer for efficient general use in the runtime.
821   StaticResource<ConsStringIteratorOp> string_iterator_;
822   unibrow::Mapping<unibrow::ToUppercase, 128> to_upper_mapping_;
823   unibrow::Mapping<unibrow::ToLowercase, 128> to_lower_mapping_;
824   ConsStringIteratorOp string_iterator_compare_x_;
825   ConsStringIteratorOp string_iterator_compare_y_;
826   ConsStringIteratorOp string_locale_compare_it1_;
827   ConsStringIteratorOp string_locale_compare_it2_;
828
829   friend class Isolate;
830   friend class Runtime;
831
832   DISALLOW_COPY_AND_ASSIGN(RuntimeState);
833 };
834
835
836 class Runtime : public AllStatic {
837  public:
838   enum FunctionId {
839 #define F(name, nargs, ressize) k##name,
840     RUNTIME_FUNCTION_LIST(F)
841 #undef F
842 #define F(name, nargs, ressize) kHidden##name,
843     RUNTIME_HIDDEN_FUNCTION_LIST(F)
844 #undef F
845 #define F(name, nargs, ressize) kInline##name,
846     INLINE_FUNCTION_LIST(F)
847 #undef F
848 #define F(name, nargs, ressize) kInlineOptimized##name,
849     INLINE_OPTIMIZED_FUNCTION_LIST(F)
850 #undef F
851     kNumFunctions,
852     kFirstInlineFunction = kInlineIsSmi
853   };
854
855   enum IntrinsicType {
856     RUNTIME,
857     RUNTIME_HIDDEN,
858     INLINE,
859     INLINE_OPTIMIZED
860   };
861
862   // Intrinsic function descriptor.
863   struct Function {
864     FunctionId function_id;
865     IntrinsicType intrinsic_type;
866     // The JS name of the function.
867     const char* name;
868
869     // The C++ (native) entry point.  NULL if the function is inlined.
870     byte* entry;
871
872     // The number of arguments expected. nargs is -1 if the function takes
873     // a variable number of arguments.
874     int nargs;
875     // Size of result.  Most functions return a single pointer, size 1.
876     int result_size;
877   };
878
879   static const int kNotFound = -1;
880
881   // Add internalized strings for all the intrinsic function names to a
882   // StringDictionary.
883   static void InitializeIntrinsicFunctionNames(Isolate* isolate,
884                                                Handle<NameDictionary> dict);
885
886   // Get the intrinsic function with the given name, which must be internalized.
887   static const Function* FunctionForName(Handle<String> name);
888
889   // Get the intrinsic function with the given FunctionId.
890   static const Function* FunctionForId(FunctionId id);
891
892   // General-purpose helper functions for runtime system.
893   static int StringMatch(Isolate* isolate,
894                          Handle<String> sub,
895                          Handle<String> pat,
896                          int index);
897
898   static bool IsUpperCaseChar(RuntimeState* runtime_state, uint16_t ch);
899
900   // TODO(1240886): Some of the following methods are *not* handle safe, but
901   // accept handle arguments. This seems fragile.
902
903   // Support getting the characters in a string using [] notation as
904   // in Firefox/SpiderMonkey, Safari and Opera.
905   MUST_USE_RESULT static MaybeHandle<Object> GetElementOrCharAt(
906       Isolate* isolate,
907       Handle<Object> object,
908       uint32_t index);
909
910   MUST_USE_RESULT static MaybeHandle<Object> SetObjectProperty(
911       Isolate* isolate,
912       Handle<Object> object,
913       Handle<Object> key,
914       Handle<Object> value,
915       PropertyAttributes attr,
916       StrictMode strict_mode);
917
918   MUST_USE_RESULT static MaybeHandle<Object> ForceSetObjectProperty(
919       Handle<JSObject> object,
920       Handle<Object> key,
921       Handle<Object> value,
922       PropertyAttributes attr,
923       JSReceiver::StoreFromKeyed store_from_keyed
924         = JSReceiver::MAY_BE_STORE_FROM_KEYED);
925
926   MUST_USE_RESULT static MaybeHandle<Object> DeleteObjectProperty(
927       Isolate* isolate,
928       Handle<JSReceiver> object,
929       Handle<Object> key,
930       JSReceiver::DeleteMode mode);
931
932   MUST_USE_RESULT static MaybeHandle<Object> HasObjectProperty(
933       Isolate* isolate,
934       Handle<JSReceiver> object,
935       Handle<Object> key);
936
937   MUST_USE_RESULT static MaybeHandle<Object> GetObjectProperty(
938       Isolate* isolate,
939       Handle<Object> object,
940       Handle<Object> key);
941
942   static void SetupArrayBuffer(Isolate* isolate,
943                                Handle<JSArrayBuffer> array_buffer,
944                                bool is_external,
945                                void* data,
946                                size_t allocated_length);
947
948   static bool SetupArrayBufferAllocatingData(
949       Isolate* isolate,
950       Handle<JSArrayBuffer> array_buffer,
951       size_t allocated_length,
952       bool initialize = true);
953
954   static void NeuterArrayBuffer(Handle<JSArrayBuffer> array_buffer);
955
956   static void FreeArrayBuffer(
957       Isolate* isolate,
958       JSArrayBuffer* phantom_array_buffer);
959
960   enum TypedArrayId {
961     // arrayIds below should be synchromized with typedarray.js natives.
962     ARRAY_ID_UINT8 = 1,
963     ARRAY_ID_INT8 = 2,
964     ARRAY_ID_UINT16 = 3,
965     ARRAY_ID_INT16 = 4,
966     ARRAY_ID_UINT32 = 5,
967     ARRAY_ID_INT32 = 6,
968     ARRAY_ID_FLOAT32 = 7,
969     ARRAY_ID_FLOAT64 = 8,
970     ARRAY_ID_UINT8_CLAMPED = 9,
971     ARRAY_ID_FLOAT32x4 = 10,
972     ARRAY_ID_FLOAT64x2 = 11,
973     ARRAY_ID_INT32x4 = 12,
974     ARRAY_ID_FIRST = ARRAY_ID_UINT8,
975     ARRAY_ID_LAST = ARRAY_ID_INT32x4
976   };
977
978   static void ArrayIdToTypeAndSize(int array_id,
979       ExternalArrayType *type,
980       ElementsKind* external_elements_kind,
981       ElementsKind* fixed_elements_kind,
982       size_t *element_size);
983
984   // Used in runtime.cc and hydrogen's VisitArrayLiteral.
985   MUST_USE_RESULT static MaybeHandle<Object> CreateArrayLiteralBoilerplate(
986       Isolate* isolate,
987       Handle<FixedArray> literals,
988       Handle<FixedArray> elements);
989 };
990
991
992 //---------------------------------------------------------------------------
993 // Constants used by interface to runtime functions.
994
995 class AllocateDoubleAlignFlag:  public BitField<bool,            0, 1> {};
996 class AllocateTargetSpace:      public BitField<AllocationSpace, 1, 3> {};
997
998 class DeclareGlobalsEvalFlag:   public BitField<bool,       0, 1> {};
999 class DeclareGlobalsNativeFlag: public BitField<bool,       1, 1> {};
1000 class DeclareGlobalsStrictMode: public BitField<StrictMode, 2, 1> {};
1001
1002 } }  // namespace v8::internal
1003
1004 #endif  // V8_RUNTIME_H_