83991bb76bbcad04f93f0a2b108a58029a8e133d
[profile/ivi/qtjsbackend.git] / src / 3rdparty / 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, 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   \
73   F(GetOwnProperty, 2, 1) \
74   \
75   F(IsExtensible, 1, 1) \
76   F(PreventExtensions, 1, 1)\
77   \
78   /* Utilities */ \
79   F(CheckIsBootstrapping, 0, 1) \
80   F(GetRootNaN, 0, 1) \
81   F(Call, -1 /* >= 2 */, 1) \
82   F(Apply, 5, 1) \
83   F(GetFunctionDelegate, 1, 1) \
84   F(GetConstructorDelegate, 1, 1) \
85   F(NewArgumentsFast, 3, 1) \
86   F(NewStrictArgumentsFast, 3, 1) \
87   F(LazyCompile, 1, 1) \
88   F(LazyRecompile, 1, 1) \
89   F(NotifyDeoptimized, 1, 1) \
90   F(NotifyOSR, 0, 1) \
91   F(DeoptimizeFunction, 1, 1) \
92   F(ClearFunctionTypeFeedback, 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   F(DebugCallbackSupportsStepping, 1, 1) \
103   F(DebugPrepareStepInIfStepping, 1, 1) \
104   \
105   /* Array join support */ \
106   F(PushIfAbsent, 2, 1) \
107   F(ArrayConcat, 1, 1) \
108   \
109   /* Conversions */ \
110   F(ToBool, 1, 1) \
111   F(Typeof, 1, 1) \
112   \
113   F(StringToNumber, 1, 1) \
114   F(StringFromCharCodeArray, 1, 1) \
115   F(StringParseInt, 2, 1) \
116   F(StringParseFloat, 1, 1) \
117   F(StringToLowerCase, 1, 1) \
118   F(StringToUpperCase, 1, 1) \
119   F(StringSplit, 3, 1) \
120   F(CharFromCode, 1, 1) \
121   F(URIEscape, 1, 1) \
122   F(URIUnescape, 1, 1) \
123   F(QuoteJSONString, 1, 1) \
124   F(QuoteJSONStringComma, 1, 1) \
125   F(QuoteJSONStringArray, 1, 1) \
126   \
127   F(NumberToString, 1, 1) \
128   F(NumberToStringSkipCache, 1, 1) \
129   F(NumberToInteger, 1, 1) \
130   F(NumberToIntegerMapMinusZero, 1, 1) \
131   F(NumberToJSUint32, 1, 1) \
132   F(NumberToJSInt32, 1, 1) \
133   F(NumberToSmi, 1, 1) \
134   F(AllocateHeapNumber, 0, 1) \
135   \
136   /* Arithmetic operations */ \
137   F(NumberAdd, 2, 1) \
138   F(NumberSub, 2, 1) \
139   F(NumberMul, 2, 1) \
140   F(NumberDiv, 2, 1) \
141   F(NumberMod, 2, 1) \
142   F(NumberUnaryMinus, 1, 1) \
143   F(NumberAlloc, 0, 1) \
144   \
145   F(StringAdd, 2, 1) \
146   F(StringBuilderConcat, 3, 1) \
147   F(StringBuilderJoin, 3, 1) \
148   F(SparseJoinWithSeparator, 3, 1) \
149   \
150   /* Bit operations */ \
151   F(NumberOr, 2, 1) \
152   F(NumberAnd, 2, 1) \
153   F(NumberXor, 2, 1) \
154   F(NumberNot, 1, 1) \
155   \
156   F(NumberShl, 2, 1) \
157   F(NumberShr, 2, 1) \
158   F(NumberSar, 2, 1) \
159   \
160   /* Comparisons */ \
161   F(NumberEquals, 2, 1) \
162   F(StringEquals, 2, 1) \
163   \
164   F(NumberCompare, 3, 1) \
165   F(SmiLexicographicCompare, 2, 1) \
166   F(StringCompare, 2, 1) \
167   \
168   /* Math */ \
169   F(Math_acos, 1, 1) \
170   F(Math_asin, 1, 1) \
171   F(Math_atan, 1, 1) \
172   F(Math_atan2, 2, 1) \
173   F(Math_ceil, 1, 1) \
174   F(Math_cos, 1, 1) \
175   F(Math_exp, 1, 1) \
176   F(Math_floor, 1, 1) \
177   F(Math_log, 1, 1) \
178   F(Math_pow, 2, 1) \
179   F(Math_pow_cfunction, 2, 1) \
180   F(RoundNumber, 1, 1) \
181   F(Math_sin, 1, 1) \
182   F(Math_sqrt, 1, 1) \
183   F(Math_tan, 1, 1) \
184   \
185   /* Regular expressions */ \
186   F(RegExpCompile, 3, 1) \
187   F(RegExpExec, 4, 1) \
188   F(RegExpExecMultiple, 4, 1) \
189   F(RegExpInitializeObject, 5, 1) \
190   F(RegExpConstructResult, 3, 1) \
191   \
192   /* JSON */ \
193   F(ParseJson, 1, 1) \
194   \
195   /* Strings */ \
196   F(StringCharCodeAt, 2, 1) \
197   F(StringIndexOf, 3, 1) \
198   F(StringLastIndexOf, 3, 1) \
199   F(StringLocaleCompare, 2, 1) \
200   F(SubString, 3, 1) \
201   F(StringReplaceRegExpWithString, 4, 1) \
202   F(StringReplaceOneCharWithString, 3, 1) \
203   F(StringMatch, 3, 1) \
204   F(StringTrim, 3, 1) \
205   F(StringToArray, 2, 1) \
206   F(NewStringWrapper, 1, 1) \
207   \
208   /* Numbers */ \
209   F(NumberToRadixString, 2, 1) \
210   F(NumberToFixed, 2, 1) \
211   F(NumberToExponential, 2, 1) \
212   F(NumberToPrecision, 2, 1)
213
214 #define RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
215   /* Reflection */ \
216   F(FunctionSetInstanceClassName, 2, 1) \
217   F(FunctionSetLength, 2, 1) \
218   F(FunctionSetPrototype, 2, 1) \
219   F(FunctionSetReadOnlyPrototype, 1, 1) \
220   F(FunctionGetName, 1, 1) \
221   F(FunctionSetName, 2, 1) \
222   F(FunctionNameShouldPrintAsAnonymous, 1, 1) \
223   F(FunctionMarkNameShouldPrintAsAnonymous, 1, 1) \
224   F(FunctionBindArguments, 4, 1) \
225   F(BoundFunctionGetBindings, 1, 1) \
226   F(FunctionRemovePrototype, 1, 1) \
227   F(FunctionGetSourceCode, 1, 1) \
228   F(FunctionGetScript, 1, 1) \
229   F(FunctionGetScriptSourcePosition, 1, 1) \
230   F(FunctionGetPositionForOffset, 2, 1) \
231   F(FunctionIsAPIFunction, 1, 1) \
232   F(FunctionIsBuiltin, 1, 1) \
233   F(GetScript, 1, 1) \
234   F(CollectStackTrace, 3, 1) \
235   F(GetV8Version, 0, 1) \
236   \
237   F(ClassOf, 1, 1) \
238   F(SetCode, 2, 1) \
239   F(SetExpectedNumberOfProperties, 2, 1) \
240   \
241   F(CreateApiFunction, 1, 1) \
242   F(IsTemplate, 1, 1) \
243   F(GetTemplateField, 2, 1) \
244   F(DisableAccessChecks, 1, 1) \
245   F(EnableAccessChecks, 1, 1) \
246   \
247   /* Dates */ \
248   F(DateCurrentTime, 0, 1) \
249   F(DateParseString, 2, 1) \
250   F(DateLocalTimezone, 1, 1) \
251   F(DateToUTC, 1, 1) \
252   F(DateMakeDay, 2, 1) \
253   F(DateSetValue, 3, 1) \
254   \
255   /* Numbers */ \
256   \
257   /* Globals */ \
258   F(CompileString, 1, 1) \
259   F(GlobalPrint, 1, 1) \
260   \
261   /* Eval */ \
262   F(GlobalReceiver, 1, 1) \
263   F(ResolvePossiblyDirectEval, 5, 2) \
264   \
265   F(SetProperty, -1 /* 4 or 5 */, 1) \
266   F(DefineOrRedefineDataProperty, 4, 1) \
267   F(DefineOrRedefineAccessorProperty, 5, 1) \
268   F(IgnoreAttributesAndSetProperty, -1 /* 3 or 4 */, 1) \
269   \
270   /* Arrays */ \
271   F(RemoveArrayHoles, 2, 1) \
272   F(GetArrayKeys, 2, 1) \
273   F(MoveArrayContents, 2, 1) \
274   F(EstimateNumberOfElements, 1, 1) \
275   \
276   /* Getters and Setters */ \
277   F(LookupAccessor, 3, 1) \
278   \
279   /* Literals */ \
280   F(MaterializeRegExpLiteral, 4, 1)\
281   F(CreateObjectLiteral, 4, 1) \
282   F(CreateObjectLiteralShallow, 4, 1) \
283   F(CreateArrayLiteral, 3, 1) \
284   F(CreateArrayLiteralShallow, 3, 1) \
285   \
286   /* Harmony proxies */ \
287   F(CreateJSProxy, 2, 1) \
288   F(CreateJSFunctionProxy, 4, 1) \
289   F(IsJSProxy, 1, 1) \
290   F(IsJSFunctionProxy, 1, 1) \
291   F(GetHandler, 1, 1) \
292   F(GetCallTrap, 1, 1) \
293   F(GetConstructTrap, 1, 1) \
294   F(Fix, 1, 1) \
295   \
296   /* Harmony sets */ \
297   F(SetInitialize, 1, 1) \
298   F(SetAdd, 2, 1) \
299   F(SetHas, 2, 1) \
300   F(SetDelete, 2, 1) \
301   \
302   /* Harmony maps */ \
303   F(MapInitialize, 1, 1) \
304   F(MapGet, 2, 1) \
305   F(MapSet, 3, 1) \
306   \
307   /* Harmony weakmaps */ \
308   F(WeakMapInitialize, 1, 1) \
309   F(WeakMapGet, 2, 1) \
310   F(WeakMapSet, 3, 1) \
311   \
312   /* Statements */ \
313   F(NewClosure, 3, 1) \
314   F(NewObject, 1, 1) \
315   F(NewObjectFromBound, 1, 1) \
316   F(FinalizeInstanceSize, 1, 1) \
317   F(Throw, 1, 1) \
318   F(ReThrow, 1, 1) \
319   F(ThrowReferenceError, 1, 1) \
320   F(StackGuard, 0, 1) \
321   F(Interrupt, 0, 1) \
322   F(PromoteScheduledException, 0, 1) \
323   \
324   /* Contexts */ \
325   F(NewFunctionContext, 1, 1) \
326   F(PushWithContext, 2, 1) \
327   F(PushCatchContext, 3, 1) \
328   F(PushBlockContext, 2, 1) \
329   F(PushModuleContext, 2, 1) \
330   F(DeleteContextSlot, 2, 1) \
331   F(LoadContextSlot, 2, 2) \
332   F(LoadContextSlotNoReferenceError, 2, 2) \
333   F(StoreContextSlot, 4, 1) \
334   \
335   /* Declarations and initialization */ \
336   F(DeclareGlobals, 3, 1) \
337   F(DeclareContextSlot, 4, 1) \
338   F(InitializeVarGlobal, -1 /* 2 or 3 */, 1) \
339   F(InitializeConstGlobal, 2, 1) \
340   F(InitializeConstContextSlot, 3, 1) \
341   F(OptimizeObjectForAddingMultipleProperties, 2, 1) \
342   \
343   /* Debugging */ \
344   F(DebugPrint, 1, 1) \
345   F(DebugTrace, 0, 1) \
346   F(TraceEnter, 0, 1) \
347   F(TraceExit, 1, 1) \
348   F(Abort, 2, 1) \
349   /* Logging */ \
350   F(Log, 2, 1) \
351   /* ES5 */ \
352   F(LocalKeys, 1, 1) \
353   /* Cache suport */ \
354   F(GetFromCache, 2, 1) \
355   \
356   /* Message objects */ \
357   F(NewMessageObject, 2, 1) \
358   F(MessageGetType, 1, 1) \
359   F(MessageGetArguments, 1, 1) \
360   F(MessageGetStartPosition, 1, 1) \
361   F(MessageGetScript, 1, 1) \
362   \
363   /* Pseudo functions - handled as macros by parser */ \
364   F(IS_VAR, 1, 1) \
365   \
366   /* expose boolean functions from objects-inl.h */ \
367   F(HasFastSmiOnlyElements, 1, 1) \
368   F(HasFastElements, 1, 1) \
369   F(HasFastDoubleElements, 1, 1) \
370   F(HasDictionaryElements, 1, 1) \
371   F(HasExternalPixelElements, 1, 1) \
372   F(HasExternalArrayElements, 1, 1) \
373   F(HasExternalByteElements, 1, 1) \
374   F(HasExternalUnsignedByteElements, 1, 1) \
375   F(HasExternalShortElements, 1, 1) \
376   F(HasExternalUnsignedShortElements, 1, 1) \
377   F(HasExternalIntElements, 1, 1) \
378   F(HasExternalUnsignedIntElements, 1, 1) \
379   F(HasExternalFloatElements, 1, 1) \
380   F(HasExternalDoubleElements, 1, 1) \
381   F(TransitionElementsSmiToDouble, 1, 1) \
382   F(TransitionElementsDoubleToObject, 1, 1) \
383   F(HaveSameMap, 2, 1) \
384   /* profiler */ \
385   F(ProfilerResume, 0, 1) \
386   F(ProfilerPause, 0, 1)
387
388
389 #ifdef ENABLE_DEBUGGER_SUPPORT
390 #define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \
391   /* Debugger support*/ \
392   F(DebugBreak, 0, 1) \
393   F(SetDebugEventListener, 2, 1) \
394   F(Break, 0, 1) \
395   F(DebugGetPropertyDetails, 2, 1) \
396   F(DebugGetProperty, 2, 1) \
397   F(DebugPropertyTypeFromDetails, 1, 1) \
398   F(DebugPropertyAttributesFromDetails, 1, 1) \
399   F(DebugPropertyIndexFromDetails, 1, 1) \
400   F(DebugNamedInterceptorPropertyValue, 2, 1) \
401   F(DebugIndexedInterceptorElementValue, 2, 1) \
402   F(CheckExecutionState, 1, 1) \
403   F(GetFrameCount, 1, 1) \
404   F(GetFrameDetails, 2, 1) \
405   F(GetScopeCount, 2, 1) \
406   F(GetScopeDetails, 4, 1) \
407   F(GetFunctionScopeCount, 1, 1) \
408   F(GetFunctionScopeDetails, 2, 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(DebugSetScriptSource, 2, 1) \
428   F(SystemBreak, 0, 1) \
429   F(DebugDisassembleFunction, 1, 1) \
430   F(DebugDisassembleConstructor, 1, 1) \
431   F(FunctionGetInferredName, 1, 1) \
432   F(LiveEditFindSharedFunctionInfosForScript, 1, 1) \
433   F(LiveEditGatherCompileInfo, 2, 1) \
434   F(LiveEditReplaceScript, 3, 1) \
435   F(LiveEditReplaceFunctionCode, 2, 1) \
436   F(LiveEditFunctionSourceUpdated, 1, 1) \
437   F(LiveEditFunctionSetScript, 2, 1) \
438   F(LiveEditReplaceRefToNestedFunction, 3, 1) \
439   F(LiveEditPatchFunctionPositions, 2, 1) \
440   F(LiveEditCheckAndDropActivations, 2, 1) \
441   F(LiveEditCompareStrings, 2, 1) \
442   F(GetFunctionCodePositionFromSource, 2, 1) \
443   F(ExecuteInDebugContext, 2, 1) \
444   \
445   F(SetFlags, 1, 1) \
446   F(CollectGarbage, 1, 1) \
447   F(GetHeapUsage, 0, 1) \
448   \
449   /* LiveObjectList support*/ \
450   F(HasLOLEnabled, 0, 1) \
451   F(CaptureLOL, 0, 1) \
452   F(DeleteLOL, 1, 1) \
453   F(DumpLOL, 5, 1) \
454   F(GetLOLObj, 1, 1) \
455   F(GetLOLObjId, 1, 1) \
456   F(GetLOLObjRetainers, 6, 1) \
457   F(GetLOLPath, 3, 1) \
458   F(InfoLOL, 2, 1) \
459   F(PrintLOLObj, 1, 1) \
460   F(ResetLOL, 0, 1) \
461   F(SummarizeLOL, 3, 1)
462
463 #else
464 #define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F)
465 #endif
466
467 #ifdef DEBUG
468 #define RUNTIME_FUNCTION_LIST_DEBUG(F) \
469   /* Testing */ \
470   F(ListNatives, 0, 1)
471 #else
472 #define RUNTIME_FUNCTION_LIST_DEBUG(F)
473 #endif
474
475 // ----------------------------------------------------------------------------
476 // RUNTIME_FUNCTION_LIST defines all runtime functions accessed
477 // either directly by id (via the code generator), or indirectly
478 // via a native call by name (from within JS code).
479
480 #define RUNTIME_FUNCTION_LIST(F) \
481   RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
482   RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
483   RUNTIME_FUNCTION_LIST_DEBUG(F) \
484   RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F)
485
486 // ----------------------------------------------------------------------------
487 // INLINE_FUNCTION_LIST defines all inlined functions accessed
488 // with a native call of the form %_name from within JS code.
489 // Entries have the form F(name, number of arguments, number of return values).
490 #define INLINE_FUNCTION_LIST(F) \
491   F(IsSmi, 1, 1)                                                             \
492   F(IsNonNegativeSmi, 1, 1)                                                  \
493   F(IsArray, 1, 1)                                                           \
494   F(IsRegExp, 1, 1)                                                          \
495   F(IsConstructCall, 0, 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(DateField, 2 /* date object, field index */, 1)                          \
502   F(StringCharFromCode, 1, 1)                                                \
503   F(StringCharAt, 2, 1)                                                      \
504   F(ObjectEquals, 2, 1)                                                      \
505   F(RandomHeapNumber, 0, 1)                                                  \
506   F(IsObject, 1, 1)                                                          \
507   F(IsFunction, 1, 1)                                                        \
508   F(IsUndetectableObject, 1, 1)                                              \
509   F(IsSpecObject, 1, 1)                                                      \
510   F(IsStringWrapperSafeForDefaultValueOf, 1, 1)                              \
511   F(MathPow, 2, 1)                                                           \
512   F(MathSin, 1, 1)                                                           \
513   F(MathCos, 1, 1)                                                           \
514   F(MathTan, 1, 1)                                                           \
515   F(MathSqrt, 1, 1)                                                          \
516   F(MathLog, 1, 1)                                                           \
517   F(IsRegExpEquivalent, 2, 1)                                                \
518   F(HasCachedArrayIndex, 1, 1)                                               \
519   F(GetCachedArrayIndex, 1, 1)                                               \
520   F(FastAsciiArrayJoin, 2, 1)
521
522
523 // ----------------------------------------------------------------------------
524 // INLINE_AND_RUNTIME_FUNCTION_LIST defines all inlined functions accessed
525 // with a native call of the form %_name from within JS code that also have
526 // a corresponding runtime function, that is called for slow cases.
527 // Entries have the form F(name, number of arguments, number of return values).
528 #define INLINE_RUNTIME_FUNCTION_LIST(F) \
529   F(ClassOf, 1, 1)                                                           \
530   F(StringCharCodeAt, 2, 1)                                                  \
531   F(Log, 3, 1)                                                               \
532   F(StringAdd, 2, 1)                                                         \
533   F(SubString, 3, 1)                                                         \
534   F(StringCompare, 2, 1)                                                     \
535   F(RegExpExec, 4, 1)                                                        \
536   F(RegExpConstructResult, 3, 1)                                             \
537   F(GetFromCache, 2, 1)                                                      \
538   F(NumberToString, 1, 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   static Handle<String> StringReplaceOneCharWithString(Isolate* isolate,
638                                                        Handle<String> subject,
639                                                        Handle<String> search,
640                                                        Handle<String> replace,
641                                                        bool* found,
642                                                        int recursion_limit);
643
644   // General-purpose helper functions for runtime system.
645   static int StringMatch(Isolate* isolate,
646                          Handle<String> sub,
647                          Handle<String> pat,
648                          int index);
649
650   static bool IsUpperCaseChar(RuntimeState* runtime_state, uint16_t ch);
651
652   // TODO(1240886): Some of the following methods are *not* handle safe, but
653   // accept handle arguments. This seems fragile.
654
655   // Support getting the characters in a string using [] notation as
656   // in Firefox/SpiderMonkey, Safari and Opera.
657   MUST_USE_RESULT static MaybeObject* GetElementOrCharAt(Isolate* isolate,
658                                                          Handle<Object> object,
659                                                          uint32_t index);
660
661   MUST_USE_RESULT static MaybeObject* SetObjectProperty(
662       Isolate* isolate,
663       Handle<Object> object,
664       Handle<Object> key,
665       Handle<Object> value,
666       PropertyAttributes attr,
667       StrictModeFlag strict_mode);
668
669   MUST_USE_RESULT static MaybeObject* ForceSetObjectProperty(
670       Isolate* isolate,
671       Handle<JSObject> object,
672       Handle<Object> key,
673       Handle<Object> value,
674       PropertyAttributes attr);
675
676   MUST_USE_RESULT static MaybeObject* ForceDeleteObjectProperty(
677       Isolate* isolate,
678       Handle<JSReceiver> object,
679       Handle<Object> key);
680
681   MUST_USE_RESULT static MaybeObject* GetObjectProperty(
682       Isolate* isolate,
683       Handle<Object> object,
684       Handle<Object> key);
685
686   // This function is used in FunctionNameUsing* tests.
687   static Object* FindSharedFunctionInfoInScript(Isolate* isolate,
688                                                 Handle<Script> script,
689                                                 int position);
690
691   // Helper functions used stubs.
692   static void PerformGC(Object* result);
693
694   // Used in runtime.cc and hydrogen's VisitArrayLiteral.
695   static Handle<Object> CreateArrayLiteralBoilerplate(
696       Isolate* isolate,
697       Handle<FixedArray> literals,
698       Handle<FixedArray> elements);
699 };
700
701
702 //---------------------------------------------------------------------------
703 // Constants used by interface to runtime functions.
704
705 class DeclareGlobalsEvalFlag:     public BitField<bool,         0, 1> {};
706 class DeclareGlobalsNativeFlag:   public BitField<bool,         1, 1> {};
707 class DeclareGlobalsLanguageMode: public BitField<LanguageMode, 2, 2> {};
708
709 } }  // namespace v8::internal
710
711 #endif  // V8_RUNTIME_H_