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