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