1// Copyright 2012 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_RUNTIME_H_
6#define V8_RUNTIME_H_
7
8#include "src/allocation.h"
9#include "src/zone.h"
10
11namespace v8 {
12namespace internal {
13
14// The interface to C++ runtime functions.
15
16// ----------------------------------------------------------------------------
17// RUNTIME_FUNCTION_LIST_ALWAYS defines runtime calls available in both
18// release and debug mode.
19// This macro should only be used by the macro RUNTIME_FUNCTION_LIST.
20
21// WARNING: RUNTIME_FUNCTION_LIST_ALWAYS_* is a very large macro that caused
22// MSVC Intellisense to crash.  It was broken into two macros to work around
23// this problem. Please avoid large recursive macros whenever possible.
24#define RUNTIME_FUNCTION_LIST_ALWAYS_1(F)                  \
25  /* Property access */                                    \
26  F(GetProperty, 2, 1)                                     \
27  F(KeyedGetProperty, 2, 1)                                \
28  F(DeleteProperty, 3, 1)                                  \
29  F(HasOwnProperty, 2, 1)                                  \
30  F(HasProperty, 2, 1)                                     \
31  F(HasElement, 2, 1)                                      \
32  F(IsPropertyEnumerable, 2, 1)                            \
33  F(GetPropertyNames, 1, 1)                                \
34  F(GetPropertyNamesFast, 1, 1)                            \
35  F(GetOwnPropertyNames, 2, 1)                             \
36  F(GetOwnElementNames, 1, 1)                              \
37  F(GetInterceptorInfo, 1, 1)                              \
38  F(GetNamedInterceptorPropertyNames, 1, 1)                \
39  F(GetIndexedInterceptorElementNames, 1, 1)               \
40  F(GetArgumentsProperty, 1, 1)                            \
41  F(ToFastProperties, 1, 1)                                \
42  F(FinishArrayPrototypeSetup, 1, 1)                       \
43  F(SpecialArrayFunctions, 0, 1)                           \
44  F(IsSloppyModeFunction, 1, 1)                            \
45  F(GetDefaultReceiver, 1, 1)                              \
46                                                           \
47  F(GetPrototype, 1, 1)                                    \
48  F(SetPrototype, 2, 1)                                    \
49  F(InternalSetPrototype, 2, 1)                            \
50  F(IsInPrototypeChain, 2, 1)                              \
51                                                           \
52  F(GetOwnProperty, 2, 1)                                  \
53                                                           \
54  F(IsExtensible, 1, 1)                                    \
55  F(PreventExtensions, 1, 1)                               \
56                                                           \
57  /* Utilities */                                          \
58  F(CheckIsBootstrapping, 0, 1)                            \
59  F(GetRootNaN, 0, 1)                                      \
60  F(Call, -1 /* >= 2 */, 1)                                \
61  F(Apply, 5, 1)                                           \
62  F(GetFunctionDelegate, 1, 1)                             \
63  F(GetConstructorDelegate, 1, 1)                          \
64  F(DeoptimizeFunction, 1, 1)                              \
65  F(ClearFunctionTypeFeedback, 1, 1)                       \
66  F(RunningInSimulator, 0, 1)                              \
67  F(IsConcurrentRecompilationSupported, 0, 1)              \
68  F(OptimizeFunctionOnNextCall, -1, 1)                     \
69  F(NeverOptimizeFunction, 1, 1)                           \
70  F(GetOptimizationStatus, -1, 1)                          \
71  F(GetOptimizationCount, 1, 1)                            \
72  F(UnblockConcurrentRecompilation, 0, 1)                  \
73  F(CompileForOnStackReplacement, 1, 1)                    \
74  F(SetAllocationTimeout, -1 /* 2 || 3 */, 1)              \
75  F(SetNativeFlag, 1, 1)                                   \
76  F(SetInlineBuiltinFlag, 1, 1)                            \
77  F(StoreArrayLiteralElement, 5, 1)                        \
78  F(DebugPrepareStepInIfStepping, 1, 1)                    \
79  F(DebugPushPromise, 1, 1)                                \
80  F(DebugPopPromise, 0, 1)                                 \
81  F(DebugPromiseEvent, 1, 1)                               \
82  F(DebugPromiseRejectEvent, 2, 1)                         \
83  F(DebugAsyncTaskEvent, 1, 1)                             \
84  F(FlattenString, 1, 1)                                   \
85  F(LoadMutableDouble, 2, 1)                               \
86  F(TryMigrateInstance, 1, 1)                              \
87  F(NotifyContextDisposed, 0, 1)                           \
88                                                           \
89  /* Array join support */                                 \
90  F(PushIfAbsent, 2, 1)                                    \
91  F(ArrayConcat, 1, 1)                                     \
92                                                           \
93  /* Conversions */                                        \
94  F(ToBool, 1, 1)                                          \
95  F(Typeof, 1, 1)                                          \
96                                                           \
97  F(Booleanize, 2, 1) /* TODO(turbofan): Only temporary */ \
98                                                           \
99  F(StringToNumber, 1, 1)                                  \
100  F(StringParseInt, 2, 1)                                  \
101  F(StringParseFloat, 1, 1)                                \
102  F(StringToLowerCase, 1, 1)                               \
103  F(StringToUpperCase, 1, 1)                               \
104  F(StringSplit, 3, 1)                                     \
105  F(CharFromCode, 1, 1)                                    \
106  F(URIEscape, 1, 1)                                       \
107  F(URIUnescape, 1, 1)                                     \
108                                                           \
109  F(NumberToInteger, 1, 1)                                 \
110  F(NumberToIntegerMapMinusZero, 1, 1)                     \
111  F(NumberToJSUint32, 1, 1)                                \
112  F(NumberToJSInt32, 1, 1)                                 \
113                                                           \
114  /* Arithmetic operations */                              \
115  F(NumberAdd, 2, 1)                                       \
116  F(NumberSub, 2, 1)                                       \
117  F(NumberMul, 2, 1)                                       \
118  F(NumberDiv, 2, 1)                                       \
119  F(NumberMod, 2, 1)                                       \
120  F(NumberUnaryMinus, 1, 1)                                \
121  F(NumberImul, 2, 1)                                      \
122                                                           \
123  F(StringBuilderConcat, 3, 1)                             \
124  F(StringBuilderJoin, 3, 1)                               \
125  F(SparseJoinWithSeparator, 3, 1)                         \
126                                                           \
127  /* Bit operations */                                     \
128  F(NumberOr, 2, 1)                                        \
129  F(NumberAnd, 2, 1)                                       \
130  F(NumberXor, 2, 1)                                       \
131                                                           \
132  F(NumberShl, 2, 1)                                       \
133  F(NumberShr, 2, 1)                                       \
134  F(NumberSar, 2, 1)                                       \
135                                                           \
136  /* Comparisons */                                        \
137  F(NumberEquals, 2, 1)                                    \
138  F(StringEquals, 2, 1)                                    \
139                                                           \
140  F(NumberCompare, 3, 1)                                   \
141  F(SmiLexicographicCompare, 2, 1)                         \
142                                                           \
143  /* Math */                                               \
144  F(MathAcos, 1, 1)                                        \
145  F(MathAsin, 1, 1)                                        \
146  F(MathAtan, 1, 1)                                        \
147  F(MathFloorRT, 1, 1)                                     \
148  F(MathAtan2, 2, 1)                                       \
149  F(MathExpRT, 1, 1)                                       \
150  F(RoundNumber, 1, 1)                                     \
151  F(MathFround, 1, 1)                                      \
152  F(RemPiO2, 1, 1)                                         \
153                                                           \
154  /* Regular expressions */                                \
155  F(RegExpCompile, 3, 1)                                   \
156  F(RegExpExecMultiple, 4, 1)                              \
157  F(RegExpInitializeObject, 6, 1)                          \
158                                                           \
159  /* JSON */                                               \
160  F(ParseJson, 1, 1)                                       \
161  F(BasicJSONStringify, 1, 1)                              \
162  F(QuoteJSONString, 1, 1)                                 \
163                                                           \
164  /* Strings */                                            \
165  F(StringIndexOf, 3, 1)                                   \
166  F(StringLastIndexOf, 3, 1)                               \
167  F(StringLocaleCompare, 2, 1)                             \
168  F(StringReplaceGlobalRegExpWithString, 4, 1)             \
169  F(StringReplaceOneCharWithString, 3, 1)                  \
170  F(StringMatch, 3, 1)                                     \
171  F(StringTrim, 3, 1)                                      \
172  F(StringToArray, 2, 1)                                   \
173  F(NewStringWrapper, 1, 1)                                \
174  F(NewString, 2, 1)                                       \
175  F(TruncateString, 2, 1)                                  \
176                                                           \
177  /* Numbers */                                            \
178  F(NumberToRadixString, 2, 1)                             \
179  F(NumberToFixed, 2, 1)                                   \
180  F(NumberToExponential, 2, 1)                             \
181  F(NumberToPrecision, 2, 1)                               \
182  F(IsValidSmi, 1, 1)                                      \
183                                                           \
184  /* Classes support */                                    \
185  F(ToMethod, 2, 1)                                        \
186  F(HomeObjectSymbol, 0, 1)                                \
187  F(ThrowNonMethodError, 0, 1)                             \
188  F(ThrowUnsupportedSuperError, 0, 1)                      \
189  F(LoadFromSuper, 3, 1)
190
191
192#define RUNTIME_FUNCTION_LIST_ALWAYS_2(F)                             \
193  /* Reflection */                                                    \
194  F(FunctionSetInstanceClassName, 2, 1)                               \
195  F(FunctionSetLength, 2, 1)                                          \
196  F(FunctionSetPrototype, 2, 1)                                       \
197  F(FunctionGetName, 1, 1)                                            \
198  F(FunctionSetName, 2, 1)                                            \
199  F(FunctionNameShouldPrintAsAnonymous, 1, 1)                         \
200  F(FunctionMarkNameShouldPrintAsAnonymous, 1, 1)                     \
201  F(FunctionIsGenerator, 1, 1)                                        \
202  F(FunctionIsArrow, 1, 1)                                            \
203  F(FunctionIsConciseMethod, 1, 1)                                    \
204  F(FunctionBindArguments, 4, 1)                                      \
205  F(BoundFunctionGetBindings, 1, 1)                                   \
206  F(FunctionRemovePrototype, 1, 1)                                    \
207  F(FunctionGetSourceCode, 1, 1)                                      \
208  F(FunctionGetScript, 1, 1)                                          \
209  F(FunctionGetScriptSourcePosition, 1, 1)                            \
210  F(FunctionGetPositionForOffset, 2, 1)                               \
211  F(FunctionIsAPIFunction, 1, 1)                                      \
212  F(FunctionIsBuiltin, 1, 1)                                          \
213  F(GetScript, 1, 1)                                                  \
214  F(CollectStackTrace, 2, 1)                                          \
215  F(GetV8Version, 0, 1)                                               \
216  F(GeneratorGetFunction, 1, 1)                                       \
217  F(GeneratorGetContext, 1, 1)                                        \
218  F(GeneratorGetReceiver, 1, 1)                                       \
219  F(GeneratorGetContinuation, 1, 1)                                   \
220  F(GeneratorGetSourcePosition, 1, 1)                                 \
221                                                                      \
222  F(SetCode, 2, 1)                                                    \
223                                                                      \
224  F(CreateApiFunction, 2, 1)                                          \
225  F(IsTemplate, 1, 1)                                                 \
226  F(GetTemplateField, 2, 1)                                           \
227  F(DisableAccessChecks, 1, 1)                                        \
228  F(EnableAccessChecks, 1, 1)                                         \
229                                                                      \
230  /* Dates */                                                         \
231  F(DateCurrentTime, 0, 1)                                            \
232  F(DateParseString, 2, 1)                                            \
233  F(DateLocalTimezone, 1, 1)                                          \
234  F(DateToUTC, 1, 1)                                                  \
235  F(DateMakeDay, 2, 1)                                                \
236  F(DateSetValue, 3, 1)                                               \
237  F(DateCacheVersion, 0, 1)                                           \
238                                                                      \
239  /* Globals */                                                       \
240  F(CompileString, 2, 1)                                              \
241                                                                      \
242  /* Eval */                                                          \
243  F(GlobalProxy, 1, 1)                                                \
244  F(IsAttachedGlobal, 1, 1)                                           \
245                                                                      \
246  F(AddNamedProperty, 4, 1)                                           \
247  F(AddPropertyForTemplate, 4, 1)                                     \
248  F(SetProperty, 4, 1)                                                \
249  F(AddElement, 4, 1)                                                 \
250  F(DefineApiAccessorProperty, 5, 1)                                  \
251  F(DefineDataPropertyUnchecked, 4, 1)                                \
252  F(DefineAccessorPropertyUnchecked, 5, 1)                            \
253  F(GetDataProperty, 2, 1)                                            \
254  F(SetHiddenProperty, 3, 1)                                          \
255                                                                      \
256  /* Arrays */                                                        \
257  F(RemoveArrayHoles, 2, 1)                                           \
258  F(GetArrayKeys, 2, 1)                                               \
259  F(MoveArrayContents, 2, 1)                                          \
260  F(EstimateNumberOfElements, 1, 1)                                   \
261  F(NormalizeElements, 1, 1)                                          \
262                                                                      \
263  /* Getters and Setters */                                           \
264  F(LookupAccessor, 3, 1)                                             \
265                                                                      \
266  /* ES5 */                                                           \
267  F(ObjectFreeze, 1, 1)                                               \
268                                                                      \
269  /* Harmony modules */                                               \
270  F(IsJSModule, 1, 1)                                                 \
271                                                                      \
272  /* Harmony symbols */                                               \
273  F(CreateSymbol, 1, 1)                                               \
274  F(CreatePrivateSymbol, 1, 1)                                        \
275  F(CreateGlobalPrivateOwnSymbol, 1, 1)                               \
276  F(CreatePrivateOwnSymbol, 1, 1)                                     \
277  F(NewSymbolWrapper, 1, 1)                                           \
278  F(SymbolDescription, 1, 1)                                          \
279  F(SymbolRegistry, 0, 1)                                             \
280  F(SymbolIsPrivate, 1, 1)                                            \
281                                                                      \
282  /* Harmony proxies */                                               \
283  F(CreateJSProxy, 2, 1)                                              \
284  F(CreateJSFunctionProxy, 4, 1)                                      \
285  F(IsJSProxy, 1, 1)                                                  \
286  F(IsJSFunctionProxy, 1, 1)                                          \
287  F(GetHandler, 1, 1)                                                 \
288  F(GetCallTrap, 1, 1)                                                \
289  F(GetConstructTrap, 1, 1)                                           \
290  F(Fix, 1, 1)                                                        \
291                                                                      \
292  /* Harmony sets */                                                  \
293  F(SetInitialize, 1, 1)                                              \
294  F(SetAdd, 2, 1)                                                     \
295  F(SetHas, 2, 1)                                                     \
296  F(SetDelete, 2, 1)                                                  \
297  F(SetClear, 1, 1)                                                   \
298  F(SetGetSize, 1, 1)                                                 \
299                                                                      \
300  F(SetIteratorInitialize, 3, 1)                                      \
301  F(SetIteratorNext, 2, 1)                                            \
302                                                                      \
303  /* Harmony maps */                                                  \
304  F(MapInitialize, 1, 1)                                              \
305  F(MapGet, 2, 1)                                                     \
306  F(MapHas, 2, 1)                                                     \
307  F(MapDelete, 2, 1)                                                  \
308  F(MapClear, 1, 1)                                                   \
309  F(MapSet, 3, 1)                                                     \
310  F(MapGetSize, 1, 1)                                                 \
311                                                                      \
312  F(MapIteratorInitialize, 3, 1)                                      \
313  F(MapIteratorNext, 2, 1)                                            \
314                                                                      \
315  /* Harmony weak maps and sets */                                    \
316  F(WeakCollectionInitialize, 1, 1)                                   \
317  F(WeakCollectionGet, 2, 1)                                          \
318  F(WeakCollectionHas, 2, 1)                                          \
319  F(WeakCollectionDelete, 2, 1)                                       \
320  F(WeakCollectionSet, 3, 1)                                          \
321                                                                      \
322  F(GetWeakMapEntries, 1, 1)                                          \
323  F(GetWeakSetValues, 1, 1)                                           \
324                                                                      \
325  /* Harmony events */                                                \
326  F(EnqueueMicrotask, 1, 1)                                           \
327  F(RunMicrotasks, 0, 1)                                              \
328                                                                      \
329  /* Harmony observe */                                               \
330  F(IsObserved, 1, 1)                                                 \
331  F(SetIsObserved, 1, 1)                                              \
332  F(GetObservationState, 0, 1)                                        \
333  F(ObservationWeakMapCreate, 0, 1)                                   \
334  F(ObserverObjectAndRecordHaveSameOrigin, 3, 1)                      \
335  F(ObjectWasCreatedInCurrentOrigin, 1, 1)                            \
336  F(GetObjectContextObjectObserve, 1, 1)                              \
337  F(GetObjectContextObjectGetNotifier, 1, 1)                          \
338  F(GetObjectContextNotifierPerformChange, 1, 1)                      \
339                                                                      \
340  /* Harmony typed arrays */                                          \
341  F(ArrayBufferInitialize, 2, 1)                                      \
342  F(ArrayBufferSliceImpl, 3, 1)                                       \
343  F(ArrayBufferIsView, 1, 1)                                          \
344  F(ArrayBufferNeuter, 1, 1)                                          \
345                                                                      \
346  F(TypedArrayInitializeFromArrayLike, 4, 1)                          \
347  F(TypedArrayGetBuffer, 1, 1)                                        \
348  F(TypedArraySetFastCases, 3, 1)                                     \
349                                                                      \
350  F(DataViewGetBuffer, 1, 1)                                          \
351  F(DataViewGetInt8, 3, 1)                                            \
352  F(DataViewGetUint8, 3, 1)                                           \
353  F(DataViewGetInt16, 3, 1)                                           \
354  F(DataViewGetUint16, 3, 1)                                          \
355  F(DataViewGetInt32, 3, 1)                                           \
356  F(DataViewGetUint32, 3, 1)                                          \
357  F(DataViewGetFloat32, 3, 1)                                         \
358  F(DataViewGetFloat64, 3, 1)                                         \
359                                                                      \
360  F(DataViewSetInt8, 4, 1)                                            \
361  F(DataViewSetUint8, 4, 1)                                           \
362  F(DataViewSetInt16, 4, 1)                                           \
363  F(DataViewSetUint16, 4, 1)                                          \
364  F(DataViewSetInt32, 4, 1)                                           \
365  F(DataViewSetUint32, 4, 1)                                          \
366  F(DataViewSetFloat32, 4, 1)                                         \
367  F(DataViewSetFloat64, 4, 1)                                         \
368                                                                      \
369  /* Statements */                                                    \
370  F(NewObjectFromBound, 1, 1)                                         \
371                                                                      \
372  /* Declarations and initialization */                               \
373  F(InitializeVarGlobal, 3, 1)                                        \
374  F(OptimizeObjectForAddingMultipleProperties, 2, 1)                  \
375                                                                      \
376  /* Debugging */                                                     \
377  F(DebugPrint, 1, 1)                                                 \
378  F(GlobalPrint, 1, 1)                                                \
379  F(DebugTrace, 0, 1)                                                 \
380  F(TraceEnter, 0, 1)                                                 \
381  F(TraceExit, 1, 1)                                                  \
382  F(Abort, 1, 1)                                                      \
383  F(AbortJS, 1, 1)                                                    \
384  /* ES5 */                                                           \
385  F(OwnKeys, 1, 1)                                                    \
386                                                                      \
387  /* Message objects */                                               \
388  F(MessageGetStartPosition, 1, 1)                                    \
389  F(MessageGetScript, 1, 1)                                           \
390                                                                      \
391  /* Pseudo functions - handled as macros by parser */                \
392  F(IS_VAR, 1, 1)                                                     \
393                                                                      \
394  /* expose boolean functions from objects-inl.h */                   \
395  F(HasFastSmiElements, 1, 1)                                         \
396  F(HasFastSmiOrObjectElements, 1, 1)                                 \
397  F(HasFastObjectElements, 1, 1)                                      \
398  F(HasFastDoubleElements, 1, 1)                                      \
399  F(HasFastHoleyElements, 1, 1)                                       \
400  F(HasDictionaryElements, 1, 1)                                      \
401  F(HasSloppyArgumentsElements, 1, 1)                                 \
402  F(HasExternalUint8ClampedElements, 1, 1)                            \
403  F(HasExternalArrayElements, 1, 1)                                   \
404  F(HasExternalInt8Elements, 1, 1)                                    \
405  F(HasExternalUint8Elements, 1, 1)                                   \
406  F(HasExternalInt16Elements, 1, 1)                                   \
407  F(HasExternalUint16Elements, 1, 1)                                  \
408  F(HasExternalInt32Elements, 1, 1)                                   \
409  F(HasExternalUint32Elements, 1, 1)                                  \
410  F(HasExternalFloat32Elements, 1, 1)                                 \
411  F(HasExternalFloat64Elements, 1, 1)                                 \
412  F(HasFixedUint8ClampedElements, 1, 1)                               \
413  F(HasFixedInt8Elements, 1, 1)                                       \
414  F(HasFixedUint8Elements, 1, 1)                                      \
415  F(HasFixedInt16Elements, 1, 1)                                      \
416  F(HasFixedUint16Elements, 1, 1)                                     \
417  F(HasFixedInt32Elements, 1, 1)                                      \
418  F(HasFixedUint32Elements, 1, 1)                                     \
419  F(HasFixedFloat32Elements, 1, 1)                                    \
420  F(HasFixedFloat64Elements, 1, 1)                                    \
421  F(HasFastProperties, 1, 1)                                          \
422  F(TransitionElementsKind, 2, 1)                                     \
423  F(HaveSameMap, 2, 1)                                                \
424  F(IsJSGlobalProxy, 1, 1)                                            \
425  F(ForInInit, 2, 2)             /* TODO(turbofan): Only temporary */ \
426  F(ForInNext, 4, 2)             /* TODO(turbofan): Only temporary */ \
427  F(ForInCacheArrayLength, 2, 1) /* TODO(turbofan): Only temporary */
428
429
430#define RUNTIME_FUNCTION_LIST_ALWAYS_3(F)                    \
431  /* String and Regexp */                                    \
432  F(NumberToStringRT, 1, 1)                                  \
433  F(RegExpConstructResult, 3, 1)                             \
434  F(RegExpExecRT, 4, 1)                                      \
435  F(StringAdd, 2, 1)                                         \
436  F(SubString, 3, 1)                                         \
437  F(InternalizeString, 1, 1)                                 \
438  F(StringCompare, 2, 1)                                     \
439  F(StringCharCodeAtRT, 2, 1)                                \
440  F(GetFromCache, 2, 1)                                      \
441                                                             \
442  /* Compilation */                                          \
443  F(CompileLazy, 1, 1)                                       \
444  F(CompileOptimized, 2, 1)                                  \
445  F(TryInstallOptimizedCode, 1, 1)                           \
446  F(NotifyDeoptimized, 1, 1)                                 \
447  F(NotifyStubFailure, 0, 1)                                 \
448                                                             \
449  /* Utilities */                                            \
450  F(AllocateInNewSpace, 1, 1)                                \
451  F(AllocateInTargetSpace, 2, 1)                             \
452  F(AllocateHeapNumber, 0, 1)                                \
453  F(NumberToSmi, 1, 1)                                       \
454  F(NumberToStringSkipCache, 1, 1)                           \
455                                                             \
456  F(NewArguments, 1, 1) /* TODO(turbofan): Only temporary */ \
457  F(NewSloppyArguments, 3, 1)                                \
458  F(NewStrictArguments, 3, 1)                                \
459                                                             \
460  /* Harmony generators */                                   \
461  F(CreateJSGeneratorObject, 0, 1)                           \
462  F(SuspendJSGeneratorObject, 1, 1)                          \
463  F(ResumeJSGeneratorObject, 3, 1)                           \
464  F(ThrowGeneratorStateError, 1, 1)                          \
465                                                             \
466  /* Arrays */                                               \
467  F(ArrayConstructor, -1, 1)                                 \
468  F(InternalArrayConstructor, -1, 1)                         \
469                                                             \
470  /* Literals */                                             \
471  F(MaterializeRegExpLiteral, 4, 1)                          \
472  F(CreateObjectLiteral, 4, 1)                               \
473  F(CreateArrayLiteral, 4, 1)                                \
474  F(CreateArrayLiteralStubBailout, 3, 1)                     \
475                                                             \
476  /* Statements */                                           \
477  F(NewClosure, 3, 1)                                        \
478  F(NewClosureFromStubFailure, 1, 1)                         \
479  F(NewObject, 1, 1)                                         \
480  F(NewObjectWithAllocationSite, 2, 1)                       \
481  F(FinalizeInstanceSize, 1, 1)                              \
482  F(Throw, 1, 1)                                             \
483  F(ReThrow, 1, 1)                                           \
484  F(ThrowReferenceError, 1, 1)                               \
485  F(ThrowNotDateError, 0, 1)                                 \
486  F(StackGuard, 0, 1)                                        \
487  F(Interrupt, 0, 1)                                         \
488  F(PromoteScheduledException, 0, 1)                         \
489                                                             \
490  /* Contexts */                                             \
491  F(NewGlobalContext, 2, 1)                                  \
492  F(NewFunctionContext, 1, 1)                                \
493  F(PushWithContext, 2, 1)                                   \
494  F(PushCatchContext, 3, 1)                                  \
495  F(PushBlockContext, 2, 1)                                  \
496  F(PushModuleContext, 2, 1)                                 \
497  F(DeleteLookupSlot, 2, 1)                                  \
498  F(LoadLookupSlot, 2, 2)                                    \
499  F(LoadLookupSlotNoReferenceError, 2, 2)                    \
500  F(StoreLookupSlot, 4, 1)                                   \
501                                                             \
502  /* Declarations and initialization */                      \
503  F(DeclareGlobals, 3, 1)                                    \
504  F(DeclareModules, 1, 1)                                    \
505  F(DeclareLookupSlot, 4, 1)                                 \
506  F(InitializeConstGlobal, 2, 1)                             \
507  F(InitializeLegacyConstLookupSlot, 3, 1)                   \
508                                                             \
509  /* Eval */                                                 \
510  F(ResolvePossiblyDirectEval, 6, 2)                         \
511                                                             \
512  /* Maths */                                                \
513  F(MathPowSlow, 2, 1)                                       \
514  F(MathPowRT, 2, 1)
515
516
517#define RUNTIME_FUNCTION_LIST_DEBUGGER(F) \
518  /* Debugger support*/ \
519  F(DebugBreak, 0, 1) \
520  F(SetDebugEventListener, 2, 1) \
521  F(Break, 0, 1) \
522  F(DebugGetPropertyDetails, 2, 1) \
523  F(DebugGetProperty, 2, 1) \
524  F(DebugPropertyTypeFromDetails, 1, 1) \
525  F(DebugPropertyAttributesFromDetails, 1, 1) \
526  F(DebugPropertyIndexFromDetails, 1, 1) \
527  F(DebugNamedInterceptorPropertyValue, 2, 1) \
528  F(DebugIndexedInterceptorElementValue, 2, 1) \
529  F(CheckExecutionState, 1, 1) \
530  F(GetFrameCount, 1, 1) \
531  F(GetFrameDetails, 2, 1) \
532  F(GetScopeCount, 2, 1) \
533  F(GetStepInPositions, 2, 1) \
534  F(GetScopeDetails, 4, 1) \
535  F(GetAllScopesDetails, 4, 1) \
536  F(GetFunctionScopeCount, 1, 1) \
537  F(GetFunctionScopeDetails, 2, 1) \
538  F(SetScopeVariableValue, 6, 1) \
539  F(DebugPrintScopes, 0, 1) \
540  F(GetThreadCount, 1, 1) \
541  F(GetThreadDetails, 2, 1) \
542  F(SetDisableBreak, 1, 1) \
543  F(GetBreakLocations, 2, 1) \
544  F(SetFunctionBreakPoint, 3, 1) \
545  F(SetScriptBreakPoint, 4, 1) \
546  F(ClearBreakPoint, 1, 1) \
547  F(ChangeBreakOnException, 2, 1) \
548  F(IsBreakOnException, 1, 1) \
549  F(PrepareStep, 4, 1) \
550  F(ClearStepping, 0, 1) \
551  F(DebugEvaluate, 6, 1) \
552  F(DebugEvaluateGlobal, 4, 1) \
553  F(DebugGetLoadedScripts, 0, 1) \
554  F(DebugReferencedBy, 3, 1) \
555  F(DebugConstructedBy, 2, 1) \
556  F(DebugGetPrototype, 1, 1) \
557  F(DebugSetScriptSource, 2, 1) \
558  F(DebugCallbackSupportsStepping, 1, 1) \
559  F(SystemBreak, 0, 1) \
560  F(DebugDisassembleFunction, 1, 1) \
561  F(DebugDisassembleConstructor, 1, 1) \
562  F(FunctionGetInferredName, 1, 1) \
563  F(LiveEditFindSharedFunctionInfosForScript, 1, 1) \
564  F(LiveEditGatherCompileInfo, 2, 1) \
565  F(LiveEditReplaceScript, 3, 1) \
566  F(LiveEditReplaceFunctionCode, 2, 1) \
567  F(LiveEditFunctionSourceUpdated, 1, 1) \
568  F(LiveEditFunctionSetScript, 2, 1) \
569  F(LiveEditReplaceRefToNestedFunction, 3, 1) \
570  F(LiveEditPatchFunctionPositions, 2, 1) \
571  F(LiveEditCheckAndDropActivations, 2, 1) \
572  F(LiveEditCompareStrings, 2, 1) \
573  F(LiveEditRestartFrame, 2, 1) \
574  F(GetFunctionCodePositionFromSource, 2, 1) \
575  F(ExecuteInDebugContext, 2, 1) \
576  \
577  F(SetFlags, 1, 1) \
578  F(CollectGarbage, 1, 1) \
579  F(GetHeapUsage, 0, 1) \
580
581
582#ifdef V8_I18N_SUPPORT
583#define RUNTIME_FUNCTION_LIST_I18N_SUPPORT(F) \
584  /* i18n support */ \
585  /* Standalone, helper methods. */ \
586  F(CanonicalizeLanguageTag, 1, 1) \
587  F(AvailableLocalesOf, 1, 1) \
588  F(GetDefaultICULocale, 0, 1) \
589  F(GetLanguageTagVariants, 1, 1) \
590  F(IsInitializedIntlObject, 1, 1) \
591  F(IsInitializedIntlObjectOfType, 2, 1) \
592  F(MarkAsInitializedIntlObjectOfType, 3, 1) \
593  F(GetImplFromInitializedIntlObject, 1, 1) \
594  \
595  /* Date format and parse. */ \
596  F(CreateDateTimeFormat, 3, 1) \
597  F(InternalDateFormat, 2, 1) \
598  F(InternalDateParse, 2, 1) \
599  \
600  /* Number format and parse. */ \
601  F(CreateNumberFormat, 3, 1) \
602  F(InternalNumberFormat, 2, 1) \
603  F(InternalNumberParse, 2, 1) \
604  \
605  /* Collator. */ \
606  F(CreateCollator, 3, 1) \
607  F(InternalCompare, 3, 1) \
608  \
609  /* String.prototype.normalize. */ \
610  F(StringNormalize, 2, 1) \
611  \
612  /* Break iterator. */ \
613  F(CreateBreakIterator, 3, 1) \
614  F(BreakIteratorAdoptText, 2, 1) \
615  F(BreakIteratorFirst, 1, 1) \
616  F(BreakIteratorNext, 1, 1) \
617  F(BreakIteratorCurrent, 1, 1) \
618  F(BreakIteratorBreakType, 1, 1) \
619
620#else
621#define RUNTIME_FUNCTION_LIST_I18N_SUPPORT(F)
622#endif
623
624
625#ifdef DEBUG
626#define RUNTIME_FUNCTION_LIST_DEBUG(F) \
627  /* Testing */ \
628  F(ListNatives, 0, 1)
629#else
630#define RUNTIME_FUNCTION_LIST_DEBUG(F)
631#endif
632
633// ----------------------------------------------------------------------------
634// RUNTIME_FUNCTION_LIST defines all runtime functions accessed
635// either directly by id (via the code generator), or indirectly
636// via a native call by name (from within JS code).
637// Entries have the form F(name, number of arguments, number of return values).
638
639#define RUNTIME_FUNCTION_LIST(F) \
640  RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
641  RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
642  RUNTIME_FUNCTION_LIST_ALWAYS_3(F) \
643  RUNTIME_FUNCTION_LIST_DEBUG(F) \
644  RUNTIME_FUNCTION_LIST_DEBUGGER(F) \
645  RUNTIME_FUNCTION_LIST_I18N_SUPPORT(F)
646
647// ----------------------------------------------------------------------------
648// INLINE_FUNCTION_LIST defines all inlined functions accessed
649// with a native call of the form %_name from within JS code.
650// Entries have the form F(name, number of arguments, number of return values).
651#define INLINE_FUNCTION_LIST(F)                             \
652  F(IsSmi, 1, 1)                                            \
653  F(IsNonNegativeSmi, 1, 1)                                 \
654  F(IsArray, 1, 1)                                          \
655  F(IsRegExp, 1, 1)                                         \
656  F(IsConstructCall, 0, 1)                                  \
657  F(CallFunction, -1 /* receiver + n args + function */, 1) \
658  F(ArgumentsLength, 0, 1)                                  \
659  F(Arguments, 1, 1)                                        \
660  F(ValueOf, 1, 1)                                          \
661  F(SetValueOf, 2, 1)                                       \
662  F(DateField, 2 /* date object, field index */, 1)         \
663  F(StringCharFromCode, 1, 1)                               \
664  F(StringCharAt, 2, 1)                                     \
665  F(OneByteSeqStringSetChar, 3, 1)                          \
666  F(TwoByteSeqStringSetChar, 3, 1)                          \
667  F(ObjectEquals, 2, 1)                                     \
668  F(IsObject, 1, 1)                                         \
669  F(IsFunction, 1, 1)                                       \
670  F(IsUndetectableObject, 1, 1)                             \
671  F(IsSpecObject, 1, 1)                                     \
672  F(IsStringWrapperSafeForDefaultValueOf, 1, 1)             \
673  F(MathPow, 2, 1)                                          \
674  F(IsMinusZero, 1, 1)                                      \
675  F(HasCachedArrayIndex, 1, 1)                              \
676  F(GetCachedArrayIndex, 1, 1)                              \
677  F(FastOneByteArrayJoin, 2, 1)                             \
678  F(GeneratorNext, 2, 1)                                    \
679  F(GeneratorThrow, 2, 1)                                   \
680  F(DebugBreakInOptimizedCode, 0, 1)                        \
681  F(ClassOf, 1, 1)                                          \
682  F(StringCharCodeAt, 2, 1)                                 \
683  F(StringAdd, 2, 1)                                        \
684  F(SubString, 3, 1)                                        \
685  F(StringCompare, 2, 1)                                    \
686  F(RegExpExec, 4, 1)                                       \
687  F(RegExpConstructResult, 3, 1)                            \
688  F(GetFromCache, 2, 1)                                     \
689  F(NumberToString, 1, 1)                                   \
690  F(DebugIsActive, 0, 1)
691
692
693// ----------------------------------------------------------------------------
694// INLINE_OPTIMIZED_FUNCTION_LIST defines all inlined functions accessed
695// with a native call of the form %_name from within JS code that also have
696// a corresponding runtime function, that is called from non-optimized code.
697// For the benefit of (fuzz) tests, the runtime version can also be called
698// directly as %name (i.e. without the leading underscore).
699// Entries have the form F(name, number of arguments, number of return values).
700#define INLINE_OPTIMIZED_FUNCTION_LIST(F) \
701  /* Typed Arrays */                                                         \
702  F(TypedArrayInitialize, 5, 1)                                              \
703  F(DataViewInitialize, 4, 1)                                                \
704  F(MaxSmi, 0, 1)                                                            \
705  F(TypedArrayMaxSizeInHeap, 0, 1)                                           \
706  F(ArrayBufferViewGetByteLength, 1, 1)                                      \
707  F(ArrayBufferViewGetByteOffset, 1, 1)                                      \
708  F(TypedArrayGetLength, 1, 1)                                               \
709  /* ArrayBuffer */                                                          \
710  F(ArrayBufferGetByteLength, 1, 1)                                          \
711  /* Maths */                                                                \
712  F(ConstructDouble, 2, 1)                                                   \
713  F(DoubleHi, 1, 1)                                                          \
714  F(DoubleLo, 1, 1)                                                          \
715  F(MathSqrtRT, 1, 1)                                                        \
716  F(MathLogRT, 1, 1)
717
718
719//---------------------------------------------------------------------------
720// Runtime provides access to all C++ runtime functions.
721
722class RuntimeState {
723 public:
724  StaticResource<ConsStringIteratorOp>* string_iterator() {
725    return &string_iterator_;
726  }
727  unibrow::Mapping<unibrow::ToUppercase, 128>* to_upper_mapping() {
728    return &to_upper_mapping_;
729  }
730  unibrow::Mapping<unibrow::ToLowercase, 128>* to_lower_mapping() {
731    return &to_lower_mapping_;
732  }
733  ConsStringIteratorOp* string_iterator_compare_x() {
734    return &string_iterator_compare_x_;
735  }
736  ConsStringIteratorOp* string_iterator_compare_y() {
737    return &string_iterator_compare_y_;
738  }
739  ConsStringIteratorOp* string_locale_compare_it1() {
740    return &string_locale_compare_it1_;
741  }
742  ConsStringIteratorOp* string_locale_compare_it2() {
743    return &string_locale_compare_it2_;
744  }
745
746 private:
747  RuntimeState() {}
748  // Non-reentrant string buffer for efficient general use in the runtime.
749  StaticResource<ConsStringIteratorOp> string_iterator_;
750  unibrow::Mapping<unibrow::ToUppercase, 128> to_upper_mapping_;
751  unibrow::Mapping<unibrow::ToLowercase, 128> to_lower_mapping_;
752  ConsStringIteratorOp string_iterator_compare_x_;
753  ConsStringIteratorOp string_iterator_compare_y_;
754  ConsStringIteratorOp string_locale_compare_it1_;
755  ConsStringIteratorOp string_locale_compare_it2_;
756
757  friend class Isolate;
758  friend class Runtime;
759
760  DISALLOW_COPY_AND_ASSIGN(RuntimeState);
761};
762
763
764class Runtime : public AllStatic {
765 public:
766  enum FunctionId {
767#define F(name, nargs, ressize) k##name,
768    RUNTIME_FUNCTION_LIST(F)
769    INLINE_OPTIMIZED_FUNCTION_LIST(F)
770#undef F
771#define F(name, nargs, ressize) kInline##name,
772    INLINE_FUNCTION_LIST(F)
773#undef F
774#define F(name, nargs, ressize) kInlineOptimized##name,
775    INLINE_OPTIMIZED_FUNCTION_LIST(F)
776#undef F
777    kNumFunctions,
778    kFirstInlineFunction = kInlineIsSmi
779  };
780
781  enum IntrinsicType {
782    RUNTIME,
783    INLINE,
784    INLINE_OPTIMIZED
785  };
786
787  // Intrinsic function descriptor.
788  struct Function {
789    FunctionId function_id;
790    IntrinsicType intrinsic_type;
791    // The JS name of the function.
792    const char* name;
793
794    // The C++ (native) entry point.  NULL if the function is inlined.
795    byte* entry;
796
797    // The number of arguments expected. nargs is -1 if the function takes
798    // a variable number of arguments.
799    int nargs;
800    // Size of result.  Most functions return a single pointer, size 1.
801    int result_size;
802  };
803
804  static const int kNotFound = -1;
805
806  // Add internalized strings for all the intrinsic function names to a
807  // StringDictionary.
808  static void InitializeIntrinsicFunctionNames(Isolate* isolate,
809                                               Handle<NameDictionary> dict);
810
811  // Get the intrinsic function with the given name, which must be internalized.
812  static const Function* FunctionForName(Handle<String> name);
813
814  // Get the intrinsic function with the given FunctionId.
815  static const Function* FunctionForId(FunctionId id);
816
817  // Get the intrinsic function with the given function entry address.
818  static const Function* FunctionForEntry(Address ref);
819
820  // General-purpose helper functions for runtime system.
821  static int StringMatch(Isolate* isolate,
822                         Handle<String> sub,
823                         Handle<String> pat,
824                         int index);
825
826  static bool IsUpperCaseChar(RuntimeState* runtime_state, uint16_t ch);
827
828  // TODO(1240886): Some of the following methods are *not* handle safe, but
829  // accept handle arguments. This seems fragile.
830
831  // Support getting the characters in a string using [] notation as
832  // in Firefox/SpiderMonkey, Safari and Opera.
833  MUST_USE_RESULT static MaybeHandle<Object> GetElementOrCharAt(
834      Isolate* isolate,
835      Handle<Object> object,
836      uint32_t index);
837
838  MUST_USE_RESULT static MaybeHandle<Object> SetObjectProperty(
839      Isolate* isolate, Handle<Object> object, Handle<Object> key,
840      Handle<Object> value, StrictMode strict_mode);
841
842  MUST_USE_RESULT static MaybeHandle<Object> DefineObjectProperty(
843      Handle<JSObject> object, Handle<Object> key, Handle<Object> value,
844      PropertyAttributes attr);
845
846  MUST_USE_RESULT static MaybeHandle<Object> DeleteObjectProperty(
847      Isolate* isolate,
848      Handle<JSReceiver> object,
849      Handle<Object> key,
850      JSReceiver::DeleteMode mode);
851
852  MUST_USE_RESULT static MaybeHandle<Object> HasObjectProperty(
853      Isolate* isolate,
854      Handle<JSReceiver> object,
855      Handle<Object> key);
856
857  MUST_USE_RESULT static MaybeHandle<Object> GetObjectProperty(
858      Isolate* isolate,
859      Handle<Object> object,
860      Handle<Object> key);
861
862  static void SetupArrayBuffer(Isolate* isolate,
863                               Handle<JSArrayBuffer> array_buffer,
864                               bool is_external,
865                               void* data,
866                               size_t allocated_length);
867
868  static bool SetupArrayBufferAllocatingData(
869      Isolate* isolate,
870      Handle<JSArrayBuffer> array_buffer,
871      size_t allocated_length,
872      bool initialize = true);
873
874  static void NeuterArrayBuffer(Handle<JSArrayBuffer> array_buffer);
875
876  static void FreeArrayBuffer(
877      Isolate* isolate,
878      JSArrayBuffer* phantom_array_buffer);
879
880  enum TypedArrayId {
881    // arrayIds below should be synchromized with typedarray.js natives.
882    ARRAY_ID_UINT8 = 1,
883    ARRAY_ID_INT8 = 2,
884    ARRAY_ID_UINT16 = 3,
885    ARRAY_ID_INT16 = 4,
886    ARRAY_ID_UINT32 = 5,
887    ARRAY_ID_INT32 = 6,
888    ARRAY_ID_FLOAT32 = 7,
889    ARRAY_ID_FLOAT64 = 8,
890    ARRAY_ID_UINT8_CLAMPED = 9,
891
892    ARRAY_ID_FIRST = ARRAY_ID_UINT8,
893    ARRAY_ID_LAST = ARRAY_ID_UINT8_CLAMPED
894  };
895
896  static void ArrayIdToTypeAndSize(int array_id,
897      ExternalArrayType *type,
898      ElementsKind* external_elements_kind,
899      ElementsKind* fixed_elements_kind,
900      size_t *element_size);
901
902  // Used in runtime.cc and hydrogen's VisitArrayLiteral.
903  MUST_USE_RESULT static MaybeHandle<Object> CreateArrayLiteralBoilerplate(
904      Isolate* isolate,
905      Handle<FixedArray> literals,
906      Handle<FixedArray> elements);
907};
908
909
910//---------------------------------------------------------------------------
911// Constants used by interface to runtime functions.
912
913class AllocateDoubleAlignFlag:  public BitField<bool,            0, 1> {};
914class AllocateTargetSpace:      public BitField<AllocationSpace, 1, 3> {};
915
916class DeclareGlobalsEvalFlag:   public BitField<bool,       0, 1> {};
917class DeclareGlobalsNativeFlag: public BitField<bool,       1, 1> {};
918class DeclareGlobalsStrictMode: public BitField<StrictMode, 2, 1> {};
919
920} }  // namespace v8::internal
921
922#endif  // V8_RUNTIME_H_
923