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
34namespace v8 {
35namespace internal {
36
37// The interface to C++ runtime functions.
38
39// ----------------------------------------------------------------------------
40// RUNTIME_FUNCTION_LIST_ALWAYS defines runtime calls available in both
41// release and debug mode.
42// This macro should only be used by the macro RUNTIME_FUNCTION_LIST.
43
44// WARNING: RUNTIME_FUNCTION_LIST_ALWAYS_* is a very large macro that caused
45// MSVC Intellisense to crash.  It was broken into two macros to work around
46// this problem. Please avoid large recursive macros whenever possible.
47#define RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
48  /* Property access */ \
49  F(GetProperty, 2, 1) \
50  F(KeyedGetProperty, 2, 1) \
51  F(DeleteProperty, 3, 1) \
52  F(HasLocalProperty, 2, 1) \
53  F(HasProperty, 2, 1) \
54  F(HasElement, 2, 1) \
55  F(IsPropertyEnumerable, 2, 1) \
56  F(GetPropertyNames, 1, 1) \
57  F(GetPropertyNamesFast, 1, 1) \
58  F(GetLocalPropertyNames, 2, 1) \
59  F(GetLocalElementNames, 1, 1) \
60  F(GetInterceptorInfo, 1, 1) \
61  F(GetNamedInterceptorPropertyNames, 1, 1) \
62  F(GetIndexedInterceptorElementNames, 1, 1) \
63  F(GetArgumentsProperty, 1, 1) \
64  F(ToFastProperties, 1, 1) \
65  F(FinishArrayPrototypeSetup, 1, 1) \
66  F(SpecialArrayFunctions, 1, 1) \
67  F(IsClassicModeFunction, 1, 1) \
68  F(GetDefaultReceiver, 1, 1) \
69  \
70  F(GetPrototype, 1, 1) \
71  F(SetPrototype, 2, 1) \
72  F(IsInPrototypeChain, 2, 1) \
73  \
74  F(GetOwnProperty, 2, 1) \
75  \
76  F(IsExtensible, 1, 1) \
77  F(PreventExtensions, 1, 1)\
78  \
79  /* Utilities */ \
80  F(CheckIsBootstrapping, 0, 1) \
81  F(GetRootNaN, 0, 1) \
82  F(Call, -1 /* >= 2 */, 1) \
83  F(Apply, 5, 1) \
84  F(GetFunctionDelegate, 1, 1) \
85  F(GetConstructorDelegate, 1, 1) \
86  F(NewArgumentsFast, 3, 1) \
87  F(NewStrictArgumentsFast, 3, 1) \
88  F(LazyCompile, 1, 1) \
89  F(LazyRecompile, 1, 1) \
90  F(ParallelRecompile, 1, 1) \
91  F(InstallRecompiledCode, 1, 1) \
92  F(NotifyDeoptimized, 1, 1) \
93  F(NotifyStubFailure, 0, 1) \
94  F(NotifyOSR, 0, 1) \
95  F(DeoptimizeFunction, 1, 1) \
96  F(ClearFunctionTypeFeedback, 1, 1) \
97  F(RunningInSimulator, 0, 1) \
98  F(IsParallelRecompilationSupported, 0, 1) \
99  F(OptimizeFunctionOnNextCall, -1, 1) \
100  F(NeverOptimizeFunction, 1, 1) \
101  F(GetOptimizationStatus, -1, 1) \
102  F(GetOptimizationCount, 1, 1) \
103  F(CompileForOnStackReplacement, 1, 1) \
104  F(SetAllocationTimeout, 2, 1) \
105  F(AllocateInNewSpace, 1, 1) \
106  F(AllocateInOldPointerSpace, 1, 1) \
107  F(AllocateInOldDataSpace, 1, 1) \
108  F(SetNativeFlag, 1, 1) \
109  F(StoreArrayLiteralElement, 5, 1) \
110  F(DebugCallbackSupportsStepping, 1, 1) \
111  F(DebugPrepareStepInIfStepping, 1, 1) \
112  F(FlattenString, 1, 1) \
113  F(MigrateInstance, 1, 1) \
114  F(NotifyContextDisposed, 0, 1) \
115  \
116  /* Array join support */ \
117  F(PushIfAbsent, 2, 1) \
118  F(ArrayConcat, 1, 1) \
119  \
120  /* Conversions */ \
121  F(ToBool, 1, 1) \
122  F(Typeof, 1, 1) \
123  \
124  F(StringToNumber, 1, 1) \
125  F(StringParseInt, 2, 1) \
126  F(StringParseFloat, 1, 1) \
127  F(StringToLowerCase, 1, 1) \
128  F(StringToUpperCase, 1, 1) \
129  F(StringSplit, 3, 1) \
130  F(CharFromCode, 1, 1) \
131  F(URIEscape, 1, 1) \
132  F(URIUnescape, 1, 1) \
133  \
134  F(NumberToString, 1, 1) \
135  F(NumberToStringSkipCache, 1, 1) \
136  F(NumberToInteger, 1, 1) \
137  F(NumberToPositiveInteger, 1, 1) \
138  F(NumberToIntegerMapMinusZero, 1, 1) \
139  F(NumberToJSUint32, 1, 1) \
140  F(NumberToJSInt32, 1, 1) \
141  F(NumberToSmi, 1, 1) \
142  F(AllocateHeapNumber, 0, 1) \
143  \
144  /* Arithmetic operations */ \
145  F(NumberAdd, 2, 1) \
146  F(NumberSub, 2, 1) \
147  F(NumberMul, 2, 1) \
148  F(NumberDiv, 2, 1) \
149  F(NumberMod, 2, 1) \
150  F(NumberUnaryMinus, 1, 1) \
151  F(NumberAlloc, 0, 1) \
152  F(NumberImul, 2, 1) \
153  \
154  F(StringAdd, 2, 1) \
155  F(StringBuilderConcat, 3, 1) \
156  F(StringBuilderJoin, 3, 1) \
157  F(SparseJoinWithSeparator, 3, 1) \
158  \
159  /* Bit operations */ \
160  F(NumberOr, 2, 1) \
161  F(NumberAnd, 2, 1) \
162  F(NumberXor, 2, 1) \
163  \
164  F(NumberShl, 2, 1) \
165  F(NumberShr, 2, 1) \
166  F(NumberSar, 2, 1) \
167  \
168  /* Comparisons */ \
169  F(NumberEquals, 2, 1) \
170  F(StringEquals, 2, 1) \
171  \
172  F(NumberCompare, 3, 1) \
173  F(SmiLexicographicCompare, 2, 1) \
174  F(StringCompare, 2, 1) \
175  \
176  /* Math */ \
177  F(Math_acos, 1, 1) \
178  F(Math_asin, 1, 1) \
179  F(Math_atan, 1, 1) \
180  F(Math_atan2, 2, 1) \
181  F(Math_ceil, 1, 1) \
182  F(Math_cos, 1, 1) \
183  F(Math_exp, 1, 1) \
184  F(Math_floor, 1, 1) \
185  F(Math_log, 1, 1) \
186  F(Math_pow, 2, 1) \
187  F(Math_pow_cfunction, 2, 1) \
188  F(RoundNumber, 1, 1) \
189  F(Math_sin, 1, 1) \
190  F(Math_sqrt, 1, 1) \
191  F(Math_tan, 1, 1) \
192  \
193  /* Regular expressions */ \
194  F(RegExpCompile, 3, 1) \
195  F(RegExpExec, 4, 1) \
196  F(RegExpExecMultiple, 4, 1) \
197  F(RegExpInitializeObject, 5, 1) \
198  F(RegExpConstructResult, 3, 1) \
199  \
200  /* JSON */ \
201  F(ParseJson, 1, 1) \
202  F(BasicJSONStringify, 1, 1) \
203  F(QuoteJSONString, 1, 1) \
204  \
205  /* Strings */ \
206  F(StringCharCodeAt, 2, 1) \
207  F(StringIndexOf, 3, 1) \
208  F(StringLastIndexOf, 3, 1) \
209  F(StringLocaleCompare, 2, 1) \
210  F(SubString, 3, 1) \
211  F(StringReplaceGlobalRegExpWithString, 4, 1) \
212  F(StringReplaceOneCharWithString, 3, 1) \
213  F(StringMatch, 3, 1) \
214  F(StringTrim, 3, 1) \
215  F(StringToArray, 2, 1) \
216  F(NewStringWrapper, 1, 1) \
217  F(NewString, 2, 1) \
218  F(TruncateString, 2, 1) \
219  \
220  /* Numbers */ \
221  F(NumberToRadixString, 2, 1) \
222  F(NumberToFixed, 2, 1) \
223  F(NumberToExponential, 2, 1) \
224  F(NumberToPrecision, 2, 1)
225
226
227#define RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
228  /* Reflection */ \
229  F(FunctionSetInstanceClassName, 2, 1) \
230  F(FunctionSetLength, 2, 1) \
231  F(FunctionSetPrototype, 2, 1) \
232  F(FunctionSetReadOnlyPrototype, 1, 1) \
233  F(FunctionGetName, 1, 1) \
234  F(FunctionSetName, 2, 1) \
235  F(FunctionNameShouldPrintAsAnonymous, 1, 1) \
236  F(FunctionMarkNameShouldPrintAsAnonymous, 1, 1) \
237  F(FunctionIsGenerator, 1, 1) \
238  F(FunctionBindArguments, 4, 1) \
239  F(BoundFunctionGetBindings, 1, 1) \
240  F(FunctionRemovePrototype, 1, 1) \
241  F(FunctionGetSourceCode, 1, 1) \
242  F(FunctionGetScript, 1, 1) \
243  F(FunctionGetScriptSourcePosition, 1, 1) \
244  F(FunctionGetPositionForOffset, 2, 1) \
245  F(FunctionIsAPIFunction, 1, 1) \
246  F(FunctionIsBuiltin, 1, 1) \
247  F(GetScript, 1, 1) \
248  F(CollectStackTrace, 3, 1) \
249  F(GetAndClearOverflowedStackTrace, 1, 1) \
250  F(GetV8Version, 0, 1) \
251  \
252  F(ClassOf, 1, 1) \
253  F(SetCode, 2, 1) \
254  F(SetExpectedNumberOfProperties, 2, 1) \
255  \
256  F(CreateApiFunction, 1, 1) \
257  F(IsTemplate, 1, 1) \
258  F(GetTemplateField, 2, 1) \
259  F(DisableAccessChecks, 1, 1) \
260  F(EnableAccessChecks, 1, 1) \
261  \
262  /* Dates */ \
263  F(DateCurrentTime, 0, 1) \
264  F(DateParseString, 2, 1) \
265  F(DateLocalTimezone, 1, 1) \
266  F(DateToUTC, 1, 1) \
267  F(DateMakeDay, 2, 1) \
268  F(DateSetValue, 3, 1) \
269  \
270  /* Numbers */ \
271  \
272  /* Globals */ \
273  F(CompileString, 2, 1) \
274  F(GlobalPrint, 1, 1) \
275  \
276  /* Eval */ \
277  F(GlobalReceiver, 1, 1) \
278  F(ResolvePossiblyDirectEval, 5, 2) \
279  \
280  F(SetProperty, -1 /* 4 or 5 */, 1) \
281  F(DefineOrRedefineDataProperty, 4, 1) \
282  F(DefineOrRedefineAccessorProperty, 5, 1) \
283  F(IgnoreAttributesAndSetProperty, -1 /* 3 or 4 */, 1) \
284  F(GetDataProperty, 2, 1) \
285  \
286  /* Arrays */ \
287  F(RemoveArrayHoles, 2, 1) \
288  F(GetArrayKeys, 2, 1) \
289  F(MoveArrayContents, 2, 1) \
290  F(EstimateNumberOfElements, 1, 1) \
291  F(ArrayConstructor, -1, 1) \
292  F(InternalArrayConstructor, -1, 1) \
293  \
294  /* Getters and Setters */ \
295  F(LookupAccessor, 3, 1) \
296  \
297  /* Literals */ \
298  F(MaterializeRegExpLiteral, 4, 1)\
299  F(CreateObjectLiteral, 4, 1) \
300  F(CreateObjectLiteralShallow, 4, 1) \
301  F(CreateArrayLiteral, 3, 1) \
302  F(CreateArrayLiteralShallow, 3, 1) \
303  \
304  /* Harmony generators */ \
305  F(CreateJSGeneratorObject, 0, 1) \
306  F(SuspendJSGeneratorObject, 1, 1) \
307  F(ResumeJSGeneratorObject, 3, 1) \
308  F(ThrowGeneratorStateError, 1, 1) \
309  \
310  /* ES5 */ \
311  F(ObjectFreeze, 1, 1) \
312  \
313  /* Harmony modules */ \
314  F(IsJSModule, 1, 1) \
315  \
316  /* Harmony symbols */ \
317  F(CreateSymbol, 1, 1) \
318  F(SymbolName, 1, 1) \
319  \
320  /* Harmony proxies */ \
321  F(CreateJSProxy, 2, 1) \
322  F(CreateJSFunctionProxy, 4, 1) \
323  F(IsJSProxy, 1, 1) \
324  F(IsJSFunctionProxy, 1, 1) \
325  F(GetHandler, 1, 1) \
326  F(GetCallTrap, 1, 1) \
327  F(GetConstructTrap, 1, 1) \
328  F(Fix, 1, 1) \
329  \
330  /* Harmony sets */ \
331  F(SetInitialize, 1, 1) \
332  F(SetAdd, 2, 1) \
333  F(SetHas, 2, 1) \
334  F(SetDelete, 2, 1) \
335  F(SetGetSize, 1, 1) \
336  \
337  /* Harmony maps */ \
338  F(MapInitialize, 1, 1) \
339  F(MapGet, 2, 1) \
340  F(MapHas, 2, 1) \
341  F(MapDelete, 2, 1) \
342  F(MapSet, 3, 1) \
343  F(MapGetSize, 1, 1) \
344  \
345  /* Harmony weak maps and sets */ \
346  F(WeakCollectionInitialize, 1, 1) \
347  F(WeakCollectionGet, 2, 1) \
348  F(WeakCollectionHas, 2, 1) \
349  F(WeakCollectionDelete, 2, 1) \
350  F(WeakCollectionSet, 3, 1) \
351  \
352  /* Harmony observe */ \
353  F(IsObserved, 1, 1) \
354  F(SetIsObserved, 1, 1) \
355  F(SetObserverDeliveryPending, 0, 1) \
356  F(GetObservationState, 0, 1) \
357  F(ObservationWeakMapCreate, 0, 1) \
358  F(UnwrapGlobalProxy, 1, 1) \
359  \
360  /* Harmony typed arrays */ \
361  F(ArrayBufferInitialize, 2, 1)\
362  F(ArrayBufferGetByteLength, 1, 1)\
363  F(ArrayBufferSliceImpl, 3, 1) \
364  \
365  F(TypedArrayInitialize, 5, 1) \
366  F(TypedArrayInitializeFromArrayLike, 4, 1) \
367  F(TypedArrayGetBuffer, 1, 1) \
368  F(TypedArrayGetByteLength, 1, 1) \
369  F(TypedArrayGetByteOffset, 1, 1) \
370  F(TypedArrayGetLength, 1, 1) \
371  F(TypedArraySetFastCases, 3, 1) \
372  \
373  F(DataViewInitialize, 4, 1) \
374  F(DataViewGetBuffer, 1, 1) \
375  F(DataViewGetByteLength, 1, 1) \
376  F(DataViewGetByteOffset, 1, 1) \
377  F(DataViewGetInt8, 3, 1) \
378  F(DataViewGetUint8, 3, 1) \
379  F(DataViewGetInt16, 3, 1) \
380  F(DataViewGetUint16, 3, 1) \
381  F(DataViewGetInt32, 3, 1) \
382  F(DataViewGetUint32, 3, 1) \
383  F(DataViewGetFloat32, 3, 1) \
384  F(DataViewGetFloat64, 3, 1) \
385  \
386  F(DataViewSetInt8, 4, 1) \
387  F(DataViewSetUint8, 4, 1) \
388  F(DataViewSetInt16, 4, 1) \
389  F(DataViewSetUint16, 4, 1) \
390  F(DataViewSetInt32, 4, 1) \
391  F(DataViewSetUint32, 4, 1) \
392  F(DataViewSetFloat32, 4, 1) \
393  F(DataViewSetFloat64, 4, 1) \
394  \
395  /* Statements */ \
396  F(NewClosure, 3, 1) \
397  F(NewObject, 1, 1) \
398  F(NewObjectFromBound, 1, 1) \
399  F(FinalizeInstanceSize, 1, 1) \
400  F(Throw, 1, 1) \
401  F(ReThrow, 1, 1) \
402  F(ThrowReferenceError, 1, 1) \
403  F(ThrowNotDateError, 0, 1) \
404  F(StackGuard, 0, 1) \
405  F(Interrupt, 0, 1) \
406  F(PromoteScheduledException, 0, 1) \
407  \
408  /* Contexts */ \
409  F(NewGlobalContext, 2, 1) \
410  F(NewFunctionContext, 1, 1) \
411  F(PushWithContext, 2, 1) \
412  F(PushCatchContext, 3, 1) \
413  F(PushBlockContext, 2, 1) \
414  F(PushModuleContext, 2, 1) \
415  F(DeleteContextSlot, 2, 1) \
416  F(LoadContextSlot, 2, 2) \
417  F(LoadContextSlotNoReferenceError, 2, 2) \
418  F(StoreContextSlot, 4, 1) \
419  \
420  /* Declarations and initialization */ \
421  F(DeclareGlobals, 3, 1) \
422  F(DeclareModules, 1, 1) \
423  F(DeclareContextSlot, 4, 1) \
424  F(InitializeVarGlobal, -1 /* 2 or 3 */, 1) \
425  F(InitializeConstGlobal, 2, 1) \
426  F(InitializeConstContextSlot, 3, 1) \
427  F(OptimizeObjectForAddingMultipleProperties, 2, 1) \
428  \
429  /* Debugging */ \
430  F(DebugPrint, 1, 1) \
431  F(DebugTrace, 0, 1) \
432  F(TraceEnter, 0, 1) \
433  F(TraceExit, 1, 1) \
434  F(Abort, 2, 1) \
435  /* Logging */ \
436  F(Log, 2, 1) \
437  /* ES5 */ \
438  F(LocalKeys, 1, 1) \
439  /* Cache suport */ \
440  F(GetFromCache, 2, 1) \
441  \
442  /* Message objects */ \
443  F(MessageGetStartPosition, 1, 1) \
444  F(MessageGetScript, 1, 1) \
445  \
446  /* Pseudo functions - handled as macros by parser */ \
447  F(IS_VAR, 1, 1) \
448  \
449  /* expose boolean functions from objects-inl.h */ \
450  F(HasFastSmiElements, 1, 1) \
451  F(HasFastSmiOrObjectElements, 1, 1) \
452  F(HasFastObjectElements, 1, 1) \
453  F(HasFastDoubleElements, 1, 1) \
454  F(HasFastHoleyElements, 1, 1) \
455  F(HasDictionaryElements, 1, 1) \
456  F(HasNonStrictArgumentsElements, 1, 1) \
457  F(HasExternalPixelElements, 1, 1) \
458  F(HasExternalArrayElements, 1, 1) \
459  F(HasExternalByteElements, 1, 1) \
460  F(HasExternalUnsignedByteElements, 1, 1) \
461  F(HasExternalShortElements, 1, 1) \
462  F(HasExternalUnsignedShortElements, 1, 1) \
463  F(HasExternalIntElements, 1, 1) \
464  F(HasExternalUnsignedIntElements, 1, 1) \
465  F(HasExternalFloatElements, 1, 1) \
466  F(HasExternalDoubleElements, 1, 1) \
467  F(HasFastProperties, 1, 1) \
468  F(TransitionElementsKind, 2, 1) \
469  F(HaveSameMap, 2, 1)
470
471
472#ifdef ENABLE_DEBUGGER_SUPPORT
473#define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \
474  /* Debugger support*/ \
475  F(DebugBreak, 0, 1) \
476  F(SetDebugEventListener, 2, 1) \
477  F(Break, 0, 1) \
478  F(DebugGetPropertyDetails, 2, 1) \
479  F(DebugGetProperty, 2, 1) \
480  F(DebugPropertyTypeFromDetails, 1, 1) \
481  F(DebugPropertyAttributesFromDetails, 1, 1) \
482  F(DebugPropertyIndexFromDetails, 1, 1) \
483  F(DebugNamedInterceptorPropertyValue, 2, 1) \
484  F(DebugIndexedInterceptorElementValue, 2, 1) \
485  F(CheckExecutionState, 1, 1) \
486  F(GetFrameCount, 1, 1) \
487  F(GetFrameDetails, 2, 1) \
488  F(GetScopeCount, 2, 1) \
489  F(GetStepInPositions, 2, 1) \
490  F(GetScopeDetails, 4, 1) \
491  F(GetFunctionScopeCount, 1, 1) \
492  F(GetFunctionScopeDetails, 2, 1) \
493  F(SetScopeVariableValue, 6, 1) \
494  F(DebugPrintScopes, 0, 1) \
495  F(GetThreadCount, 1, 1) \
496  F(GetThreadDetails, 2, 1) \
497  F(SetDisableBreak, 1, 1) \
498  F(GetBreakLocations, 2, 1) \
499  F(SetFunctionBreakPoint, 3, 1) \
500  F(SetScriptBreakPoint, 4, 1) \
501  F(ClearBreakPoint, 1, 1) \
502  F(ChangeBreakOnException, 2, 1) \
503  F(IsBreakOnException, 1, 1) \
504  F(PrepareStep, 3, 1) \
505  F(ClearStepping, 0, 1) \
506  F(DebugEvaluate, 6, 1) \
507  F(DebugEvaluateGlobal, 4, 1) \
508  F(DebugGetLoadedScripts, 0, 1) \
509  F(DebugReferencedBy, 3, 1) \
510  F(DebugConstructedBy, 2, 1) \
511  F(DebugGetPrototype, 1, 1) \
512  F(DebugSetScriptSource, 2, 1) \
513  F(SystemBreak, 0, 1) \
514  F(DebugDisassembleFunction, 1, 1) \
515  F(DebugDisassembleConstructor, 1, 1) \
516  F(FunctionGetInferredName, 1, 1) \
517  F(LiveEditFindSharedFunctionInfosForScript, 1, 1) \
518  F(LiveEditGatherCompileInfo, 2, 1) \
519  F(LiveEditReplaceScript, 3, 1) \
520  F(LiveEditReplaceFunctionCode, 2, 1) \
521  F(LiveEditFunctionSourceUpdated, 1, 1) \
522  F(LiveEditFunctionSetScript, 2, 1) \
523  F(LiveEditReplaceRefToNestedFunction, 3, 1) \
524  F(LiveEditPatchFunctionPositions, 2, 1) \
525  F(LiveEditCheckAndDropActivations, 2, 1) \
526  F(LiveEditCompareStrings, 2, 1) \
527  F(LiveEditRestartFrame, 2, 1) \
528  F(GetFunctionCodePositionFromSource, 2, 1) \
529  F(ExecuteInDebugContext, 2, 1) \
530  \
531  F(SetFlags, 1, 1) \
532  F(CollectGarbage, 1, 1) \
533  F(GetHeapUsage, 0, 1) \
534
535#else
536#define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F)
537#endif
538
539
540#ifdef V8_I18N_SUPPORT
541#define RUNTIME_FUNCTION_LIST_I18N_SUPPORT(F) \
542  /* i18n support */ \
543  /* Standalone, helper methods. */ \
544  F(CanonicalizeLanguageTag, 1, 1) \
545  F(AvailableLocalesOf, 1, 1) \
546  F(GetDefaultICULocale, 0, 1) \
547  F(GetLanguageTagVariants, 1, 1) \
548  \
549  /* Date format and parse. */ \
550  F(CreateDateTimeFormat, 3, 1) \
551  F(InternalDateFormat, 2, 1) \
552  F(InternalDateParse, 2, 1) \
553  \
554  /* Number format and parse. */ \
555  F(CreateNumberFormat, 3, 1) \
556  F(InternalNumberFormat, 2, 1) \
557  F(InternalNumberParse, 2, 1) \
558  \
559  /* Collator. */ \
560  F(CreateCollator, 3, 1) \
561  F(InternalCompare, 3, 1) \
562
563#else
564#define RUNTIME_FUNCTION_LIST_I18N_SUPPORT(F)
565#endif
566
567
568#ifdef DEBUG
569#define RUNTIME_FUNCTION_LIST_DEBUG(F) \
570  /* Testing */ \
571  F(ListNatives, 0, 1)
572#else
573#define RUNTIME_FUNCTION_LIST_DEBUG(F)
574#endif
575
576// ----------------------------------------------------------------------------
577// RUNTIME_FUNCTION_LIST defines all runtime functions accessed
578// either directly by id (via the code generator), or indirectly
579// via a native call by name (from within JS code).
580
581#define RUNTIME_FUNCTION_LIST(F) \
582  RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
583  RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
584  RUNTIME_FUNCTION_LIST_DEBUG(F) \
585  RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \
586  RUNTIME_FUNCTION_LIST_I18N_SUPPORT(F)
587
588// ----------------------------------------------------------------------------
589// INLINE_FUNCTION_LIST defines all inlined functions accessed
590// with a native call of the form %_name from within JS code.
591// Entries have the form F(name, number of arguments, number of return values).
592#define INLINE_FUNCTION_LIST(F) \
593  F(IsSmi, 1, 1)                                                             \
594  F(IsNonNegativeSmi, 1, 1)                                                  \
595  F(IsArray, 1, 1)                                                           \
596  F(IsRegExp, 1, 1)                                                          \
597  F(IsConstructCall, 0, 1)                                                   \
598  F(CallFunction, -1 /* receiver + n args + function */, 1)                  \
599  F(ArgumentsLength, 0, 1)                                                   \
600  F(Arguments, 1, 1)                                                         \
601  F(ValueOf, 1, 1)                                                           \
602  F(SetValueOf, 2, 1)                                                        \
603  F(DateField, 2 /* date object, field index */, 1)                          \
604  F(StringCharFromCode, 1, 1)                                                \
605  F(StringCharAt, 2, 1)                                                      \
606  F(OneByteSeqStringSetChar, 3, 1)                                           \
607  F(TwoByteSeqStringSetChar, 3, 1)                                           \
608  F(ObjectEquals, 2, 1)                                                      \
609  F(RandomHeapNumber, 0, 1)                                                  \
610  F(IsObject, 1, 1)                                                          \
611  F(IsFunction, 1, 1)                                                        \
612  F(IsUndetectableObject, 1, 1)                                              \
613  F(IsSpecObject, 1, 1)                                                      \
614  F(IsStringWrapperSafeForDefaultValueOf, 1, 1)                              \
615  F(MathPow, 2, 1)                                                           \
616  F(MathSin, 1, 1)                                                           \
617  F(MathCos, 1, 1)                                                           \
618  F(MathTan, 1, 1)                                                           \
619  F(MathSqrt, 1, 1)                                                          \
620  F(MathLog, 1, 1)                                                           \
621  F(IsRegExpEquivalent, 2, 1)                                                \
622  F(HasCachedArrayIndex, 1, 1)                                               \
623  F(GetCachedArrayIndex, 1, 1)                                               \
624  F(FastAsciiArrayJoin, 2, 1)                                                \
625  F(GeneratorNext, 2, 1)                                                     \
626  F(GeneratorThrow, 2, 1)                                                    \
627  F(DebugBreakInOptimizedCode, 0, 1)
628
629
630// ----------------------------------------------------------------------------
631// INLINE_RUNTIME_FUNCTION_LIST defines all inlined functions accessed
632// with a native call of the form %_name from within JS code that also have
633// a corresponding runtime function, that is called for slow cases.
634// Entries have the form F(name, number of arguments, number of return values).
635#define INLINE_RUNTIME_FUNCTION_LIST(F) \
636  F(ClassOf, 1, 1)                                                           \
637  F(StringCharCodeAt, 2, 1)                                                  \
638  F(Log, 3, 1)                                                               \
639  F(StringAdd, 2, 1)                                                         \
640  F(SubString, 3, 1)                                                         \
641  F(StringCompare, 2, 1)                                                     \
642  F(RegExpExec, 4, 1)                                                        \
643  F(RegExpConstructResult, 3, 1)                                             \
644  F(GetFromCache, 2, 1)                                                      \
645  F(NumberToString, 1, 1)
646
647
648//---------------------------------------------------------------------------
649// Runtime provides access to all C++ runtime functions.
650
651class RuntimeState {
652 public:
653  StaticResource<ConsStringIteratorOp>* string_iterator() {
654    return &string_iterator_;
655  }
656  unibrow::Mapping<unibrow::ToUppercase, 128>* to_upper_mapping() {
657    return &to_upper_mapping_;
658  }
659  unibrow::Mapping<unibrow::ToLowercase, 128>* to_lower_mapping() {
660    return &to_lower_mapping_;
661  }
662  ConsStringIteratorOp* string_iterator_compare_x() {
663    return &string_iterator_compare_x_;
664  }
665  ConsStringIteratorOp* string_iterator_compare_y() {
666    return &string_iterator_compare_y_;
667  }
668  ConsStringIteratorOp* string_locale_compare_it1() {
669    return &string_locale_compare_it1_;
670  }
671  ConsStringIteratorOp* string_locale_compare_it2() {
672    return &string_locale_compare_it2_;
673  }
674
675 private:
676  RuntimeState() {}
677  // Non-reentrant string buffer for efficient general use in the runtime.
678  StaticResource<ConsStringIteratorOp> string_iterator_;
679  unibrow::Mapping<unibrow::ToUppercase, 128> to_upper_mapping_;
680  unibrow::Mapping<unibrow::ToLowercase, 128> to_lower_mapping_;
681  ConsStringIteratorOp string_iterator_compare_x_;
682  ConsStringIteratorOp string_iterator_compare_y_;
683  ConsStringIteratorOp string_locale_compare_it1_;
684  ConsStringIteratorOp string_locale_compare_it2_;
685
686  friend class Isolate;
687  friend class Runtime;
688
689  DISALLOW_COPY_AND_ASSIGN(RuntimeState);
690};
691
692
693class Runtime : public AllStatic {
694 public:
695  enum FunctionId {
696#define F(name, nargs, ressize) k##name,
697    RUNTIME_FUNCTION_LIST(F)
698#undef F
699#define F(name, nargs, ressize) kInline##name,
700    INLINE_FUNCTION_LIST(F)
701    INLINE_RUNTIME_FUNCTION_LIST(F)
702#undef F
703    kNumFunctions,
704    kFirstInlineFunction = kInlineIsSmi
705  };
706
707  enum IntrinsicType {
708    RUNTIME,
709    INLINE
710  };
711
712  // Intrinsic function descriptor.
713  struct Function {
714    FunctionId function_id;
715    IntrinsicType intrinsic_type;
716    // The JS name of the function.
717    const char* name;
718
719    // The C++ (native) entry point.  NULL if the function is inlined.
720    byte* entry;
721
722    // The number of arguments expected. nargs is -1 if the function takes
723    // a variable number of arguments.
724    int nargs;
725    // Size of result.  Most functions return a single pointer, size 1.
726    int result_size;
727  };
728
729  static const int kNotFound = -1;
730
731  // Add internalized strings for all the intrinsic function names to a
732  // StringDictionary.
733  // Returns failure if an allocation fails.  In this case, it must be
734  // retried with a new, empty StringDictionary, not with the same one.
735  // Alternatively, heap initialization can be completely restarted.
736  MUST_USE_RESULT static MaybeObject* InitializeIntrinsicFunctionNames(
737      Heap* heap, Object* dictionary);
738
739  // Get the intrinsic function with the given name, which must be internalized.
740  static const Function* FunctionForName(Handle<String> name);
741
742  // Get the intrinsic function with the given FunctionId.
743  static const Function* FunctionForId(FunctionId id);
744
745  // General-purpose helper functions for runtime system.
746  static int StringMatch(Isolate* isolate,
747                         Handle<String> sub,
748                         Handle<String> pat,
749                         int index);
750
751  static bool IsUpperCaseChar(RuntimeState* runtime_state, uint16_t ch);
752
753  // TODO(1240886): Some of the following methods are *not* handle safe, but
754  // accept handle arguments. This seems fragile.
755
756  // Support getting the characters in a string using [] notation as
757  // in Firefox/SpiderMonkey, Safari and Opera.
758  MUST_USE_RESULT static MaybeObject* GetElementOrCharAt(Isolate* isolate,
759                                                         Handle<Object> object,
760                                                         uint32_t index);
761
762  MUST_USE_RESULT static MaybeObject* GetElementOrCharAtOrFail(
763      Isolate* isolate,
764      Handle<Object> object,
765      uint32_t index);
766
767  MUST_USE_RESULT static MaybeObject* SetObjectProperty(
768      Isolate* isolate,
769      Handle<Object> object,
770      Handle<Object> key,
771      Handle<Object> value,
772      PropertyAttributes attr,
773      StrictModeFlag strict_mode);
774
775  MUST_USE_RESULT static MaybeObject* SetObjectPropertyOrFail(
776      Isolate* isolate,
777      Handle<Object> object,
778      Handle<Object> key,
779      Handle<Object> value,
780      PropertyAttributes attr,
781      StrictModeFlag strict_mode);
782
783  MUST_USE_RESULT static MaybeObject* ForceSetObjectProperty(
784      Isolate* isolate,
785      Handle<JSObject> object,
786      Handle<Object> key,
787      Handle<Object> value,
788      PropertyAttributes attr);
789
790  MUST_USE_RESULT static MaybeObject* DeleteObjectProperty(
791      Isolate* isolate,
792      Handle<JSReceiver> object,
793      Handle<Object> key,
794      JSReceiver::DeleteMode mode);
795
796  MUST_USE_RESULT static MaybeObject* HasObjectProperty(
797      Isolate* isolate,
798      Handle<JSReceiver> object,
799      Handle<Object> key);
800
801  MUST_USE_RESULT static MaybeObject* GetObjectProperty(
802      Isolate* isolate,
803      Handle<Object> object,
804      Handle<Object> key);
805
806  MUST_USE_RESULT static MaybeObject* GetObjectPropertyOrFail(
807      Isolate* isolate,
808      Handle<Object> object,
809      Handle<Object> key);
810
811  static void SetupArrayBuffer(Isolate* isolate,
812                               Handle<JSArrayBuffer> array_buffer,
813                               bool is_external,
814                               void* data,
815                               size_t allocated_length);
816
817  static bool SetupArrayBufferAllocatingData(
818      Isolate* isolate,
819      Handle<JSArrayBuffer> array_buffer,
820      size_t allocated_length,
821      bool initialize = true);
822
823  static void FreeArrayBuffer(
824      Isolate* isolate,
825      JSArrayBuffer* phantom_array_buffer);
826
827  // Helper functions used stubs.
828  static void PerformGC(Object* result);
829
830  // Used in runtime.cc and hydrogen's VisitArrayLiteral.
831  static Handle<Object> CreateArrayLiteralBoilerplate(
832      Isolate* isolate,
833      Handle<FixedArray> literals,
834      Handle<FixedArray> elements);
835};
836
837
838//---------------------------------------------------------------------------
839// Constants used by interface to runtime functions.
840
841class DeclareGlobalsEvalFlag:     public BitField<bool,         0, 1> {};
842class DeclareGlobalsNativeFlag:   public BitField<bool,         1, 1> {};
843class DeclareGlobalsLanguageMode: public BitField<LanguageMode, 2, 2> {};
844
845} }  // namespace v8::internal
846
847#endif  // V8_RUNTIME_H_
848