v8  3.14.5(node0.10.28)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
runtime.h
Go to the documentation of this file.
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(FinishArrayPrototypeSetup, 1, 1) \
66  F(SpecialArrayFunctions, 1, 1) \
67  F(GetDefaultReceiver, 1, 1) \
68  \
69  F(GetPrototype, 1, 1) \
70  F(IsInPrototypeChain, 2, 1) \
71  \
72  F(GetOwnProperty, 2, 1) \
73  \
74  F(IsExtensible, 1, 1) \
75  F(PreventExtensions, 1, 1)\
76  \
77  /* Utilities */ \
78  F(CheckIsBootstrapping, 0, 1) \
79  F(GetRootNaN, 0, 1) \
80  F(Call, -1 /* >= 2 */, 1) \
81  F(Apply, 5, 1) \
82  F(GetFunctionDelegate, 1, 1) \
83  F(GetConstructorDelegate, 1, 1) \
84  F(NewArgumentsFast, 3, 1) \
85  F(NewStrictArgumentsFast, 3, 1) \
86  F(LazyCompile, 1, 1) \
87  F(LazyRecompile, 1, 1) \
88  F(ParallelRecompile, 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 modules */ \
287  F(IsJSModule, 1, 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(MapHas, 2, 1) \
309  F(MapDelete, 2, 1) \
310  F(MapSet, 3, 1) \
311  \
312  /* Harmony weakmaps */ \
313  F(WeakMapInitialize, 1, 1) \
314  F(WeakMapGet, 2, 1) \
315  F(WeakMapHas, 2, 1) \
316  F(WeakMapDelete, 2, 1) \
317  F(WeakMapSet, 3, 1) \
318  \
319  /* Statements */ \
320  F(NewClosure, 3, 1) \
321  F(NewObject, 1, 1) \
322  F(NewObjectFromBound, 1, 1) \
323  F(FinalizeInstanceSize, 1, 1) \
324  F(Throw, 1, 1) \
325  F(ReThrow, 1, 1) \
326  F(ThrowReferenceError, 1, 1) \
327  F(ThrowNotDateError, 0, 1) \
328  F(StackGuard, 0, 1) \
329  F(Interrupt, 0, 1) \
330  F(PromoteScheduledException, 0, 1) \
331  \
332  /* Contexts */ \
333  F(NewGlobalContext, 2, 1) \
334  F(NewFunctionContext, 1, 1) \
335  F(PushWithContext, 2, 1) \
336  F(PushCatchContext, 3, 1) \
337  F(PushBlockContext, 2, 1) \
338  F(PushModuleContext, 1, 1) \
339  F(DeleteContextSlot, 2, 1) \
340  F(LoadContextSlot, 2, 2) \
341  F(LoadContextSlotNoReferenceError, 2, 2) \
342  F(StoreContextSlot, 4, 1) \
343  \
344  /* Declarations and initialization */ \
345  F(DeclareGlobals, 3, 1) \
346  F(DeclareContextSlot, 4, 1) \
347  F(InitializeVarGlobal, -1 /* 2 or 3 */, 1) \
348  F(InitializeConstGlobal, 2, 1) \
349  F(InitializeConstContextSlot, 3, 1) \
350  F(OptimizeObjectForAddingMultipleProperties, 2, 1) \
351  \
352  /* Debugging */ \
353  F(DebugPrint, 1, 1) \
354  F(DebugTrace, 0, 1) \
355  F(TraceEnter, 0, 1) \
356  F(TraceExit, 1, 1) \
357  F(Abort, 2, 1) \
358  /* Logging */ \
359  F(Log, 2, 1) \
360  /* ES5 */ \
361  F(LocalKeys, 1, 1) \
362  /* Cache suport */ \
363  F(GetFromCache, 2, 1) \
364  \
365  /* Message objects */ \
366  F(NewMessageObject, 2, 1) \
367  F(MessageGetType, 1, 1) \
368  F(MessageGetArguments, 1, 1) \
369  F(MessageGetStartPosition, 1, 1) \
370  F(MessageGetScript, 1, 1) \
371  \
372  /* Pseudo functions - handled as macros by parser */ \
373  F(IS_VAR, 1, 1) \
374  \
375  /* expose boolean functions from objects-inl.h */ \
376  F(HasFastSmiElements, 1, 1) \
377  F(HasFastSmiOrObjectElements, 1, 1) \
378  F(HasFastObjectElements, 1, 1) \
379  F(HasFastDoubleElements, 1, 1) \
380  F(HasFastHoleyElements, 1, 1) \
381  F(HasDictionaryElements, 1, 1) \
382  F(HasExternalPixelElements, 1, 1) \
383  F(HasExternalArrayElements, 1, 1) \
384  F(HasExternalByteElements, 1, 1) \
385  F(HasExternalUnsignedByteElements, 1, 1) \
386  F(HasExternalShortElements, 1, 1) \
387  F(HasExternalUnsignedShortElements, 1, 1) \
388  F(HasExternalIntElements, 1, 1) \
389  F(HasExternalUnsignedIntElements, 1, 1) \
390  F(HasExternalFloatElements, 1, 1) \
391  F(HasExternalDoubleElements, 1, 1) \
392  F(HasFastProperties, 1, 1) \
393  F(TransitionElementsSmiToDouble, 1, 1) \
394  F(TransitionElementsDoubleToObject, 1, 1) \
395  F(HaveSameMap, 2, 1) \
396  /* profiler */ \
397  F(ProfilerResume, 0, 1) \
398  F(ProfilerPause, 0, 1)
399 
400 
401 #ifdef ENABLE_DEBUGGER_SUPPORT
402 #define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \
403  /* Debugger support*/ \
404  F(DebugBreak, 0, 1) \
405  F(SetDebugEventListener, 2, 1) \
406  F(Break, 0, 1) \
407  F(DebugGetPropertyDetails, 2, 1) \
408  F(DebugGetProperty, 2, 1) \
409  F(DebugPropertyTypeFromDetails, 1, 1) \
410  F(DebugPropertyAttributesFromDetails, 1, 1) \
411  F(DebugPropertyIndexFromDetails, 1, 1) \
412  F(DebugNamedInterceptorPropertyValue, 2, 1) \
413  F(DebugIndexedInterceptorElementValue, 2, 1) \
414  F(CheckExecutionState, 1, 1) \
415  F(GetFrameCount, 1, 1) \
416  F(GetFrameDetails, 2, 1) \
417  F(GetScopeCount, 2, 1) \
418  F(GetScopeDetails, 4, 1) \
419  F(GetFunctionScopeCount, 1, 1) \
420  F(GetFunctionScopeDetails, 2, 1) \
421  F(DebugPrintScopes, 0, 1) \
422  F(GetThreadCount, 1, 1) \
423  F(GetThreadDetails, 2, 1) \
424  F(SetDisableBreak, 1, 1) \
425  F(GetBreakLocations, 1, 1) \
426  F(SetFunctionBreakPoint, 3, 1) \
427  F(SetScriptBreakPoint, 3, 1) \
428  F(ClearBreakPoint, 1, 1) \
429  F(ChangeBreakOnException, 2, 1) \
430  F(IsBreakOnException, 1, 1) \
431  F(PrepareStep, 3, 1) \
432  F(ClearStepping, 0, 1) \
433  F(DebugEvaluate, 6, 1) \
434  F(DebugEvaluateGlobal, 4, 1) \
435  F(DebugGetLoadedScripts, 0, 1) \
436  F(DebugReferencedBy, 3, 1) \
437  F(DebugConstructedBy, 2, 1) \
438  F(DebugGetPrototype, 1, 1) \
439  F(DebugSetScriptSource, 2, 1) \
440  F(SystemBreak, 0, 1) \
441  F(DebugDisassembleFunction, 1, 1) \
442  F(DebugDisassembleConstructor, 1, 1) \
443  F(FunctionGetInferredName, 1, 1) \
444  F(LiveEditFindSharedFunctionInfosForScript, 1, 1) \
445  F(LiveEditGatherCompileInfo, 2, 1) \
446  F(LiveEditReplaceScript, 3, 1) \
447  F(LiveEditReplaceFunctionCode, 2, 1) \
448  F(LiveEditFunctionSourceUpdated, 1, 1) \
449  F(LiveEditFunctionSetScript, 2, 1) \
450  F(LiveEditReplaceRefToNestedFunction, 3, 1) \
451  F(LiveEditPatchFunctionPositions, 2, 1) \
452  F(LiveEditCheckAndDropActivations, 2, 1) \
453  F(LiveEditCompareStrings, 2, 1) \
454  F(LiveEditRestartFrame, 2, 1) \
455  F(GetFunctionCodePositionFromSource, 2, 1) \
456  F(ExecuteInDebugContext, 2, 1) \
457  \
458  F(SetFlags, 1, 1) \
459  F(CollectGarbage, 1, 1) \
460  F(GetHeapUsage, 0, 1) \
461  \
462  /* LiveObjectList support*/ \
463  F(HasLOLEnabled, 0, 1) \
464  F(CaptureLOL, 0, 1) \
465  F(DeleteLOL, 1, 1) \
466  F(DumpLOL, 5, 1) \
467  F(GetLOLObj, 1, 1) \
468  F(GetLOLObjId, 1, 1) \
469  F(GetLOLObjRetainers, 6, 1) \
470  F(GetLOLPath, 3, 1) \
471  F(InfoLOL, 2, 1) \
472  F(PrintLOLObj, 1, 1) \
473  F(ResetLOL, 0, 1) \
474  F(SummarizeLOL, 3, 1)
475 
476 #else
477 #define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F)
478 #endif
479 
480 #ifdef DEBUG
481 #define RUNTIME_FUNCTION_LIST_DEBUG(F) \
482  /* Testing */ \
483  F(ListNatives, 0, 1)
484 #else
485 #define RUNTIME_FUNCTION_LIST_DEBUG(F)
486 #endif
487 
488 // ----------------------------------------------------------------------------
489 // RUNTIME_FUNCTION_LIST defines all runtime functions accessed
490 // either directly by id (via the code generator), or indirectly
491 // via a native call by name (from within JS code).
492 
493 #define RUNTIME_FUNCTION_LIST(F) \
494  RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
495  RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
496  RUNTIME_FUNCTION_LIST_DEBUG(F) \
497  RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F)
498 
499 // ----------------------------------------------------------------------------
500 // INLINE_FUNCTION_LIST defines all inlined functions accessed
501 // with a native call of the form %_name from within JS code.
502 // Entries have the form F(name, number of arguments, number of return values).
503 #define INLINE_FUNCTION_LIST(F) \
504  F(IsSmi, 1, 1) \
505  F(IsNonNegativeSmi, 1, 1) \
506  F(IsArray, 1, 1) \
507  F(IsRegExp, 1, 1) \
508  F(IsConstructCall, 0, 1) \
509  F(CallFunction, -1 /* receiver + n args + function */, 1) \
510  F(ArgumentsLength, 0, 1) \
511  F(Arguments, 1, 1) \
512  F(ValueOf, 1, 1) \
513  F(SetValueOf, 2, 1) \
514  F(DateField, 2 /* date object, field index */, 1) \
515  F(StringCharFromCode, 1, 1) \
516  F(StringCharAt, 2, 1) \
517  F(ObjectEquals, 2, 1) \
518  F(RandomHeapNumber, 0, 1) \
519  F(IsObject, 1, 1) \
520  F(IsFunction, 1, 1) \
521  F(IsUndetectableObject, 1, 1) \
522  F(IsSpecObject, 1, 1) \
523  F(IsStringWrapperSafeForDefaultValueOf, 1, 1) \
524  F(MathPow, 2, 1) \
525  F(MathSin, 1, 1) \
526  F(MathCos, 1, 1) \
527  F(MathTan, 1, 1) \
528  F(MathSqrt, 1, 1) \
529  F(MathLog, 1, 1) \
530  F(IsRegExpEquivalent, 2, 1) \
531  F(HasCachedArrayIndex, 1, 1) \
532  F(GetCachedArrayIndex, 1, 1) \
533  F(FastAsciiArrayJoin, 2, 1)
534 
535 
536 // ----------------------------------------------------------------------------
537 // INLINE_AND_RUNTIME_FUNCTION_LIST defines all inlined functions accessed
538 // with a native call of the form %_name from within JS code that also have
539 // a corresponding runtime function, that is called for slow cases.
540 // Entries have the form F(name, number of arguments, number of return values).
541 #define INLINE_RUNTIME_FUNCTION_LIST(F) \
542  F(ClassOf, 1, 1) \
543  F(StringCharCodeAt, 2, 1) \
544  F(Log, 3, 1) \
545  F(StringAdd, 2, 1) \
546  F(SubString, 3, 1) \
547  F(StringCompare, 2, 1) \
548  F(RegExpExec, 4, 1) \
549  F(RegExpConstructResult, 3, 1) \
550  F(GetFromCache, 2, 1) \
551  F(NumberToString, 1, 1)
552 
553 
554 //---------------------------------------------------------------------------
555 // Runtime provides access to all C++ runtime functions.
556 
558  public:
560  return &string_input_buffer_;
561  }
563  return &to_upper_mapping_;
564  }
566  return &to_lower_mapping_;
567  }
569  return &string_input_buffer_compare_bufx_;
570  }
572  return &string_input_buffer_compare_bufy_;
573  }
575  return &string_locale_compare_buf1_;
576  }
578  return &string_locale_compare_buf2_;
579  }
580 
581  private:
582  RuntimeState() {}
583  // Non-reentrant string buffer for efficient general use in the runtime.
584  StaticResource<StringInputBuffer> string_input_buffer_;
587  StringInputBuffer string_input_buffer_compare_bufx_;
588  StringInputBuffer string_input_buffer_compare_bufy_;
589  StringInputBuffer string_locale_compare_buf1_;
590  StringInputBuffer string_locale_compare_buf2_;
591 
592  friend class Isolate;
593  friend class Runtime;
594 
596 };
597 
598 
599 class Runtime : public AllStatic {
600  public:
601  enum FunctionId {
602 #define F(name, nargs, ressize) k##name,
604 #undef F
605 #define F(name, nargs, ressize) kInline##name,
608 #undef F
610  kFirstInlineFunction = kInlineIsSmi
611  };
612 
616  };
617 
618  // Intrinsic function descriptor.
619  struct Function {
622  // The JS name of the function.
623  const char* name;
624 
625  // The C++ (native) entry point. NULL if the function is inlined.
627 
628  // The number of arguments expected. nargs is -1 if the function takes
629  // a variable number of arguments.
630  int nargs;
631  // Size of result. Most functions return a single pointer, size 1.
633  };
634 
635  static const int kNotFound = -1;
636 
637  // Add symbols for all the intrinsic function names to a StringDictionary.
638  // Returns failure if an allocation fails. In this case, it must be
639  // retried with a new, empty StringDictionary, not with the same one.
640  // Alternatively, heap initialization can be completely restarted.
642  Heap* heap, Object* dictionary);
643 
644  // Get the intrinsic function with the given name, which must be a symbol.
645  static const Function* FunctionForSymbol(Handle<String> name);
646 
647  // Get the intrinsic function with the given FunctionId.
648  static const Function* FunctionForId(FunctionId id);
649 
650  // General-purpose helper functions for runtime system.
651  static int StringMatch(Isolate* isolate,
652  Handle<String> sub,
653  Handle<String> pat,
654  int index);
655 
656  static bool IsUpperCaseChar(RuntimeState* runtime_state, uint16_t ch);
657 
658  // TODO(1240886): Some of the following methods are *not* handle safe, but
659  // accept handle arguments. This seems fragile.
660 
661  // Support getting the characters in a string using [] notation as
662  // in Firefox/SpiderMonkey, Safari and Opera.
663  MUST_USE_RESULT static MaybeObject* GetElementOrCharAt(Isolate* isolate,
664  Handle<Object> object,
665  uint32_t index);
666 
667  MUST_USE_RESULT static MaybeObject* SetObjectProperty(
668  Isolate* isolate,
669  Handle<Object> object,
670  Handle<Object> key,
671  Handle<Object> value,
672  PropertyAttributes attr,
673  StrictModeFlag strict_mode);
674 
675  MUST_USE_RESULT static MaybeObject* ForceSetObjectProperty(
676  Isolate* isolate,
677  Handle<JSObject> object,
678  Handle<Object> key,
679  Handle<Object> value,
680  PropertyAttributes attr);
681 
682  MUST_USE_RESULT static MaybeObject* ForceDeleteObjectProperty(
683  Isolate* isolate,
684  Handle<JSReceiver> object,
685  Handle<Object> key);
686 
687  MUST_USE_RESULT static MaybeObject* GetObjectProperty(
688  Isolate* isolate,
689  Handle<Object> object,
690  Handle<Object> key);
691 
692  // Helper functions used stubs.
693  static void PerformGC(Object* result);
694 
695  // Used in runtime.cc and hydrogen's VisitArrayLiteral.
697  Isolate* isolate,
698  Handle<FixedArray> literals,
699  Handle<FixedArray> elements);
700 };
701 
702 
703 //---------------------------------------------------------------------------
704 // Constants used by interface to runtime functions.
705 
706 class DeclareGlobalsEvalFlag: public BitField<bool, 0, 1> {};
707 class DeclareGlobalsNativeFlag: public BitField<bool, 1, 1> {};
708 class DeclareGlobalsLanguageMode: public BitField<LanguageMode, 2, 2> {};
709 
710 } } // namespace v8::internal
711 
712 #endif // V8_RUNTIME_H_
#define INLINE_FUNCTION_LIST(F)
Definition: runtime.h:503
static const int kNotFound
Definition: runtime.h:635
static const Function * FunctionForSymbol(Handle< String > name)
Definition: runtime.cc:13262
static void PerformGC(Object *result)
Definition: runtime.cc:13279
static MUST_USE_RESULT MaybeObject * ForceDeleteObjectProperty(Isolate *isolate, Handle< JSReceiver > object, Handle< Object > key)
Definition: runtime.cc:4357
static MUST_USE_RESULT MaybeObject * SetObjectProperty(Isolate *isolate, Handle< Object > object, Handle< Object > key, Handle< Object > value, PropertyAttributes attr, StrictModeFlag strict_mode)
Definition: runtime.cc:4222
static const Function * FunctionForId(FunctionId id)
Definition: runtime.cc:13274
unsigned short uint16_t
Definition: unicode.cc:46
StringInputBuffer * string_input_buffer_compare_bufy()
Definition: runtime.h:571
PropertyAttributes
#define RUNTIME_FUNCTION_LIST(F)
Definition: runtime.h:493
static MUST_USE_RESULT MaybeObject * InitializeIntrinsicFunctionNames(Heap *heap, Object *dictionary)
Definition: runtime.cc:13235
uint8_t byte
Definition: globals.h:156
StringInputBuffer * string_locale_compare_buf2()
Definition: runtime.h:577
#define MUST_USE_RESULT
Definition: globals.h:346
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: globals.h:307
IntrinsicType intrinsic_type
Definition: runtime.h:621
unibrow::Mapping< unibrow::ToUppercase, 128 > * to_upper_mapping()
Definition: runtime.h:562
static int StringMatch(Isolate *isolate, Handle< String > sub, Handle< String > pat, int index)
Definition: runtime.cc:3355
static bool IsUpperCaseChar(RuntimeState *runtime_state, uint16_t ch)
Definition: runtime.cc:6298
static Handle< Object > CreateArrayLiteralBoilerplate(Isolate *isolate, Handle< FixedArray > literals, Handle< FixedArray > elements)
Definition: runtime.cc:461
StringInputBuffer * string_input_buffer_compare_bufx()
Definition: runtime.h:568
static MUST_USE_RESULT MaybeObject * GetObjectProperty(Isolate *isolate, Handle< Object > object, Handle< Object > key)
Definition: runtime.cc:3970
static MUST_USE_RESULT MaybeObject * ForceSetObjectProperty(Isolate *isolate, Handle< JSObject > object, Handle< Object > key, Handle< Object > value, PropertyAttributes attr)
Definition: runtime.cc:4304
StaticResource< StringInputBuffer > * string_input_buffer()
Definition: runtime.h:559
unibrow::Mapping< unibrow::ToLowercase, 128 > * to_lower_mapping()
Definition: runtime.h:565
#define INLINE_RUNTIME_FUNCTION_LIST(F)
Definition: runtime.h:541
StringInputBuffer * string_locale_compare_buf1()
Definition: runtime.h:574
static MUST_USE_RESULT MaybeObject * GetElementOrCharAt(Isolate *isolate, Handle< Object > object, uint32_t index)
Definition: runtime.cc:3945