c92c457e19a8ed8e2d101d1c81ac3b63c4a912a5
[profile/ivi/qtjsbackend.git] / src / 3rdparty / v8 / src / runtime.h
1 // Copyright 2011 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, 1, 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(ToSlowProperties, 1, 1) \
66   F(FinishArrayPrototypeSetup, 1, 1) \
67   F(SpecialArrayFunctions, 1, 1) \
68   F(GetDefaultReceiver, 1, 1) \
69   \
70   F(GetPrototype, 1, 1) \
71   F(IsInPrototypeChain, 2, 1) \
72   F(SetHiddenPrototype, 2, 1) \
73   \
74   F(IsConstructCall, 0, 1) \
75   \
76   F(GetOwnProperty, 2, 1) \
77   \
78   F(IsExtensible, 1, 1) \
79   F(PreventExtensions, 1, 1)\
80   \
81   /* Utilities */ \
82   F(CheckIsBootstrapping, 0, 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(LazyCompile, 1, 1) \
89   F(LazyRecompile, 1, 1) \
90   F(NotifyDeoptimized, 1, 1) \
91   F(NotifyOSR, 0, 1) \
92   F(DeoptimizeFunction, 1, 1) \
93   F(RunningInSimulator, 0, 1) \
94   F(OptimizeFunctionOnNextCall, 1, 1) \
95   F(GetOptimizationStatus, 1, 1) \
96   F(GetOptimizationCount, 1, 1) \
97   F(CompileForOnStackReplacement, 1, 1) \
98   F(SetNewFunctionAttributes, 1, 1) \
99   F(AllocateInNewSpace, 1, 1) \
100   F(SetNativeFlag, 1, 1) \
101   F(StoreArrayLiteralElement, 5, 1) \
102   \
103   /* Array join support */ \
104   F(PushIfAbsent, 2, 1) \
105   F(ArrayConcat, 1, 1) \
106   \
107   /* Conversions */ \
108   F(ToBool, 1, 1) \
109   F(Typeof, 1, 1) \
110   \
111   F(StringToNumber, 1, 1) \
112   F(StringFromCharCodeArray, 1, 1) \
113   F(StringParseInt, 2, 1) \
114   F(StringParseFloat, 1, 1) \
115   F(StringToLowerCase, 1, 1) \
116   F(StringToUpperCase, 1, 1) \
117   F(StringSplit, 3, 1) \
118   F(CharFromCode, 1, 1) \
119   F(URIEscape, 1, 1) \
120   F(URIUnescape, 1, 1) \
121   F(QuoteJSONString, 1, 1) \
122   F(QuoteJSONStringComma, 1, 1) \
123   F(QuoteJSONStringArray, 1, 1) \
124   \
125   F(NumberToString, 1, 1) \
126   F(NumberToStringSkipCache, 1, 1) \
127   F(NumberToInteger, 1, 1) \
128   F(NumberToIntegerMapMinusZero, 1, 1) \
129   F(NumberToJSUint32, 1, 1) \
130   F(NumberToJSInt32, 1, 1) \
131   F(NumberToSmi, 1, 1) \
132   F(AllocateHeapNumber, 0, 1) \
133   \
134   /* Arithmetic operations */ \
135   F(NumberAdd, 2, 1) \
136   F(NumberSub, 2, 1) \
137   F(NumberMul, 2, 1) \
138   F(NumberDiv, 2, 1) \
139   F(NumberMod, 2, 1) \
140   F(NumberUnaryMinus, 1, 1) \
141   F(NumberAlloc, 0, 1) \
142   \
143   F(StringAdd, 2, 1) \
144   F(StringBuilderConcat, 3, 1) \
145   F(StringBuilderJoin, 3, 1) \
146   F(SparseJoinWithSeparator, 3, 1)            \
147   \
148   /* Bit operations */ \
149   F(NumberOr, 2, 1) \
150   F(NumberAnd, 2, 1) \
151   F(NumberXor, 2, 1) \
152   F(NumberNot, 1, 1) \
153   \
154   F(NumberShl, 2, 1) \
155   F(NumberShr, 2, 1) \
156   F(NumberSar, 2, 1) \
157   \
158   /* Comparisons */ \
159   F(NumberEquals, 2, 1) \
160   F(StringEquals, 2, 1) \
161   F(UserObjectEquals, 2, 1) \
162   \
163   F(NumberCompare, 3, 1) \
164   F(SmiLexicographicCompare, 2, 1) \
165   F(StringCompare, 2, 1) \
166   \
167   /* Math */ \
168   F(Math_acos, 1, 1) \
169   F(Math_asin, 1, 1) \
170   F(Math_atan, 1, 1) \
171   F(Math_atan2, 2, 1) \
172   F(Math_ceil, 1, 1) \
173   F(Math_cos, 1, 1) \
174   F(Math_exp, 1, 1) \
175   F(Math_floor, 1, 1) \
176   F(Math_log, 1, 1) \
177   F(Math_pow, 2, 1) \
178   F(Math_pow_cfunction, 2, 1) \
179   F(RoundNumber, 1, 1) \
180   F(Math_sin, 1, 1) \
181   F(Math_sqrt, 1, 1) \
182   F(Math_tan, 1, 1) \
183   \
184   /* Regular expressions */ \
185   F(RegExpCompile, 3, 1) \
186   F(RegExpExec, 4, 1) \
187   F(RegExpExecMultiple, 4, 1) \
188   F(RegExpInitializeObject, 5, 1) \
189   F(RegExpConstructResult, 3, 1) \
190   \
191   /* JSON */ \
192   F(ParseJson, 1, 1) \
193   \
194   /* Strings */ \
195   F(StringCharCodeAt, 2, 1) \
196   F(StringIndexOf, 3, 1) \
197   F(StringLastIndexOf, 3, 1) \
198   F(StringLocaleCompare, 2, 1) \
199   F(SubString, 3, 1) \
200   F(StringReplaceRegExpWithString, 4, 1) \
201   F(StringMatch, 3, 1) \
202   F(StringTrim, 3, 1) \
203   F(StringToArray, 2, 1) \
204   F(NewStringWrapper, 1, 1) \
205   \
206   /* Numbers */ \
207   F(NumberToRadixString, 2, 1) \
208   F(NumberToFixed, 2, 1) \
209   F(NumberToExponential, 2, 1) \
210   F(NumberToPrecision, 2, 1)
211
212 #define RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
213   /* Reflection */ \
214   F(FunctionSetInstanceClassName, 2, 1) \
215   F(FunctionSetLength, 2, 1) \
216   F(FunctionSetPrototype, 2, 1) \
217   F(FunctionSetReadOnlyPrototype, 1, 1) \
218   F(FunctionGetName, 1, 1) \
219   F(FunctionSetName, 2, 1) \
220   F(FunctionNameShouldPrintAsAnonymous, 1, 1) \
221   F(FunctionMarkNameShouldPrintAsAnonymous, 1, 1) \
222   F(FunctionBindArguments, 4, 1) \
223   F(BoundFunctionGetBindings, 1, 1) \
224   F(FunctionRemovePrototype, 1, 1) \
225   F(FunctionGetSourceCode, 1, 1) \
226   F(FunctionGetScript, 1, 1) \
227   F(FunctionGetScriptSourcePosition, 1, 1) \
228   F(FunctionGetPositionForOffset, 2, 1) \
229   F(FunctionIsAPIFunction, 1, 1) \
230   F(FunctionIsBuiltin, 1, 1) \
231   F(GetScript, 1, 1) \
232   F(CollectStackTrace, 2, 1) \
233   F(GetV8Version, 0, 1) \
234   \
235   F(ClassOf, 1, 1) \
236   F(SetCode, 2, 1) \
237   F(SetExpectedNumberOfProperties, 2, 1) \
238   \
239   F(CreateApiFunction, 1, 1) \
240   F(IsTemplate, 1, 1) \
241   F(GetTemplateField, 2, 1) \
242   F(DisableAccessChecks, 1, 1) \
243   F(EnableAccessChecks, 1, 1) \
244   \
245   /* Dates */ \
246   F(DateCurrentTime, 0, 1) \
247   F(DateParseString, 2, 1) \
248   F(DateLocalTimezone, 1, 1) \
249   F(DateLocalTimeOffset, 0, 1) \
250   F(DateDaylightSavingsOffset, 1, 1) \
251   F(DateMakeDay, 2, 1) \
252   F(DateYMDFromTime, 2, 1) \
253   \
254   /* Numbers */ \
255   \
256   /* Globals */ \
257   F(CompileString, 1, 1) \
258   F(GlobalPrint, 1, 1) \
259   \
260   /* Eval */ \
261   F(GlobalReceiver, 1, 1) \
262   F(ResolvePossiblyDirectEval, 5, 2) \
263   \
264   F(SetProperty, -1 /* 4 or 5 */, 1) \
265   F(DefineOrRedefineDataProperty, 4, 1) \
266   F(DefineOrRedefineAccessorProperty, 5, 1) \
267   F(IgnoreAttributesAndSetProperty, -1 /* 3 or 4 */, 1) \
268   \
269   /* Arrays */ \
270   F(RemoveArrayHoles, 2, 1) \
271   F(GetArrayKeys, 2, 1) \
272   F(MoveArrayContents, 2, 1) \
273   F(EstimateNumberOfElements, 1, 1) \
274   F(SwapElements, 3, 1) \
275   \
276   /* Getters and Setters */ \
277   F(DefineAccessor, -1 /* 4 or 5 */, 1) \
278   F(LookupAccessor, 3, 1) \
279   \
280   /* Literals */ \
281   F(MaterializeRegExpLiteral, 4, 1)\
282   F(CreateArrayLiteralBoilerplate, 4, 1) \
283   F(CloneLiteralBoilerplate, 1, 1) \
284   F(CloneShallowLiteralBoilerplate, 1, 1) \
285   F(CreateObjectLiteral, 4, 1) \
286   F(CreateObjectLiteralShallow, 4, 1) \
287   F(CreateArrayLiteral, 3, 1) \
288   F(CreateArrayLiteralShallow, 3, 1) \
289   \
290   /* Harmony proxies */ \
291   F(CreateJSProxy, 2, 1) \
292   F(CreateJSFunctionProxy, 4, 1) \
293   F(IsJSProxy, 1, 1) \
294   F(IsJSFunctionProxy, 1, 1) \
295   F(GetHandler, 1, 1) \
296   F(GetCallTrap, 1, 1) \
297   F(GetConstructTrap, 1, 1) \
298   F(Fix, 1, 1) \
299   \
300   /* Harmony sets */ \
301   F(SetInitialize, 1, 1) \
302   F(SetAdd, 2, 1) \
303   F(SetHas, 2, 1) \
304   F(SetDelete, 2, 1) \
305   \
306   /* Harmony maps */ \
307   F(MapInitialize, 1, 1) \
308   F(MapGet, 2, 1) \
309   F(MapSet, 3, 1) \
310   \
311   /* Harmony weakmaps */ \
312   F(WeakMapInitialize, 1, 1) \
313   F(WeakMapGet, 2, 1) \
314   F(WeakMapSet, 3, 1) \
315   \
316   /* Statements */ \
317   F(NewClosure, 3, 1) \
318   F(NewObject, 1, 1) \
319   F(NewObjectFromBound, 1, 1) \
320   F(FinalizeInstanceSize, 1, 1) \
321   F(Throw, 1, 1) \
322   F(ReThrow, 1, 1) \
323   F(ThrowReferenceError, 1, 1) \
324   F(StackGuard, 0, 1) \
325   F(PromoteScheduledException, 0, 1) \
326   \
327   /* Contexts */ \
328   F(NewFunctionContext, 1, 1) \
329   F(PushWithContext, 2, 1) \
330   F(PushCatchContext, 3, 1) \
331   F(PushBlockContext, 2, 1) \
332   F(DeleteContextSlot, 2, 1) \
333   F(LoadContextSlot, 2, 2) \
334   F(LoadContextSlotNoReferenceError, 2, 2) \
335   F(StoreContextSlot, 4, 1) \
336   \
337   /* Declarations and initialization */ \
338   F(DeclareGlobals, 3, 1) \
339   F(DeclareContextSlot, 4, 1) \
340   F(InitializeVarGlobal, -1 /* 3 or 4 */, 1) \
341   F(InitializeConstGlobal, 3, 1) \
342   F(InitializeConstContextSlot, 3, 1) \
343   F(OptimizeObjectForAddingMultipleProperties, 2, 1) \
344   \
345   /* Debugging */ \
346   F(DebugPrint, 1, 1) \
347   F(DebugTrace, 0, 1) \
348   F(TraceElementsKindTransition, 5, 1) \
349   F(TraceEnter, 0, 1) \
350   F(TraceExit, 1, 1) \
351   F(Abort, 2, 1) \
352   /* Logging */ \
353   F(Log, 2, 1) \
354   /* ES5 */ \
355   F(LocalKeys, 1, 1) \
356   /* Cache suport */ \
357   F(GetFromCache, 2, 1) \
358   \
359   /* Message objects */ \
360   F(NewMessageObject, 2, 1) \
361   F(MessageGetType, 1, 1) \
362   F(MessageGetArguments, 1, 1) \
363   F(MessageGetStartPosition, 1, 1) \
364   F(MessageGetScript, 1, 1) \
365   \
366   /* Pseudo functions - handled as macros by parser */ \
367   F(IS_VAR, 1, 1) \
368   \
369   /* expose boolean functions from objects-inl.h */ \
370   F(HasFastSmiOnlyElements, 1, 1) \
371   F(HasFastElements, 1, 1) \
372   F(HasFastDoubleElements, 1, 1) \
373   F(HasDictionaryElements, 1, 1) \
374   F(HasExternalPixelElements, 1, 1) \
375   F(HasExternalArrayElements, 1, 1) \
376   F(HasExternalByteElements, 1, 1) \
377   F(HasExternalUnsignedByteElements, 1, 1) \
378   F(HasExternalShortElements, 1, 1) \
379   F(HasExternalUnsignedShortElements, 1, 1) \
380   F(HasExternalIntElements, 1, 1) \
381   F(HasExternalUnsignedIntElements, 1, 1) \
382   F(HasExternalFloatElements, 1, 1) \
383   F(HasExternalDoubleElements, 1, 1) \
384   F(TransitionElementsSmiToDouble, 1, 1) \
385   F(TransitionElementsDoubleToObject, 1, 1) \
386   F(HaveSameMap, 2, 1) \
387   /* profiler */ \
388   F(ProfilerResume, 0, 1) \
389   F(ProfilerPause, 0, 1)
390
391
392 #ifdef ENABLE_DEBUGGER_SUPPORT
393 #define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \
394   /* Debugger support*/ \
395   F(DebugBreak, 0, 1) \
396   F(SetDebugEventListener, 2, 1) \
397   F(Break, 0, 1) \
398   F(DebugGetPropertyDetails, 2, 1) \
399   F(DebugGetProperty, 2, 1) \
400   F(DebugPropertyTypeFromDetails, 1, 1) \
401   F(DebugPropertyAttributesFromDetails, 1, 1) \
402   F(DebugPropertyIndexFromDetails, 1, 1) \
403   F(DebugNamedInterceptorPropertyValue, 2, 1) \
404   F(DebugIndexedInterceptorElementValue, 2, 1) \
405   F(CheckExecutionState, 1, 1) \
406   F(GetFrameCount, 1, 1) \
407   F(GetFrameDetails, 2, 1) \
408   F(GetScopeCount, 2, 1) \
409   F(GetScopeDetails, 4, 1) \
410   F(DebugPrintScopes, 0, 1) \
411   F(GetThreadCount, 1, 1) \
412   F(GetThreadDetails, 2, 1) \
413   F(SetDisableBreak, 1, 1) \
414   F(GetBreakLocations, 1, 1) \
415   F(AllowBreakPointRelocation, 0, 1) \
416   F(SetFunctionBreakPoint, 3, 1) \
417   F(SetScriptBreakPoint, 3, 1) \
418   F(ClearBreakPoint, 1, 1) \
419   F(ChangeBreakOnException, 2, 1) \
420   F(IsBreakOnException, 1, 1) \
421   F(PrepareStep, 3, 1) \
422   F(ClearStepping, 0, 1) \
423   F(DebugEvaluate, 6, 1) \
424   F(DebugEvaluateGlobal, 4, 1) \
425   F(DebugGetLoadedScripts, 0, 1) \
426   F(DebugReferencedBy, 3, 1) \
427   F(DebugConstructedBy, 2, 1) \
428   F(DebugGetPrototype, 1, 1) \
429   F(SystemBreak, 0, 1) \
430   F(DebugDisassembleFunction, 1, 1) \
431   F(DebugDisassembleConstructor, 1, 1) \
432   F(FunctionGetInferredName, 1, 1) \
433   F(LiveEditFindSharedFunctionInfosForScript, 1, 1) \
434   F(LiveEditGatherCompileInfo, 2, 1) \
435   F(LiveEditReplaceScript, 3, 1) \
436   F(LiveEditReplaceFunctionCode, 2, 1) \
437   F(LiveEditFunctionSourceUpdated, 1, 1) \
438   F(LiveEditFunctionSetScript, 2, 1) \
439   F(LiveEditReplaceRefToNestedFunction, 3, 1) \
440   F(LiveEditPatchFunctionPositions, 2, 1) \
441   F(LiveEditCheckAndDropActivations, 2, 1) \
442   F(LiveEditCompareStrings, 2, 1) \
443   F(GetFunctionCodePositionFromSource, 2, 1) \
444   F(ExecuteInDebugContext, 2, 1) \
445   \
446   F(SetFlags, 1, 1) \
447   F(CollectGarbage, 1, 1) \
448   F(GetHeapUsage, 0, 1) \
449   \
450   /* LiveObjectList support*/ \
451   F(HasLOLEnabled, 0, 1) \
452   F(CaptureLOL, 0, 1) \
453   F(DeleteLOL, 1, 1) \
454   F(DumpLOL, 5, 1) \
455   F(GetLOLObj, 1, 1) \
456   F(GetLOLObjId, 1, 1) \
457   F(GetLOLObjRetainers, 6, 1) \
458   F(GetLOLPath, 3, 1) \
459   F(InfoLOL, 2, 1) \
460   F(PrintLOLObj, 1, 1) \
461   F(ResetLOL, 0, 1) \
462   F(SummarizeLOL, 3, 1)
463
464 #else
465 #define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F)
466 #endif
467
468 #ifdef DEBUG
469 #define RUNTIME_FUNCTION_LIST_DEBUG(F) \
470   /* Testing */ \
471   F(ListNatives, 0, 1)
472 #else
473 #define RUNTIME_FUNCTION_LIST_DEBUG(F)
474 #endif
475
476 // ----------------------------------------------------------------------------
477 // RUNTIME_FUNCTION_LIST defines all runtime functions accessed
478 // either directly by id (via the code generator), or indirectly
479 // via a native call by name (from within JS code).
480
481 #define RUNTIME_FUNCTION_LIST(F) \
482   RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
483   RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
484   RUNTIME_FUNCTION_LIST_DEBUG(F) \
485   RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F)
486
487 // ----------------------------------------------------------------------------
488 // INLINE_FUNCTION_LIST defines all inlined functions accessed
489 // with a native call of the form %_name from within JS code.
490 // Entries have the form F(name, number of arguments, number of return values).
491 #define INLINE_FUNCTION_LIST(F) \
492   F(IsSmi, 1, 1)                                                             \
493   F(IsNonNegativeSmi, 1, 1)                                                  \
494   F(IsArray, 1, 1)                                                           \
495   F(IsRegExp, 1, 1)                                                          \
496   F(CallFunction, -1 /* receiver + n args + function */, 1)                  \
497   F(ArgumentsLength, 0, 1)                                                   \
498   F(Arguments, 1, 1)                                                         \
499   F(ValueOf, 1, 1)                                                           \
500   F(SetValueOf, 2, 1)                                                        \
501   F(StringCharFromCode, 1, 1)                                                \
502   F(StringCharAt, 2, 1)                                                      \
503   F(ObjectEquals, 2, 1)                                                      \
504   F(RandomHeapNumber, 0, 1)                                                  \
505   F(IsObject, 1, 1)                                                          \
506   F(IsFunction, 1, 1)                                                        \
507   F(IsUndetectableObject, 1, 1)                                              \
508   F(IsSpecObject, 1, 1)                                                      \
509   F(IsStringWrapperSafeForDefaultValueOf, 1, 1)                              \
510   F(MathPow, 2, 1)                                                           \
511   F(MathSin, 1, 1)                                                           \
512   F(MathCos, 1, 1)                                                           \
513   F(MathSqrt, 1, 1)                                                          \
514   F(MathLog, 1, 1)                                                           \
515   F(IsRegExpEquivalent, 2, 1)                                                \
516   F(HasCachedArrayIndex, 1, 1)                                               \
517   F(GetCachedArrayIndex, 1, 1)                                               \
518   F(FastAsciiArrayJoin, 2, 1)
519
520
521 // ----------------------------------------------------------------------------
522 // INLINE_AND_RUNTIME_FUNCTION_LIST defines all inlined functions accessed
523 // with a native call of the form %_name from within JS code that also have
524 // a corresponding runtime function, that is called for slow cases.
525 // Entries have the form F(name, number of arguments, number of return values).
526 #define INLINE_RUNTIME_FUNCTION_LIST(F) \
527   F(IsConstructCall, 0, 1)                                                   \
528   F(ClassOf, 1, 1)                                                           \
529   F(StringCharCodeAt, 2, 1)                                                  \
530   F(Log, 3, 1)                                                               \
531   F(StringAdd, 2, 1)                                                         \
532   F(SubString, 3, 1)                                                         \
533   F(StringCompare, 2, 1)                                                     \
534   F(RegExpExec, 4, 1)                                                        \
535   F(RegExpConstructResult, 3, 1)                                             \
536   F(GetFromCache, 2, 1)                                                      \
537   F(NumberToString, 1, 1)                                                    \
538   F(SwapElements, 3, 1)
539
540
541 //---------------------------------------------------------------------------
542 // Runtime provides access to all C++ runtime functions.
543
544 class RuntimeState {
545  public:
546   StaticResource<StringInputBuffer>* string_input_buffer() {
547     return &string_input_buffer_;
548   }
549   unibrow::Mapping<unibrow::ToUppercase, 128>* to_upper_mapping() {
550     return &to_upper_mapping_;
551   }
552   unibrow::Mapping<unibrow::ToLowercase, 128>* to_lower_mapping() {
553     return &to_lower_mapping_;
554   }
555   StringInputBuffer* string_input_buffer_compare_bufx() {
556     return &string_input_buffer_compare_bufx_;
557   }
558   StringInputBuffer* string_input_buffer_compare_bufy() {
559     return &string_input_buffer_compare_bufy_;
560   }
561   StringInputBuffer* string_locale_compare_buf1() {
562     return &string_locale_compare_buf1_;
563   }
564   StringInputBuffer* string_locale_compare_buf2() {
565     return &string_locale_compare_buf2_;
566   }
567
568  private:
569   RuntimeState() {}
570   // Non-reentrant string buffer for efficient general use in the runtime.
571   StaticResource<StringInputBuffer> string_input_buffer_;
572   unibrow::Mapping<unibrow::ToUppercase, 128> to_upper_mapping_;
573   unibrow::Mapping<unibrow::ToLowercase, 128> to_lower_mapping_;
574   StringInputBuffer string_input_buffer_compare_bufx_;
575   StringInputBuffer string_input_buffer_compare_bufy_;
576   StringInputBuffer string_locale_compare_buf1_;
577   StringInputBuffer string_locale_compare_buf2_;
578
579   friend class Isolate;
580   friend class Runtime;
581
582   DISALLOW_COPY_AND_ASSIGN(RuntimeState);
583 };
584
585
586 class Runtime : public AllStatic {
587  public:
588   enum FunctionId {
589 #define F(name, nargs, ressize) k##name,
590     RUNTIME_FUNCTION_LIST(F)
591 #undef F
592 #define F(name, nargs, ressize) kInline##name,
593     INLINE_FUNCTION_LIST(F)
594     INLINE_RUNTIME_FUNCTION_LIST(F)
595 #undef F
596     kNumFunctions,
597     kFirstInlineFunction = kInlineIsSmi
598   };
599
600   enum IntrinsicType {
601     RUNTIME,
602     INLINE
603   };
604
605   // Intrinsic function descriptor.
606   struct Function {
607     FunctionId function_id;
608     IntrinsicType intrinsic_type;
609     // The JS name of the function.
610     const char* name;
611
612     // The C++ (native) entry point.  NULL if the function is inlined.
613     byte* entry;
614
615     // The number of arguments expected. nargs is -1 if the function takes
616     // a variable number of arguments.
617     int nargs;
618     // Size of result.  Most functions return a single pointer, size 1.
619     int result_size;
620   };
621
622   static const int kNotFound = -1;
623
624   // Add symbols for all the intrinsic function names to a StringDictionary.
625   // Returns failure if an allocation fails.  In this case, it must be
626   // retried with a new, empty StringDictionary, not with the same one.
627   // Alternatively, heap initialization can be completely restarted.
628   MUST_USE_RESULT static MaybeObject* InitializeIntrinsicFunctionNames(
629       Heap* heap, Object* dictionary);
630
631   // Get the intrinsic function with the given name, which must be a symbol.
632   static const Function* FunctionForSymbol(Handle<String> name);
633
634   // Get the intrinsic function with the given FunctionId.
635   static const Function* FunctionForId(FunctionId id);
636
637   // General-purpose helper functions for runtime system.
638   static int StringMatch(Isolate* isolate,
639                          Handle<String> sub,
640                          Handle<String> pat,
641                          int index);
642
643   static bool IsUpperCaseChar(RuntimeState* runtime_state, uint16_t ch);
644
645   // TODO(1240886): Some of the following methods are *not* handle safe, but
646   // accept handle arguments. This seems fragile.
647
648   // Support getting the characters in a string using [] notation as
649   // in Firefox/SpiderMonkey, Safari and Opera.
650   MUST_USE_RESULT static MaybeObject* GetElementOrCharAt(Isolate* isolate,
651                                                          Handle<Object> object,
652                                                          uint32_t index);
653
654   MUST_USE_RESULT static MaybeObject* SetObjectProperty(
655       Isolate* isolate,
656       Handle<Object> object,
657       Handle<Object> key,
658       Handle<Object> value,
659       PropertyAttributes attr,
660       StrictModeFlag strict_mode);
661
662   MUST_USE_RESULT static MaybeObject* ForceSetObjectProperty(
663       Isolate* isolate,
664       Handle<JSObject> object,
665       Handle<Object> key,
666       Handle<Object> value,
667       PropertyAttributes attr);
668
669   MUST_USE_RESULT static MaybeObject* ForceDeleteObjectProperty(
670       Isolate* isolate,
671       Handle<JSReceiver> object,
672       Handle<Object> key);
673
674   MUST_USE_RESULT static MaybeObject* GetObjectProperty(
675       Isolate* isolate,
676       Handle<Object> object,
677       Handle<Object> key);
678
679   // This function is used in FunctionNameUsing* tests.
680   static Object* FindSharedFunctionInfoInScript(Isolate* isolate,
681                                                 Handle<Script> script,
682                                                 int position);
683
684   // Helper functions used stubs.
685   static void PerformGC(Object* result);
686 };
687
688
689 //---------------------------------------------------------------------------
690 // Constants used by interface to runtime functions.
691
692 class DeclareGlobalsEvalFlag:       public BitField<bool,           0, 1> {};
693 class DeclareGlobalsStrictModeFlag: public BitField<StrictModeFlag, 1, 1> {};
694 class DeclareGlobalsNativeFlag:     public BitField<bool,           2, 1> {};
695
696 } }  // namespace v8::internal
697
698 #endif  // V8_RUNTIME_H_