• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_RUNTIME_H_
6 #define V8_RUNTIME_RUNTIME_H_
7 
8 #include <memory>
9 
10 #include "src/allocation.h"
11 #include "src/base/platform/time.h"
12 #include "src/elements-kind.h"
13 #include "src/globals.h"
14 #include "src/unicode.h"
15 #include "src/zone/zone.h"
16 
17 namespace v8 {
18 namespace internal {
19 
20 // * Each intrinsic is consistently exposed in JavaScript via 2 names:
21 //    * %#name, which is always a runtime call.
22 //    * %_#name, which can be inlined or just a runtime call, the compiler in
23 //      question decides.
24 //
25 // * IntrinsicTypes are Runtime::RUNTIME and Runtime::INLINE, respectively.
26 //
27 // * IDs are Runtime::k##name and Runtime::kInline##name, respectively.
28 //
29 // * All intrinsics have a C++ implementation Runtime_##name.
30 //
31 // * Each compiler has an explicit list of intrisics it supports, falling back
32 //   to a simple runtime call if necessary.
33 
34 
35 // Entries have the form F(name, number of arguments, number of values):
36 // A variable number of arguments is specified by a -1, additional restrictions
37 // are specified by inline comments
38 
39 #define FOR_EACH_INTRINSIC_ARRAY(F)  \
40   F(FinishArrayPrototypeSetup, 1, 1) \
41   F(SpecialArrayFunctions, 0, 1)     \
42   F(TransitionElementsKind, 2, 1)    \
43   F(RemoveArrayHoles, 2, 1)          \
44   F(MoveArrayContents, 2, 1)         \
45   F(EstimateNumberOfElements, 1, 1)  \
46   F(GetArrayKeys, 2, 1)              \
47   F(NewArray, -1 /* >= 3 */, 1)      \
48   F(FunctionBind, -1, 1)             \
49   F(NormalizeElements, 1, 1)         \
50   F(GrowArrayElements, 2, 1)         \
51   F(HasComplexElements, 1, 1)        \
52   F(IsArray, 1, 1)                   \
53   F(ArrayIsArray, 1, 1)              \
54   F(FixedArrayGet, 2, 1)             \
55   F(FixedArraySet, 3, 1)             \
56   F(ArraySpeciesConstructor, 1, 1)   \
57   F(ArrayIncludes_Slow, 3, 1)        \
58   F(ArrayIndexOf, 3, 1)              \
59   F(SpreadIterablePrepare, 1, 1)     \
60   F(SpreadIterableFixed, 1, 1)
61 
62 #define FOR_EACH_INTRINSIC_ATOMICS(F)           \
63   F(ThrowNotIntegerSharedTypedArrayError, 1, 1) \
64   F(ThrowNotInt32SharedTypedArrayError, 1, 1)   \
65   F(ThrowInvalidAtomicAccessIndexError, 0, 1)   \
66   F(AtomicsCompareExchange, 4, 1)               \
67   F(AtomicsAdd, 3, 1)                           \
68   F(AtomicsSub, 3, 1)                           \
69   F(AtomicsAnd, 3, 1)                           \
70   F(AtomicsOr, 3, 1)                            \
71   F(AtomicsXor, 3, 1)                           \
72   F(AtomicsExchange, 3, 1)                      \
73   F(AtomicsIsLockFree, 1, 1)                    \
74   F(AtomicsWait, 4, 1)                          \
75   F(AtomicsWake, 3, 1)                          \
76   F(AtomicsNumWaitersForTesting, 2, 1)          \
77   F(SetAllowAtomicsWait, 1, 1)
78 
79 #define FOR_EACH_INTRINSIC_CLASSES(F)        \
80   F(ThrowUnsupportedSuperError, 0, 1)        \
81   F(ThrowConstructorNonCallableError, 1, 1)  \
82   F(ThrowStaticPrototypeError, 0, 1)         \
83   F(ThrowSuperAlreadyCalledError, 0, 1)      \
84   F(ThrowNotSuperConstructor, 2, 1)          \
85   F(HomeObjectSymbol, 0, 1)                  \
86   F(DefineClass, 4, 1)                       \
87   F(InstallClassNameAccessor, 1, 1)          \
88   F(InstallClassNameAccessorWithCheck, 1, 1) \
89   F(LoadFromSuper, 3, 1)                     \
90   F(LoadKeyedFromSuper, 3, 1)                \
91   F(StoreToSuper_Strict, 4, 1)               \
92   F(StoreToSuper_Sloppy, 4, 1)               \
93   F(StoreKeyedToSuper_Strict, 4, 1)          \
94   F(StoreKeyedToSuper_Sloppy, 4, 1)          \
95   F(GetSuperConstructor, 1, 1)
96 
97 #define FOR_EACH_INTRINSIC_COLLECTIONS(F) \
98   F(StringGetRawHashField, 1, 1)          \
99   F(TheHole, 0, 1)                        \
100   F(JSCollectionGetTable, 1, 1)           \
101   F(GenericHash, 1, 1)                    \
102   F(SetInitialize, 1, 1)                  \
103   F(SetGrow, 1, 1)                        \
104   F(SetShrink, 1, 1)                      \
105   F(SetClear, 1, 1)                       \
106   F(SetIteratorInitialize, 3, 1)          \
107   F(SetIteratorClone, 1, 1)               \
108   F(SetIteratorNext, 2, 1)                \
109   F(SetIteratorDetails, 1, 1)             \
110   F(MapInitialize, 1, 1)                  \
111   F(MapShrink, 1, 1)                      \
112   F(MapClear, 1, 1)                       \
113   F(MapGrow, 1, 1)                        \
114   F(MapIteratorInitialize, 3, 1)          \
115   F(MapIteratorClone, 1, 1)               \
116   F(MapIteratorDetails, 1, 1)             \
117   F(GetWeakMapEntries, 2, 1)              \
118   F(MapIteratorNext, 2, 1)                \
119   F(WeakCollectionInitialize, 1, 1)       \
120   F(WeakCollectionGet, 3, 1)              \
121   F(WeakCollectionHas, 3, 1)              \
122   F(WeakCollectionDelete, 3, 1)           \
123   F(WeakCollectionSet, 4, 1)              \
124   F(GetWeakSetValues, 2, 1)
125 
126 #define FOR_EACH_INTRINSIC_COMPILER(F)    \
127   F(CompileLazy, 1, 1)                    \
128   F(CompileBaseline, 1, 1)                \
129   F(CompileOptimized_Concurrent, 1, 1)    \
130   F(CompileOptimized_NotConcurrent, 1, 1) \
131   F(NotifyStubFailure, 0, 1)              \
132   F(NotifyDeoptimized, 1, 1)              \
133   F(CompileForOnStackReplacement, 1, 1)   \
134   F(TryInstallOptimizedCode, 1, 1)        \
135   F(ResolvePossiblyDirectEval, 6, 1)      \
136   F(InstantiateAsmJs, 4, 1)
137 
138 #define FOR_EACH_INTRINSIC_DATE(F) \
139   F(IsDate, 1, 1)                  \
140   F(DateCurrentTime, 0, 1)         \
141   F(ThrowNotDateError, 0, 1)
142 
143 #define FOR_EACH_INTRINSIC_DEBUG(F)             \
144   F(HandleDebuggerStatement, 0, 1)              \
145   F(DebugBreak, 1, 1)                           \
146   F(DebugBreakOnBytecode, 1, 1)                 \
147   F(SetDebugEventListener, 2, 1)                \
148   F(ScheduleBreak, 0, 1)                        \
149   F(DebugGetInternalProperties, 1, 1)           \
150   F(DebugGetPropertyDetails, 2, 1)              \
151   F(DebugGetProperty, 2, 1)                     \
152   F(DebugPropertyKindFromDetails, 1, 1)         \
153   F(DebugPropertyAttributesFromDetails, 1, 1)   \
154   F(CheckExecutionState, 1, 1)                  \
155   F(GetFrameCount, 1, 1)                        \
156   F(GetFrameDetails, 2, 1)                      \
157   F(GetScopeCount, 2, 1)                        \
158   F(GetScopeDetails, 4, 1)                      \
159   F(GetAllScopesDetails, 4, 1)                  \
160   F(GetFunctionScopeCount, 1, 1)                \
161   F(GetFunctionScopeDetails, 2, 1)              \
162   F(GetGeneratorScopeCount, 1, 1)               \
163   F(GetGeneratorScopeDetails, 2, 1)             \
164   F(SetScopeVariableValue, 6, 1)                \
165   F(DebugPrintScopes, 0, 1)                     \
166   F(SetBreakPointsActive, 1, 1)                 \
167   F(GetBreakLocations, 2, 1)                    \
168   F(SetFunctionBreakPoint, 3, 1)                \
169   F(SetScriptBreakPoint, 4, 1)                  \
170   F(ClearBreakPoint, 1, 1)                      \
171   F(ChangeBreakOnException, 2, 1)               \
172   F(IsBreakOnException, 1, 1)                   \
173   F(PrepareStep, 2, 1)                          \
174   F(ClearStepping, 0, 1)                        \
175   F(DebugEvaluate, 5, 1)                        \
176   F(DebugEvaluateGlobal, 2, 1)                  \
177   F(DebugGetLoadedScripts, 0, 1)                \
178   F(DebugReferencedBy, 3, 1)                    \
179   F(DebugConstructedBy, 2, 1)                   \
180   F(DebugGetPrototype, 1, 1)                    \
181   F(DebugSetScriptSource, 2, 1)                 \
182   F(FunctionGetInferredName, 1, 1)              \
183   F(FunctionGetDebugName, 1, 1)                 \
184   F(GetDebugContext, 0, 1)                      \
185   F(CollectGarbage, 1, 1)                       \
186   F(GetHeapUsage, 0, 1)                         \
187   F(GetScript, 1, 1)                            \
188   F(ScriptLineCount, 1, 1)                      \
189   F(ScriptLineStartPosition, 2, 1)              \
190   F(ScriptLineEndPosition, 2, 1)                \
191   F(ScriptLocationFromLine, 4, 1)               \
192   F(ScriptLocationFromLine2, 4, 1)              \
193   F(ScriptPositionInfo, 3, 1)                   \
194   F(ScriptPositionInfo2, 3, 1)                  \
195   F(ScriptSourceLine, 2, 1)                     \
196   F(DebugOnFunctionCall, 1, 1)                  \
197   F(DebugPrepareStepInSuspendedGenerator, 0, 1) \
198   F(DebugRecordGenerator, 1, 1)                 \
199   F(DebugPushPromise, 1, 1)                     \
200   F(DebugPopPromise, 0, 1)                      \
201   F(DebugPromiseReject, 2, 1)                   \
202   F(DebugAsyncEventEnqueueRecurring, 2, 1)      \
203   F(DebugAsyncFunctionPromiseCreated, 1, 1)     \
204   F(DebugIsActive, 0, 1)                        \
205   F(DebugBreakInOptimizedCode, 0, 1)            \
206   F(DebugCollectCoverage, 0, 1)                 \
207   F(DebugTogglePreciseCoverage, 1, 1)
208 
209 #define FOR_EACH_INTRINSIC_ERROR(F) F(ErrorToString, 1, 1)
210 
211 #define FOR_EACH_INTRINSIC_FORIN(F) \
212   F(ForInEnumerate, 1, 1)           \
213   F(ForInFilter, 2, 1)              \
214   F(ForInHasProperty, 2, 1)
215 
216 #define FOR_EACH_INTRINSIC_INTERPRETER(F) \
217   F(InterpreterNewClosure, 4, 1)          \
218   F(InterpreterTraceBytecodeEntry, 3, 1)  \
219   F(InterpreterTraceBytecodeExit, 3, 1)   \
220   F(InterpreterAdvanceBytecodeOffset, 2, 1)
221 
222 #define FOR_EACH_INTRINSIC_FUNCTION(F)     \
223   F(FunctionGetName, 1, 1)                 \
224   F(FunctionSetName, 2, 1)                 \
225   F(FunctionRemovePrototype, 1, 1)         \
226   F(FunctionGetScript, 1, 1)               \
227   F(FunctionGetScriptId, 1, 1)             \
228   F(FunctionGetSourceCode, 1, 1)           \
229   F(FunctionGetScriptSourcePosition, 1, 1) \
230   F(FunctionGetContextData, 1, 1)          \
231   F(FunctionSetInstanceClassName, 2, 1)    \
232   F(FunctionSetLength, 2, 1)               \
233   F(FunctionSetPrototype, 2, 1)            \
234   F(FunctionIsAPIFunction, 1, 1)           \
235   F(SetCode, 2, 1)                         \
236   F(SetNativeFlag, 1, 1)                   \
237   F(IsConstructor, 1, 1)                   \
238   F(SetForceInlineFlag, 1, 1)              \
239   F(Call, -1 /* >= 2 */, 1)                \
240   F(ConvertReceiver, 1, 1)                 \
241   F(IsFunction, 1, 1)                      \
242   F(FunctionToString, 1, 1)
243 
244 #define FOR_EACH_INTRINSIC_GENERATOR(F) \
245   F(CreateJSGeneratorObject, 2, 1)      \
246   F(GeneratorClose, 1, 1)               \
247   F(GeneratorGetFunction, 1, 1)         \
248   F(GeneratorGetReceiver, 1, 1)         \
249   F(GeneratorGetContext, 1, 1)          \
250   F(GeneratorGetInputOrDebugPos, 1, 1)  \
251   F(GeneratorGetContinuation, 1, 1)     \
252   F(GeneratorGetSourcePosition, 1, 1)   \
253   F(GeneratorGetResumeMode, 1, 1)
254 
255 #ifdef V8_I18N_SUPPORT
256 #define FOR_EACH_INTRINSIC_I18N(F)           \
257   F(CanonicalizeLanguageTag, 1, 1)           \
258   F(AvailableLocalesOf, 1, 1)                \
259   F(GetDefaultICULocale, 0, 1)               \
260   F(GetLanguageTagVariants, 1, 1)            \
261   F(IsInitializedIntlObject, 1, 1)           \
262   F(IsInitializedIntlObjectOfType, 2, 1)     \
263   F(MarkAsInitializedIntlObjectOfType, 2, 1) \
264   F(CreateDateTimeFormat, 3, 1)              \
265   F(InternalDateFormat, 2, 1)                \
266   F(InternalDateFormatToParts, 2, 1)         \
267   F(CreateNumberFormat, 3, 1)                \
268   F(InternalNumberFormat, 2, 1)              \
269   F(CreateCollator, 3, 1)                    \
270   F(InternalCompare, 3, 1)                   \
271   F(StringNormalize, 2, 1)                   \
272   F(CreateBreakIterator, 3, 1)               \
273   F(BreakIteratorAdoptText, 2, 1)            \
274   F(BreakIteratorFirst, 1, 1)                \
275   F(BreakIteratorNext, 1, 1)                 \
276   F(BreakIteratorCurrent, 1, 1)              \
277   F(BreakIteratorBreakType, 1, 1)            \
278   F(StringToLowerCaseI18N, 1, 1)             \
279   F(StringToUpperCaseI18N, 1, 1)             \
280   F(StringLocaleConvertCase, 3, 1)           \
281   F(DateCacheVersion, 0, 1)
282 #else
283 #define FOR_EACH_INTRINSIC_I18N(F)
284 #endif
285 
286 #define FOR_EACH_INTRINSIC_INTERNAL(F)              \
287   F(AllocateInNewSpace, 1, 1)                       \
288   F(AllocateInTargetSpace, 2, 1)                    \
289   F(AllocateSeqOneByteString, 1, 1)                 \
290   F(AllocateSeqTwoByteString, 1, 1)                 \
291   F(CheckIsBootstrapping, 0, 1)                     \
292   F(CreateAsyncFromSyncIterator, 1, 1)              \
293   F(CreateListFromArrayLike, 1, 1)                  \
294   F(GetAndResetRuntimeCallStats, -1 /* <= 2 */, 1)  \
295   F(ExportFromRuntime, 1, 1)                        \
296   F(IncrementUseCounter, 1, 1)                      \
297   F(InstallToContext, 1, 1)                         \
298   F(Interrupt, 0, 1)                                \
299   F(IS_VAR, 1, 1)                                   \
300   F(NewReferenceError, 2, 1)                        \
301   F(NewSyntaxError, 2, 1)                           \
302   F(NewTypeError, 2, 1)                             \
303   F(OrdinaryHasInstance, 2, 1)                      \
304   F(PromoteScheduledException, 0, 1)                \
305   F(ReThrow, 1, 1)                                  \
306   F(RunMicrotasks, 0, 1)                            \
307   F(StackGuard, 0, 1)                               \
308   F(Throw, 1, 1)                                    \
309   F(ThrowApplyNonFunction, 1, 1)                    \
310   F(ThrowCannotConvertToPrimitive, 0, 1)            \
311   F(ThrowCalledNonCallable, 1, 1)                   \
312   F(ThrowCalledOnNullOrUndefined, 1, 1)             \
313   F(ThrowConstructedNonConstructable, 1, 1)         \
314   F(ThrowDerivedConstructorReturnedNonObject, 0, 1) \
315   F(ThrowGeneratorRunning, 0, 1)                    \
316   F(ThrowIllegalInvocation, 0, 1)                   \
317   F(ThrowIncompatibleMethodReceiver, 2, 1)          \
318   F(ThrowInvalidHint, 1, 1)                         \
319   F(ThrowInvalidStringLength, 0, 1)                 \
320   F(ThrowIteratorResultNotAnObject, 1, 1)           \
321   F(ThrowSymbolIteratorInvalid, 0, 1)               \
322   F(ThrowNonCallableInInstanceOfCheck, 0, 1)        \
323   F(ThrowNonObjectInInstanceOfCheck, 0, 1)          \
324   F(ThrowNotConstructor, 1, 1)                      \
325   F(ThrowNotGeneric, 1, 1)                          \
326   F(ThrowReferenceError, 1, 1)                      \
327   F(ThrowStackOverflow, 0, 1)                       \
328   F(ThrowSymbolAsyncIteratorInvalid, 0, 1)          \
329   F(ThrowTypeError, -1 /* >= 1 */, 1)               \
330   F(ThrowUndefinedOrNullToObject, 1, 1)             \
331   F(Typeof, 1, 1)                                   \
332   F(UnwindAndFindExceptionHandler, 0, 1)            \
333   F(AllowDynamicFunction, 1, 1)
334 
335 #define FOR_EACH_INTRINSIC_LITERALS(F) \
336   F(CreateRegExpLiteral, 4, 1)         \
337   F(CreateObjectLiteral, 4, 1)         \
338   F(CreateArrayLiteral, 4, 1)          \
339   F(CreateArrayLiteralStubBailout, 3, 1)
340 
341 #define FOR_EACH_INTRINSIC_LIVEEDIT(F)              \
342   F(LiveEditFindSharedFunctionInfosForScript, 1, 1) \
343   F(LiveEditGatherCompileInfo, 2, 1)                \
344   F(LiveEditReplaceScript, 3, 1)                    \
345   F(LiveEditFunctionSourceUpdated, 2, 1)            \
346   F(LiveEditReplaceFunctionCode, 2, 1)              \
347   F(LiveEditFixupScript, 2, 1)                      \
348   F(LiveEditFunctionSetScript, 2, 1)                \
349   F(LiveEditReplaceRefToNestedFunction, 3, 1)       \
350   F(LiveEditPatchFunctionPositions, 2, 1)           \
351   F(LiveEditCheckAndDropActivations, 3, 1)          \
352   F(LiveEditCompareStrings, 2, 1)                   \
353   F(LiveEditRestartFrame, 2, 1)
354 
355 #define FOR_EACH_INTRINSIC_MATHS(F) F(GenerateRandomNumbers, 0, 1)
356 
357 #define FOR_EACH_INTRINSIC_MODULE(F) \
358   F(DynamicImportCall, 1, 1)         \
359   F(GetModuleNamespace, 1, 1)        \
360   F(LoadModuleVariable, 1, 1)        \
361   F(StoreModuleVariable, 2, 1)
362 
363 #define FOR_EACH_INTRINSIC_NUMBERS(F)  \
364   F(IsValidSmi, 1, 1)                  \
365   F(StringToNumber, 1, 1)              \
366   F(StringParseInt, 2, 1)              \
367   F(StringParseFloat, 1, 1)            \
368   F(NumberToString, 1, 1)              \
369   F(NumberToStringSkipCache, 1, 1)     \
370   F(NumberToSmi, 1, 1)                 \
371   F(SmiLexicographicCompare, 2, 1)     \
372   F(MaxSmi, 0, 1)                      \
373   F(IsSmi, 1, 1)                       \
374   F(GetRootNaN, 0, 1)                  \
375   F(GetHoleNaNUpper, 0, 1)             \
376   F(GetHoleNaNLower, 0, 1)
377 
378 #define FOR_EACH_INTRINSIC_OBJECT(F)                            \
379   F(GetPrototype, 1, 1)                                         \
380   F(ObjectHasOwnProperty, 2, 1)                                 \
381   F(ObjectCreate, 2, 1)                                         \
382   F(InternalSetPrototype, 2, 1)                                 \
383   F(OptimizeObjectForAddingMultipleProperties, 2, 1)            \
384   F(GetProperty, 2, 1)                                          \
385   F(KeyedGetProperty, 2, 1)                                     \
386   F(AddNamedProperty, 4, 1)                                     \
387   F(SetProperty, 4, 1)                                          \
388   F(AddElement, 3, 1)                                           \
389   F(AppendElement, 2, 1)                                        \
390   F(DeleteProperty_Sloppy, 2, 1)                                \
391   F(DeleteProperty_Strict, 2, 1)                                \
392   F(HasProperty, 2, 1)                                          \
393   F(GetOwnPropertyKeys, 2, 1)                                   \
394   F(GetInterceptorInfo, 1, 1)                                   \
395   F(ToFastProperties, 1, 1)                                     \
396   F(AllocateHeapNumber, 0, 1)                                   \
397   F(NewObject, 2, 1)                                            \
398   F(FinalizeInstanceSize, 1, 1)                                 \
399   F(LoadMutableDouble, 2, 1)                                    \
400   F(TryMigrateInstance, 1, 1)                                   \
401   F(IsJSGlobalProxy, 1, 1)                                      \
402   F(DefineAccessorPropertyUnchecked, 5, 1)                      \
403   F(DefineDataPropertyInLiteral, 6, 1)                          \
404   F(GetDataProperty, 2, 1)                                      \
405   F(GetConstructorName, 1, 1)                                   \
406   F(HasFastPackedElements, 1, 1)                                \
407   F(ValueOf, 1, 1)                                              \
408   F(IsJSReceiver, 1, 1)                                         \
409   F(ClassOf, 1, 1)                                              \
410   F(CopyDataProperties, 2, 1)                                   \
411   F(CopyDataPropertiesWithExcludedProperties, -1 /* >= 1 */, 1) \
412   F(DefineGetterPropertyUnchecked, 4, 1)                        \
413   F(DefineSetterPropertyUnchecked, 4, 1)                        \
414   F(ToObject, 1, 1)                                             \
415   F(ToPrimitive, 1, 1)                                          \
416   F(ToPrimitive_Number, 1, 1)                                   \
417   F(ToNumber, 1, 1)                                             \
418   F(ToInteger, 1, 1)                                            \
419   F(ToLength, 1, 1)                                             \
420   F(ToString, 1, 1)                                             \
421   F(ToName, 1, 1)                                               \
422   F(SameValue, 2, 1)                                            \
423   F(SameValueZero, 2, 1)                                        \
424   F(Compare, 3, 1)                                              \
425   F(HasInPrototypeChain, 2, 1)                                  \
426   F(CreateIterResultObject, 2, 1)                               \
427   F(CreateKeyValueArray, 2, 1)                                  \
428   F(IsAccessCheckNeeded, 1, 1)                                  \
429   F(CreateDataProperty, 3, 1)
430 
431 #define FOR_EACH_INTRINSIC_OPERATORS(F) \
432   F(Multiply, 2, 1)                     \
433   F(Divide, 2, 1)                       \
434   F(Modulus, 2, 1)                      \
435   F(Add, 2, 1)                          \
436   F(Subtract, 2, 1)                     \
437   F(ShiftLeft, 2, 1)                    \
438   F(ShiftRight, 2, 1)                   \
439   F(ShiftRightLogical, 2, 1)            \
440   F(BitwiseAnd, 2, 1)                   \
441   F(BitwiseOr, 2, 1)                    \
442   F(BitwiseXor, 2, 1)                   \
443   F(Equal, 2, 1)                        \
444   F(NotEqual, 2, 1)                     \
445   F(StrictEqual, 2, 1)                  \
446   F(StrictNotEqual, 2, 1)               \
447   F(LessThan, 2, 1)                     \
448   F(GreaterThan, 2, 1)                  \
449   F(LessThanOrEqual, 2, 1)              \
450   F(GreaterThanOrEqual, 2, 1)           \
451   F(InstanceOf, 2, 1)
452 
453 #define FOR_EACH_INTRINSIC_PROMISE(F)       \
454   F(EnqueueMicrotask, 1, 1)                 \
455   F(EnqueuePromiseReactionJob, 1, 1)        \
456   F(EnqueuePromiseResolveThenableJob, 1, 1) \
457   F(PromiseHookInit, 2, 1)                  \
458   F(PromiseHookResolve, 1, 1)               \
459   F(PromiseHookBefore, 1, 1)                \
460   F(PromiseHookAfter, 1, 1)                 \
461   F(PromiseMarkAsHandled, 1, 1)             \
462   F(PromiseRejectEventFromStack, 2, 1)      \
463   F(PromiseRevokeReject, 1, 1)              \
464   F(PromiseResult, 1, 1)                    \
465   F(PromiseStatus, 1, 1)                    \
466   F(ReportPromiseReject, 2, 1)
467 
468 #define FOR_EACH_INTRINSIC_PROXY(F)     \
469   F(IsJSProxy, 1, 1)                    \
470   F(JSProxyCall, -1 /* >= 2 */, 1)      \
471   F(JSProxyConstruct, -1 /* >= 3 */, 1) \
472   F(JSProxyGetTarget, 1, 1)             \
473   F(JSProxyGetHandler, 1, 1)            \
474   F(JSProxyRevoke, 1, 1)
475 
476 #define FOR_EACH_INTRINSIC_REGEXP(F)                \
477   F(IsRegExp, 1, 1)                                 \
478   F(RegExpCreate, 1, 1)                             \
479   F(RegExpExec, 4, 1)                               \
480   F(RegExpExecMultiple, 4, 1)                       \
481   F(RegExpExecReThrow, 4, 1)                        \
482   F(RegExpInitializeAndCompile, 3, 1)               \
483   F(RegExpInternalReplace, 3, 1)                    \
484   F(RegExpReplace, 3, 1)                            \
485   F(RegExpSplit, 3, 1)                              \
486   F(StringReplaceGlobalRegExpWithString, 4, 1)      \
487   F(StringReplaceNonGlobalRegExpWithFunction, 3, 1) \
488   F(StringSplit, 3, 1)
489 
490 #define FOR_EACH_INTRINSIC_SCOPES(F)    \
491   F(ThrowConstAssignError, 0, 1)        \
492   F(DeclareGlobals, 3, 1)               \
493   F(DeclareGlobalsForInterpreter, 3, 1) \
494   F(InitializeVarGlobal, 3, 1)          \
495   F(DeclareEvalFunction, 2, 1)          \
496   F(DeclareEvalVar, 1, 1)               \
497   F(NewSloppyArguments_Generic, 1, 1)   \
498   F(NewStrictArguments, 1, 1)           \
499   F(NewRestParameter, 1, 1)             \
500   F(NewSloppyArguments, 3, 1)           \
501   F(NewArgumentsElements, 2, 1)         \
502   F(NewClosure, 3, 1)                   \
503   F(NewClosure_Tenured, 3, 1)           \
504   F(NewScriptContext, 2, 1)             \
505   F(NewFunctionContext, 2, 1)           \
506   F(PushModuleContext, 3, 1)            \
507   F(PushWithContext, 3, 1)              \
508   F(PushCatchContext, 4, 1)             \
509   F(PushBlockContext, 2, 1)             \
510   F(DeleteLookupSlot, 1, 1)             \
511   F(LoadLookupSlot, 1, 1)               \
512   F(LoadLookupSlotInsideTypeof, 1, 1)   \
513   F(StoreLookupSlot_Sloppy, 2, 1)       \
514   F(StoreLookupSlot_Strict, 2, 1)
515 
516 #define FOR_EACH_INTRINSIC_STRINGS(F)     \
517   F(GetSubstitution, 4, 1)                \
518   F(StringReplaceOneCharWithString, 3, 1) \
519   F(StringIndexOf, 3, 1)                  \
520   F(StringIndexOfUnchecked, 3, 1)         \
521   F(StringLastIndexOf, 2, 1)              \
522   F(SubString, 3, 1)                      \
523   F(StringAdd, 2, 1)                      \
524   F(InternalizeString, 1, 1)              \
525   F(StringCharCodeAtRT, 2, 1)             \
526   F(StringCompare, 2, 1)                  \
527   F(StringBuilderConcat, 3, 1)            \
528   F(StringBuilderJoin, 3, 1)              \
529   F(SparseJoinWithSeparator, 3, 1)        \
530   F(StringToArray, 2, 1)                  \
531   F(StringLessThan, 2, 1)                 \
532   F(StringLessThanOrEqual, 2, 1)          \
533   F(StringGreaterThan, 2, 1)              \
534   F(StringGreaterThanOrEqual, 2, 1)       \
535   F(StringEqual, 2, 1)                    \
536   F(StringNotEqual, 2, 1)                 \
537   F(FlattenString, 1, 1)                  \
538   F(StringCharFromCode, 1, 1)             \
539   F(ExternalStringGetChar, 2, 1)          \
540   F(StringCharCodeAt, 2, 1)
541 
542 #define FOR_EACH_INTRINSIC_SYMBOL(F) \
543   F(CreateSymbol, 1, 1)              \
544   F(CreatePrivateSymbol, 1, 1)       \
545   F(SymbolDescription, 1, 1)         \
546   F(SymbolDescriptiveString, 1, 1)   \
547   F(SymbolIsPrivate, 1, 1)
548 
549 #define FOR_EACH_INTRINSIC_TEST(F)            \
550   F(ConstructDouble, 2, 1)                    \
551   F(DeoptimizeFunction, 1, 1)                 \
552   F(DeoptimizeNow, 0, 1)                      \
553   F(RunningInSimulator, 0, 1)                 \
554   F(IsConcurrentRecompilationSupported, 0, 1) \
555   F(OptimizeFunctionOnNextCall, -1, 1)        \
556   F(InterpretFunctionOnNextCall, 1, 1)        \
557   F(BaselineFunctionOnNextCall, 1, 1)         \
558   F(OptimizeOsr, -1, 1)                       \
559   F(NeverOptimizeFunction, 1, 1)              \
560   F(GetOptimizationStatus, -1, 1)             \
561   F(UnblockConcurrentRecompilation, 0, 1)     \
562   F(GetOptimizationCount, 1, 1)               \
563   F(GetUndetectable, 0, 1)                    \
564   F(GetCallable, 0, 1)                        \
565   F(ClearFunctionFeedback, 1, 1)              \
566   F(CheckWasmWrapperElision, 2, 1)            \
567   F(NotifyContextDisposed, 0, 1)              \
568   F(SetAllocationTimeout, -1 /* 2 || 3 */, 1) \
569   F(DebugPrint, 1, 1)                         \
570   F(DebugTrace, 0, 1)                         \
571   F(GetExceptionDetails, 1, 1)                \
572   F(GlobalPrint, 1, 1)                        \
573   F(SystemBreak, 0, 1)                        \
574   F(SetFlags, 1, 1)                           \
575   F(Abort, 1, 1)                              \
576   F(AbortJS, 1, 1)                            \
577   F(NativeScriptsCount, 0, 1)                 \
578   F(GetV8Version, 0, 1)                       \
579   F(DisassembleFunction, 1, 1)                \
580   F(TraceEnter, 0, 1)                         \
581   F(TraceExit, 1, 1)                          \
582   F(TraceTailCall, 0, 1)                      \
583   F(HaveSameMap, 2, 1)                        \
584   F(InNewSpace, 1, 1)                         \
585   F(HasFastSmiElements, 1, 1)                 \
586   F(HasFastObjectElements, 1, 1)              \
587   F(HasFastSmiOrObjectElements, 1, 1)         \
588   F(HasFastDoubleElements, 1, 1)              \
589   F(HasFastHoleyElements, 1, 1)               \
590   F(HasDictionaryElements, 1, 1)              \
591   F(HasSloppyArgumentsElements, 1, 1)         \
592   F(HasFixedTypedArrayElements, 1, 1)         \
593   F(HasFastProperties, 1, 1)                  \
594   F(HasFixedUint8Elements, 1, 1)              \
595   F(HasFixedInt8Elements, 1, 1)               \
596   F(HasFixedUint16Elements, 1, 1)             \
597   F(HasFixedInt16Elements, 1, 1)              \
598   F(HasFixedUint32Elements, 1, 1)             \
599   F(HasFixedInt32Elements, 1, 1)              \
600   F(HasFixedFloat32Elements, 1, 1)            \
601   F(HasFixedFloat64Elements, 1, 1)            \
602   F(HasFixedUint8ClampedElements, 1, 1)       \
603   F(SpeciesProtector, 0, 1)                   \
604   F(SerializeWasmModule, 1, 1)                \
605   F(DeserializeWasmModule, 2, 1)              \
606   F(IsAsmWasmCode, 1, 1)                      \
607   F(IsWasmCode, 1, 1)                         \
608   F(DisallowCodegenFromStrings, 0, 1)         \
609   F(ValidateWasmInstancesChain, 2, 1)         \
610   F(ValidateWasmModuleState, 1, 1)            \
611   F(ValidateWasmOrphanedInstance, 1, 1)       \
612   F(SetWasmCompileControls, 2, 1)             \
613   F(SetWasmInstantiateControls, 0, 1)         \
614   F(Verify, 1, 1)
615 
616 #define FOR_EACH_INTRINSIC_TYPEDARRAY(F)     \
617   F(ArrayBufferGetByteLength, 1, 1)          \
618   F(ArrayBufferSliceImpl, 4, 1)              \
619   F(ArrayBufferNeuter, 1, 1)                 \
620   F(TypedArrayInitialize, 6, 1)              \
621   F(TypedArrayInitializeFromArrayLike, 4, 1) \
622   F(ArrayBufferViewGetByteLength, 1, 1)      \
623   F(ArrayBufferViewGetByteOffset, 1, 1)      \
624   F(TypedArrayGetLength, 1, 1)               \
625   F(TypedArrayGetBuffer, 1, 1)               \
626   F(TypedArraySetFastCases, 3, 1)            \
627   F(TypedArraySortFast, 1, 1)                \
628   F(TypedArrayMaxSizeInHeap, 0, 1)           \
629   F(IsTypedArray, 1, 1)                      \
630   F(IsSharedTypedArray, 1, 1)                \
631   F(IsSharedIntegerTypedArray, 1, 1)         \
632   F(IsSharedInteger32TypedArray, 1, 1)
633 
634 #define FOR_EACH_INTRINSIC_WASM(F)     \
635   F(WasmGrowMemory, 1, 1)              \
636   F(WasmMemorySize, 0, 1)              \
637   F(ThrowWasmError, 2, 1)              \
638   F(ThrowWasmErrorFromTrapIf, 1, 1)    \
639   F(WasmThrowTypeError, 0, 1)          \
640   F(WasmThrow, 2, 1)                   \
641   F(WasmGetCaughtExceptionValue, 1, 1) \
642   F(WasmRunInterpreter, 3, 1)          \
643   F(WasmStackGuard, 0, 1)
644 
645 #define FOR_EACH_INTRINSIC_RETURN_PAIR(F) \
646   F(LoadLookupSlotForCall, 1, 2)
647 
648 #define FOR_EACH_INTRINSIC_RETURN_TRIPLE(F) \
649   F(ForInPrepare, 1, 3)
650 
651 // Most intrinsics are implemented in the runtime/ directory, but ICs are
652 // implemented in ic.cc for now.
653 #define FOR_EACH_INTRINSIC_IC(F)             \
654   F(BinaryOpIC_Miss, 2, 1)                   \
655   F(BinaryOpIC_MissWithAllocationSite, 3, 1) \
656   F(CompareIC_Miss, 3, 1)                    \
657   F(ElementsTransitionAndStoreIC_Miss, 6, 1) \
658   F(KeyedLoadIC_Miss, 4, 1)                  \
659   F(KeyedStoreIC_Miss, 5, 1)                 \
660   F(KeyedStoreIC_Slow, 5, 1)                 \
661   F(LoadElementWithInterceptor, 2, 1)        \
662   F(LoadGlobalIC_Miss, 3, 1)                 \
663   F(LoadGlobalIC_Slow, 3, 1)                 \
664   F(LoadIC_Miss, 4, 1)                       \
665   F(LoadPropertyWithInterceptor, 5, 1)       \
666   F(LoadPropertyWithInterceptorOnly, 3, 1)   \
667   F(StoreCallbackProperty, 6, 1)             \
668   F(StoreIC_Miss, 5, 1)                      \
669   F(StorePropertyWithInterceptor, 5, 1)      \
670   F(ToBooleanIC_Miss, 1, 1)                  \
671   F(Unreachable, 0, 1)
672 
673 #define FOR_EACH_INTRINSIC_RETURN_OBJECT(F) \
674   FOR_EACH_INTRINSIC_IC(F)                  \
675   FOR_EACH_INTRINSIC_ARRAY(F)               \
676   FOR_EACH_INTRINSIC_ATOMICS(F)             \
677   FOR_EACH_INTRINSIC_CLASSES(F)             \
678   FOR_EACH_INTRINSIC_COLLECTIONS(F)         \
679   FOR_EACH_INTRINSIC_COMPILER(F)            \
680   FOR_EACH_INTRINSIC_DATE(F)                \
681   FOR_EACH_INTRINSIC_DEBUG(F)               \
682   FOR_EACH_INTRINSIC_ERROR(F)               \
683   FOR_EACH_INTRINSIC_FORIN(F)               \
684   FOR_EACH_INTRINSIC_INTERPRETER(F)         \
685   FOR_EACH_INTRINSIC_FUNCTION(F)            \
686   FOR_EACH_INTRINSIC_GENERATOR(F)           \
687   FOR_EACH_INTRINSIC_I18N(F)                \
688   FOR_EACH_INTRINSIC_INTERNAL(F)            \
689   FOR_EACH_INTRINSIC_LITERALS(F)            \
690   FOR_EACH_INTRINSIC_LIVEEDIT(F)            \
691   FOR_EACH_INTRINSIC_MATHS(F)               \
692   FOR_EACH_INTRINSIC_MODULE(F)              \
693   FOR_EACH_INTRINSIC_NUMBERS(F)             \
694   FOR_EACH_INTRINSIC_OBJECT(F)              \
695   FOR_EACH_INTRINSIC_OPERATORS(F)           \
696   FOR_EACH_INTRINSIC_PROMISE(F)             \
697   FOR_EACH_INTRINSIC_PROXY(F)               \
698   FOR_EACH_INTRINSIC_REGEXP(F)              \
699   FOR_EACH_INTRINSIC_SCOPES(F)              \
700   FOR_EACH_INTRINSIC_STRINGS(F)             \
701   FOR_EACH_INTRINSIC_SYMBOL(F)              \
702   FOR_EACH_INTRINSIC_TEST(F)                \
703   FOR_EACH_INTRINSIC_TYPEDARRAY(F)          \
704   FOR_EACH_INTRINSIC_WASM(F)
705 
706 // FOR_EACH_INTRINSIC defines the list of all intrinsics, coming in 2 flavors,
707 // either returning an object or a pair.
708 #define FOR_EACH_INTRINSIC(F)         \
709   FOR_EACH_INTRINSIC_RETURN_TRIPLE(F) \
710   FOR_EACH_INTRINSIC_RETURN_PAIR(F)   \
711   FOR_EACH_INTRINSIC_RETURN_OBJECT(F)
712 
713 
714 #define F(name, nargs, ressize)                                 \
715   Object* Runtime_##name(int args_length, Object** args_object, \
716                          Isolate* isolate);
FOR_EACH_INTRINSIC_RETURN_OBJECT(F)717 FOR_EACH_INTRINSIC_RETURN_OBJECT(F)
718 #undef F
719 
720 //---------------------------------------------------------------------------
721 // Runtime provides access to all C++ runtime functions.
722 
723 class Runtime : public AllStatic {
724  public:
725   enum FunctionId : int32_t {
726 #define F(name, nargs, ressize) k##name,
727 #define I(name, nargs, ressize) kInline##name,
728     FOR_EACH_INTRINSIC(F) FOR_EACH_INTRINSIC(I)
729 #undef I
730 #undef F
731         kNumFunctions,
732   };
733 
734   enum IntrinsicType { RUNTIME, INLINE };
735 
736   // Intrinsic function descriptor.
737   struct Function {
738     FunctionId function_id;
739     IntrinsicType intrinsic_type;
740     // The JS name of the function.
741     const char* name;
742 
743     // For RUNTIME functions, this is the C++ entry point.
744     // For INLINE functions this is the C++ entry point of the fall back.
745     Address entry;
746 
747     // The number of arguments expected. nargs is -1 if the function takes
748     // a variable number of arguments.
749     int8_t nargs;
750     // Size of result.  Most functions return a single pointer, size 1.
751     int8_t result_size;
752   };
753 
754   static const int kNotFound = -1;
755 
756   // Get the intrinsic function with the given name.
757   static const Function* FunctionForName(const unsigned char* name, int length);
758 
759   // Get the intrinsic function with the given FunctionId.
760   V8_EXPORT_PRIVATE static const Function* FunctionForId(FunctionId id);
761 
762   // Get the intrinsic function with the given function entry address.
763   static const Function* FunctionForEntry(Address ref);
764 
765   // Get the runtime intrinsic function table.
766   static const Function* RuntimeFunctionTable(Isolate* isolate);
767 
768   MUST_USE_RESULT static Maybe<bool> DeleteObjectProperty(
769       Isolate* isolate, Handle<JSReceiver> receiver, Handle<Object> key,
770       LanguageMode language_mode);
771 
772   MUST_USE_RESULT static MaybeHandle<Object> SetObjectProperty(
773       Isolate* isolate, Handle<Object> object, Handle<Object> key,
774       Handle<Object> value, LanguageMode language_mode);
775 
776   MUST_USE_RESULT static MaybeHandle<Object> GetObjectProperty(
777       Isolate* isolate, Handle<Object> object, Handle<Object> key,
778       bool* is_found_out = nullptr);
779 
780   enum TypedArrayId {
781     // arrayIds below should be synchronized with typedarray.js natives.
782     ARRAY_ID_UINT8 = 1,
783     ARRAY_ID_INT8 = 2,
784     ARRAY_ID_UINT16 = 3,
785     ARRAY_ID_INT16 = 4,
786     ARRAY_ID_UINT32 = 5,
787     ARRAY_ID_INT32 = 6,
788     ARRAY_ID_FLOAT32 = 7,
789     ARRAY_ID_FLOAT64 = 8,
790     ARRAY_ID_UINT8_CLAMPED = 9,
791     ARRAY_ID_FIRST = ARRAY_ID_UINT8,
792     ARRAY_ID_LAST = ARRAY_ID_UINT8_CLAMPED
793   };
794 
795   static void ArrayIdToTypeAndSize(int array_id, ExternalArrayType* type,
796                                    ElementsKind* fixed_elements_kind,
797                                    size_t* element_size);
798 
799   static MaybeHandle<JSArray> GetInternalProperties(Isolate* isolate,
800                                                     Handle<Object>);
801 };
802 
803 
804 class RuntimeState {
805  public:
to_upper_mapping()806   unibrow::Mapping<unibrow::ToUppercase, 128>* to_upper_mapping() {
807     return &to_upper_mapping_;
808   }
to_lower_mapping()809   unibrow::Mapping<unibrow::ToLowercase, 128>* to_lower_mapping() {
810     return &to_lower_mapping_;
811   }
812 
redirected_intrinsic_functions()813   Runtime::Function* redirected_intrinsic_functions() {
814     return redirected_intrinsic_functions_.get();
815   }
816 
set_redirected_intrinsic_functions(Runtime::Function * redirected_intrinsic_functions)817   void set_redirected_intrinsic_functions(
818       Runtime::Function* redirected_intrinsic_functions) {
819     redirected_intrinsic_functions_.reset(redirected_intrinsic_functions);
820   }
821 
822  private:
RuntimeState()823   RuntimeState() {}
824   unibrow::Mapping<unibrow::ToUppercase, 128> to_upper_mapping_;
825   unibrow::Mapping<unibrow::ToLowercase, 128> to_lower_mapping_;
826 
827   std::unique_ptr<Runtime::Function[]> redirected_intrinsic_functions_;
828 
829   friend class Isolate;
830   friend class Runtime;
831 
832   DISALLOW_COPY_AND_ASSIGN(RuntimeState);
833 };
834 
835 V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream&, Runtime::FunctionId);
836 
837 //---------------------------------------------------------------------------
838 // Constants used by interface to runtime functions.
839 
840 class AllocateDoubleAlignFlag : public BitField<bool, 0, 1> {};
841 class AllocateTargetSpace : public BitField<AllocationSpace, 1, 3> {};
842 
843 class DeclareGlobalsEvalFlag : public BitField<bool, 0, 1> {};
844 class DeclareGlobalsNativeFlag : public BitField<bool, 1, 1> {};
845 STATIC_ASSERT(LANGUAGE_END == 2);
846 class DeclareGlobalsLanguageMode : public BitField<LanguageMode, 2, 1> {};
847 
848 // A set of bits returned by Runtime_GetOptimizationStatus.
849 // These bits must be in sync with bits defined in test/mjsunit/mjsunit.js
850 enum class OptimizationStatus {
851   kIsFunction = 1 << 0,
852   kNeverOptimize = 1 << 1,
853   kAlwaysOptimize = 1 << 2,
854   kMaybeDeopted = 1 << 3,
855   kOptimized = 1 << 4,
856   kTurboFanned = 1 << 5,
857   kInterpreted = 1 << 6,
858 };
859 
860 }  // namespace internal
861 }  // namespace v8
862 
863 #endif  // V8_RUNTIME_RUNTIME_H_
864