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/globals.h"
13 #include "src/objects.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(ArrayPush, -1, 1)                \
49   F(FunctionBind, -1, 1)             \
50   F(NormalizeElements, 1, 1)         \
51   F(GrowArrayElements, 2, 1)         \
52   F(HasComplexElements, 1, 1)        \
53   F(IsArray, 1, 1)                   \
54   F(ArrayIsArray, 1, 1)              \
55   F(FixedArrayGet, 2, 1)             \
56   F(FixedArraySet, 3, 1)             \
57   F(ArraySpeciesConstructor, 1, 1)   \
58   F(ArrayIncludes_Slow, 3, 1)        \
59   F(ArrayIndexOf, 3, 1)              \
60   F(SpreadIterablePrepare, 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 
78 #define FOR_EACH_INTRINSIC_CLASSES(F)       \
79   F(ThrowNonMethodError, 0, 1)              \
80   F(ThrowUnsupportedSuperError, 0, 1)       \
81   F(ThrowConstructorNonCallableError, 1, 1) \
82   F(ThrowArrayNotSubclassableError, 0, 1)   \
83   F(ThrowStaticPrototypeError, 0, 1)        \
84   F(ThrowIfStaticPrototype, 1, 1)           \
85   F(HomeObjectSymbol, 0, 1)                 \
86   F(DefineClass, 4, 1)                      \
87   F(LoadFromSuper, 3, 1)                    \
88   F(LoadKeyedFromSuper, 3, 1)               \
89   F(StoreToSuper_Strict, 4, 1)              \
90   F(StoreToSuper_Sloppy, 4, 1)              \
91   F(StoreKeyedToSuper_Strict, 4, 1)         \
92   F(StoreKeyedToSuper_Sloppy, 4, 1)         \
93   F(GetSuperConstructor, 1, 1)
94 
95 #define FOR_EACH_INTRINSIC_COLLECTIONS(F) \
96   F(StringGetRawHashField, 1, 1)          \
97   F(TheHole, 0, 1)                        \
98   F(JSCollectionGetTable, 1, 1)           \
99   F(GenericHash, 1, 1)                    \
100   F(SetInitialize, 1, 1)                  \
101   F(SetGrow, 1, 1)                        \
102   F(SetShrink, 1, 1)                      \
103   F(SetClear, 1, 1)                       \
104   F(SetIteratorInitialize, 3, 1)          \
105   F(SetIteratorClone, 1, 1)               \
106   F(SetIteratorNext, 2, 1)                \
107   F(SetIteratorDetails, 1, 1)             \
108   F(MapInitialize, 1, 1)                  \
109   F(MapShrink, 1, 1)                      \
110   F(MapClear, 1, 1)                       \
111   F(MapGrow, 1, 1)                        \
112   F(MapIteratorInitialize, 3, 1)          \
113   F(MapIteratorClone, 1, 1)               \
114   F(MapIteratorDetails, 1, 1)             \
115   F(GetWeakMapEntries, 2, 1)              \
116   F(MapIteratorNext, 2, 1)                \
117   F(WeakCollectionInitialize, 1, 1)       \
118   F(WeakCollectionGet, 3, 1)              \
119   F(WeakCollectionHas, 3, 1)              \
120   F(WeakCollectionDelete, 3, 1)           \
121   F(WeakCollectionSet, 4, 1)              \
122   F(GetWeakSetValues, 2, 1)
123 
124 #define FOR_EACH_INTRINSIC_COMPILER(F)    \
125   F(CompileLazy, 1, 1)                    \
126   F(CompileBaseline, 1, 1)                \
127   F(CompileOptimized_Concurrent, 1, 1)    \
128   F(CompileOptimized_NotConcurrent, 1, 1) \
129   F(NotifyStubFailure, 0, 1)              \
130   F(NotifyDeoptimized, 1, 1)              \
131   F(CompileForOnStackReplacement, 1, 1)   \
132   F(TryInstallOptimizedCode, 1, 1)        \
133   F(ResolvePossiblyDirectEval, 6, 1)      \
134   F(InstantiateAsmJs, 4, 1)
135 
136 #define FOR_EACH_INTRINSIC_DATE(F) \
137   F(IsDate, 1, 1)                  \
138   F(DateCurrentTime, 0, 1)         \
139   F(ThrowNotDateError, 0, 1)
140 
141 #define FOR_EACH_INTRINSIC_DEBUG(F)             \
142   F(HandleDebuggerStatement, 0, 1)              \
143   F(DebugBreak, 1, 1)                           \
144   F(DebugBreakOnBytecode, 1, 1)                 \
145   F(SetDebugEventListener, 2, 1)                \
146   F(ScheduleBreak, 0, 1)                        \
147   F(DebugGetInternalProperties, 1, 1)           \
148   F(DebugGetPropertyDetails, 2, 1)              \
149   F(DebugGetProperty, 2, 1)                     \
150   F(DebugPropertyTypeFromDetails, 1, 1)         \
151   F(DebugPropertyAttributesFromDetails, 1, 1)   \
152   F(CheckExecutionState, 1, 1)                  \
153   F(GetFrameCount, 1, 1)                        \
154   F(GetFrameDetails, 2, 1)                      \
155   F(GetScopeCount, 2, 1)                        \
156   F(GetScopeDetails, 4, 1)                      \
157   F(GetAllScopesDetails, 4, 1)                  \
158   F(GetFunctionScopeCount, 1, 1)                \
159   F(GetFunctionScopeDetails, 2, 1)              \
160   F(GetGeneratorScopeCount, 1, 1)               \
161   F(GetGeneratorScopeDetails, 2, 1)             \
162   F(SetScopeVariableValue, 6, 1)                \
163   F(DebugPrintScopes, 0, 1)                     \
164   F(SetBreakPointsActive, 1, 1)                 \
165   F(GetBreakLocations, 2, 1)                    \
166   F(SetFunctionBreakPoint, 3, 1)                \
167   F(SetScriptBreakPoint, 4, 1)                  \
168   F(ClearBreakPoint, 1, 1)                      \
169   F(ChangeBreakOnException, 2, 1)               \
170   F(IsBreakOnException, 1, 1)                   \
171   F(PrepareStep, 2, 1)                          \
172   F(ClearStepping, 0, 1)                        \
173   F(DebugEvaluate, 6, 1)                        \
174   F(DebugEvaluateGlobal, 4, 1)                  \
175   F(DebugGetLoadedScripts, 0, 1)                \
176   F(DebugReferencedBy, 3, 1)                    \
177   F(DebugConstructedBy, 2, 1)                   \
178   F(DebugGetPrototype, 1, 1)                    \
179   F(DebugSetScriptSource, 2, 1)                 \
180   F(FunctionGetInferredName, 1, 1)              \
181   F(FunctionGetDebugName, 1, 1)                 \
182   F(ExecuteInDebugContext, 1, 1)                \
183   F(GetDebugContext, 0, 1)                      \
184   F(CollectGarbage, 1, 1)                       \
185   F(GetHeapUsage, 0, 1)                         \
186   F(GetScript, 1, 1)                            \
187   F(ScriptLineCount, 1, 1)                      \
188   F(ScriptLineStartPosition, 2, 1)              \
189   F(ScriptLineEndPosition, 2, 1)                \
190   F(ScriptLocationFromLine, 4, 1)               \
191   F(ScriptLocationFromLine2, 4, 1)              \
192   F(ScriptPositionInfo, 3, 1)                   \
193   F(ScriptSourceLine, 2, 1)                     \
194   F(DebugPrepareStepInIfStepping, 1, 1)         \
195   F(DebugPrepareStepInSuspendedGenerator, 0, 1) \
196   F(DebugRecordAsyncFunction, 1, 1)             \
197   F(DebugPushPromise, 1, 1)                     \
198   F(DebugPopPromise, 0, 1)                      \
199   F(DebugNextMicrotaskId, 0, 1)                 \
200   F(DebugAsyncTaskEvent, 3, 1)                  \
201   F(DebugIsActive, 0, 1)                        \
202   F(DebugBreakInOptimizedCode, 0, 1)
203 
204 #define FOR_EACH_INTRINSIC_ERROR(F) F(ErrorToString, 1, 1)
205 
206 #define FOR_EACH_INTRINSIC_FORIN(F) \
207   F(ForInEnumerate, 1, 1)           \
208   F(ForInFilter, 2, 1)              \
209   F(ForInHasProperty, 2, 1)         \
210   F(ForInNext, 4, 1)
211 
212 #define FOR_EACH_INTRINSIC_INTERPRETER(F) \
213   F(InterpreterNewClosure, 2, 1)          \
214   F(InterpreterTraceBytecodeEntry, 3, 1)  \
215   F(InterpreterTraceBytecodeExit, 3, 1)   \
216   F(InterpreterClearPendingMessage, 0, 1) \
217   F(InterpreterSetPendingMessage, 1, 1)   \
218   F(InterpreterAdvanceBytecodeOffset, 2, 1)
219 
220 #define FOR_EACH_INTRINSIC_FUNCTION(F)     \
221   F(FunctionGetName, 1, 1)                 \
222   F(FunctionSetName, 2, 1)                 \
223   F(FunctionRemovePrototype, 1, 1)         \
224   F(FunctionGetScript, 1, 1)               \
225   F(FunctionGetScriptId, 1, 1)             \
226   F(FunctionGetSourceCode, 1, 1)           \
227   F(FunctionGetScriptSourcePosition, 1, 1) \
228   F(FunctionGetContextData, 1, 1)          \
229   F(FunctionSetInstanceClassName, 2, 1)    \
230   F(FunctionSetLength, 2, 1)               \
231   F(FunctionSetPrototype, 2, 1)            \
232   F(FunctionIsAPIFunction, 1, 1)           \
233   F(SetCode, 2, 1)                         \
234   F(SetNativeFlag, 1, 1)                   \
235   F(IsConstructor, 1, 1)                   \
236   F(SetForceInlineFlag, 1, 1)              \
237   F(Call, -1 /* >= 2 */, 1)                \
238   F(ConvertReceiver, 1, 1)                 \
239   F(IsFunction, 1, 1)                      \
240   F(FunctionToString, 1, 1)
241 
242 #define FOR_EACH_INTRINSIC_GENERATOR(F) \
243   F(CreateJSGeneratorObject, 2, 1)      \
244   F(SuspendJSGeneratorObject, 1, 1)     \
245   F(GeneratorClose, 1, 1)               \
246   F(GeneratorGetFunction, 1, 1)         \
247   F(GeneratorGetReceiver, 1, 1)         \
248   F(GeneratorGetInputOrDebugPos, 1, 1)  \
249   F(GeneratorGetContinuation, 1, 1)     \
250   F(GeneratorGetSourcePosition, 1, 1)   \
251   F(GeneratorGetResumeMode, 1, 1)
252 
253 #ifdef V8_I18N_SUPPORT
254 #define FOR_EACH_INTRINSIC_I18N(F)           \
255   F(CanonicalizeLanguageTag, 1, 1)           \
256   F(AvailableLocalesOf, 1, 1)                \
257   F(GetDefaultICULocale, 0, 1)               \
258   F(GetLanguageTagVariants, 1, 1)            \
259   F(IsInitializedIntlObject, 1, 1)           \
260   F(IsInitializedIntlObjectOfType, 2, 1)     \
261   F(MarkAsInitializedIntlObjectOfType, 3, 1) \
262   F(GetImplFromInitializedIntlObject, 1, 1)  \
263   F(CreateDateTimeFormat, 3, 1)              \
264   F(InternalDateFormat, 2, 1)                \
265   F(InternalDateFormatToParts, 2, 1)         \
266   F(InternalDateParse, 2, 1)                 \
267   F(CreateNumberFormat, 3, 1)                \
268   F(InternalNumberFormat, 2, 1)              \
269   F(InternalNumberParse, 2, 1)               \
270   F(CreateCollator, 3, 1)                    \
271   F(InternalCompare, 3, 1)                   \
272   F(StringNormalize, 2, 1)                   \
273   F(CreateBreakIterator, 3, 1)               \
274   F(BreakIteratorAdoptText, 2, 1)            \
275   F(BreakIteratorFirst, 1, 1)                \
276   F(BreakIteratorNext, 1, 1)                 \
277   F(BreakIteratorCurrent, 1, 1)              \
278   F(BreakIteratorBreakType, 1, 1)            \
279   F(StringToLowerCaseI18N, 1, 1)             \
280   F(StringToUpperCaseI18N, 1, 1)             \
281   F(StringLocaleConvertCase, 3, 1)           \
282   F(DateCacheVersion, 0, 1)
283 #else
284 #define FOR_EACH_INTRINSIC_I18N(F)
285 #endif
286 
287 #define FOR_EACH_INTRINSIC_INTERNAL(F)              \
288   F(AllocateInNewSpace, 1, 1)                       \
289   F(AllocateInTargetSpace, 2, 1)                    \
290   F(AllocateSeqOneByteString, 1, 1)                 \
291   F(AllocateSeqTwoByteString, 1, 1)                 \
292   F(CheckIsBootstrapping, 0, 1)                     \
293   F(CreateListFromArrayLike, 1, 1)                  \
294   F(EnqueueMicrotask, 1, 1)                         \
295   F(EnqueuePromiseReactionJob, 4, 1)                \
296   F(EnqueuePromiseResolveThenableJob, 3, 1)         \
297   F(GetAndResetRuntimeCallStats, -1 /* <= 2 */, 1)  \
298   F(ExportExperimentalFromRuntime, 1, 1)            \
299   F(ExportFromRuntime, 1, 1)                        \
300   F(IncrementUseCounter, 1, 1)                      \
301   F(InstallToContext, 1, 1)                         \
302   F(Interrupt, 0, 1)                                \
303   F(IS_VAR, 1, 1)                                   \
304   F(IsWasmInstance, 1, 1)                           \
305   F(NewReferenceError, 2, 1)                        \
306   F(NewSyntaxError, 2, 1)                           \
307   F(NewTypeError, 2, 1)                             \
308   F(OrdinaryHasInstance, 2, 1)                      \
309   F(PromiseReject, 3, 1)                            \
310   F(PromiseFulfill, 4, 1)                           \
311   F(PromiseRejectEventFromStack, 2, 1)              \
312   F(PromiseRevokeReject, 1, 1)                      \
313   F(PromoteScheduledException, 0, 1)                \
314   F(ReThrow, 1, 1)                                  \
315   F(RunMicrotasks, 0, 1)                            \
316   F(StackGuard, 0, 1)                               \
317   F(Throw, 1, 1)                                    \
318   F(ThrowApplyNonFunction, 1, 1)                    \
319   F(ThrowCannotConvertToPrimitive, 0, 1)            \
320   F(ThrowCalledNonCallable, 1, 1)                   \
321   F(ThrowCalledOnNullOrUndefined, 1, 1)             \
322   F(ThrowConstructedNonConstructable, 1, 1)         \
323   F(ThrowDerivedConstructorReturnedNonObject, 0, 1) \
324   F(ThrowGeneratorRunning, 0, 1)                    \
325   F(ThrowIllegalInvocation, 0, 1)                   \
326   F(ThrowIncompatibleMethodReceiver, 2, 1)          \
327   F(ThrowInvalidStringLength, 0, 1)                 \
328   F(ThrowIteratorResultNotAnObject, 1, 1)           \
329   F(ThrowNotGeneric, 1, 1)                          \
330   F(ThrowReferenceError, 1, 1)                      \
331   F(ThrowStackOverflow, 0, 1)                       \
332   F(ThrowTypeError, -1 /* >= 1 */, 1)               \
333   F(ThrowWasmError, 2, 1)                           \
334   F(ThrowUndefinedOrNullToObject, 1, 1)             \
335   F(Typeof, 1, 1)                                   \
336   F(UnwindAndFindExceptionHandler, 0, 1)
337 
338 #define FOR_EACH_INTRINSIC_LITERALS(F) \
339   F(CreateRegExpLiteral, 4, 1)         \
340   F(CreateObjectLiteral, 4, 1)         \
341   F(CreateArrayLiteral, 4, 1)          \
342   F(CreateArrayLiteralStubBailout, 3, 1)
343 
344 
345 #define FOR_EACH_INTRINSIC_LIVEEDIT(F)              \
346   F(LiveEditFindSharedFunctionInfosForScript, 1, 1) \
347   F(LiveEditGatherCompileInfo, 2, 1)                \
348   F(LiveEditReplaceScript, 3, 1)                    \
349   F(LiveEditFunctionSourceUpdated, 1, 1)            \
350   F(LiveEditReplaceFunctionCode, 2, 1)              \
351   F(LiveEditFunctionSetScript, 2, 1)                \
352   F(LiveEditReplaceRefToNestedFunction, 3, 1)       \
353   F(LiveEditPatchFunctionPositions, 2, 1)           \
354   F(LiveEditCheckAndDropActivations, 3, 1)          \
355   F(LiveEditCompareStrings, 2, 1)                   \
356   F(LiveEditRestartFrame, 2, 1)
357 
358 #define FOR_EACH_INTRINSIC_MATHS(F) F(GenerateRandomNumbers, 0, 1)
359 
360 #define FOR_EACH_INTRINSIC_MODULE(F) \
361   F(GetModuleNamespace, 1, 1)        \
362   F(LoadModuleVariable, 1, 1)        \
363   F(StoreModuleVariable, 2, 1)
364 
365 #define FOR_EACH_INTRINSIC_NUMBERS(F)  \
366   F(IsValidSmi, 1, 1)                  \
367   F(StringToNumber, 1, 1)              \
368   F(StringParseInt, 2, 1)              \
369   F(StringParseFloat, 1, 1)            \
370   F(NumberToString, 1, 1)              \
371   F(NumberToStringSkipCache, 1, 1)     \
372   F(NumberToSmi, 1, 1)                 \
373   F(SmiLexicographicCompare, 2, 1)     \
374   F(MaxSmi, 0, 1)                      \
375   F(IsSmi, 1, 1)                       \
376   F(GetRootNaN, 0, 1)                  \
377   F(GetHoleNaNUpper, 0, 1)             \
378   F(GetHoleNaNLower, 0, 1)
379 
380 #define FOR_EACH_INTRINSIC_OBJECT(F)                 \
381   F(GetPrototype, 1, 1)                              \
382   F(ObjectHasOwnProperty, 2, 1)                      \
383   F(ObjectCreate, 2, 1)                              \
384   F(InternalSetPrototype, 2, 1)                      \
385   F(OptimizeObjectForAddingMultipleProperties, 2, 1) \
386   F(GetProperty, 2, 1)                               \
387   F(KeyedGetProperty, 2, 1)                          \
388   F(AddNamedProperty, 4, 1)                          \
389   F(SetProperty, 4, 1)                               \
390   F(AddElement, 3, 1)                                \
391   F(AppendElement, 2, 1)                             \
392   F(DeleteProperty_Sloppy, 2, 1)                     \
393   F(DeleteProperty_Strict, 2, 1)                     \
394   F(HasProperty, 2, 1)                               \
395   F(GetOwnPropertyKeys, 2, 1)                        \
396   F(GetInterceptorInfo, 1, 1)                        \
397   F(ToFastProperties, 1, 1)                          \
398   F(AllocateHeapNumber, 0, 1)                        \
399   F(NewObject, 2, 1)                                 \
400   F(FinalizeInstanceSize, 1, 1)                      \
401   F(LoadMutableDouble, 2, 1)                         \
402   F(TryMigrateInstance, 1, 1)                        \
403   F(IsJSGlobalProxy, 1, 1)                           \
404   F(DefineAccessorPropertyUnchecked, 5, 1)           \
405   F(DefineDataPropertyInLiteral, 5, 1)               \
406   F(DefineDataProperty, 5, 1)                        \
407   F(GetDataProperty, 2, 1)                           \
408   F(GetConstructorName, 1, 1)                        \
409   F(HasFastPackedElements, 1, 1)                     \
410   F(ValueOf, 1, 1)                                   \
411   F(IsJSReceiver, 1, 1)                              \
412   F(ClassOf, 1, 1)                                   \
413   F(DefineGetterPropertyUnchecked, 4, 1)             \
414   F(DefineSetterPropertyUnchecked, 4, 1)             \
415   F(ToObject, 1, 1)                                  \
416   F(ToPrimitive, 1, 1)                               \
417   F(ToPrimitive_Number, 1, 1)                        \
418   F(ToNumber, 1, 1)                                  \
419   F(ToInteger, 1, 1)                                 \
420   F(ToLength, 1, 1)                                  \
421   F(ToString, 1, 1)                                  \
422   F(ToName, 1, 1)                                    \
423   F(SameValue, 2, 1)                                 \
424   F(SameValueZero, 2, 1)                             \
425   F(Compare, 3, 1)                                   \
426   F(HasInPrototypeChain, 2, 1)                       \
427   F(CreateIterResultObject, 2, 1)                    \
428   F(CreateKeyValueArray, 2, 1)                       \
429   F(IsAccessCheckNeeded, 1, 1)                       \
430   F(CreateDataProperty, 3, 1)
431 
432 #define FOR_EACH_INTRINSIC_OPERATORS(F) \
433   F(Multiply, 2, 1)                     \
434   F(Divide, 2, 1)                       \
435   F(Modulus, 2, 1)                      \
436   F(Add, 2, 1)                          \
437   F(Subtract, 2, 1)                     \
438   F(ShiftLeft, 2, 1)                    \
439   F(ShiftRight, 2, 1)                   \
440   F(ShiftRightLogical, 2, 1)            \
441   F(BitwiseAnd, 2, 1)                   \
442   F(BitwiseOr, 2, 1)                    \
443   F(BitwiseXor, 2, 1)                   \
444   F(Equal, 2, 1)                        \
445   F(NotEqual, 2, 1)                     \
446   F(StrictEqual, 2, 1)                  \
447   F(StrictNotEqual, 2, 1)               \
448   F(LessThan, 2, 1)                     \
449   F(GreaterThan, 2, 1)                  \
450   F(LessThanOrEqual, 2, 1)              \
451   F(GreaterThanOrEqual, 2, 1)           \
452   F(InstanceOf, 2, 1)
453 
454 #define FOR_EACH_INTRINSIC_PROXY(F)     \
455   F(IsJSProxy, 1, 1)                    \
456   F(JSProxyCall, -1 /* >= 2 */, 1)      \
457   F(JSProxyConstruct, -1 /* >= 3 */, 1) \
458   F(JSProxyGetTarget, 1, 1)             \
459   F(JSProxyGetHandler, 1, 1)            \
460   F(JSProxyRevoke, 1, 1)
461 
462 #define FOR_EACH_INTRINSIC_REGEXP(F)                \
463   F(IsRegExp, 1, 1)                                 \
464   F(RegExpCreate, 1, 1)                             \
465   F(RegExpExec, 4, 1)                               \
466   F(RegExpExecMultiple, 4, 1)                       \
467   F(RegExpExecReThrow, 4, 1)                        \
468   F(RegExpInternalReplace, 3, 1)                    \
469   F(RegExpReplace, 3, 1)                            \
470   F(StringReplaceGlobalRegExpWithString, 4, 1)      \
471   F(StringReplaceNonGlobalRegExpWithFunction, 3, 1) \
472   F(StringSplit, 3, 1)
473 
474 #define FOR_EACH_INTRINSIC_SCOPES(F)    \
475   F(ThrowConstAssignError, 0, 1)        \
476   F(DeclareGlobals, 3, 1)               \
477   F(DeclareGlobalsForInterpreter, 3, 1) \
478   F(InitializeVarGlobal, 3, 1)          \
479   F(DeclareEvalFunction, 2, 1)          \
480   F(DeclareEvalVar, 1, 1)               \
481   F(NewSloppyArguments_Generic, 1, 1)   \
482   F(NewStrictArguments, 1, 1)           \
483   F(NewRestParameter, 1, 1)             \
484   F(NewSloppyArguments, 3, 1)           \
485   F(NewClosure, 1, 1)                   \
486   F(NewClosure_Tenured, 1, 1)           \
487   F(NewScriptContext, 2, 1)             \
488   F(NewFunctionContext, 1, 1)           \
489   F(PushModuleContext, 3, 1)            \
490   F(PushWithContext, 3, 1)              \
491   F(PushCatchContext, 4, 1)             \
492   F(PushBlockContext, 2, 1)             \
493   F(DeleteLookupSlot, 1, 1)             \
494   F(LoadLookupSlot, 1, 1)               \
495   F(LoadLookupSlotInsideTypeof, 1, 1)   \
496   F(StoreLookupSlot_Sloppy, 2, 1)       \
497   F(StoreLookupSlot_Strict, 2, 1)
498 
499 #define FOR_EACH_INTRINSIC_SIMD(F)     \
500   F(IsSimdValue, 1, 1)                 \
501   F(CreateFloat32x4, 4, 1)             \
502   F(CreateInt32x4, 4, 1)               \
503   F(CreateUint32x4, 4, 1)              \
504   F(CreateBool32x4, 4, 1)              \
505   F(CreateInt16x8, 8, 1)               \
506   F(CreateUint16x8, 8, 1)              \
507   F(CreateBool16x8, 8, 1)              \
508   F(CreateInt8x16, 16, 1)              \
509   F(CreateUint8x16, 16, 1)             \
510   F(CreateBool8x16, 16, 1)             \
511   F(Float32x4Check, 1, 1)              \
512   F(Float32x4ExtractLane, 2, 1)        \
513   F(Float32x4ReplaceLane, 3, 1)        \
514   F(Float32x4Abs, 1, 1)                \
515   F(Float32x4Neg, 1, 1)                \
516   F(Float32x4Sqrt, 1, 1)               \
517   F(Float32x4RecipApprox, 1, 1)        \
518   F(Float32x4RecipSqrtApprox, 1, 1)    \
519   F(Float32x4Add, 2, 1)                \
520   F(Float32x4Sub, 2, 1)                \
521   F(Float32x4Mul, 2, 1)                \
522   F(Float32x4Div, 2, 1)                \
523   F(Float32x4Min, 2, 1)                \
524   F(Float32x4Max, 2, 1)                \
525   F(Float32x4MinNum, 2, 1)             \
526   F(Float32x4MaxNum, 2, 1)             \
527   F(Float32x4Equal, 2, 1)              \
528   F(Float32x4NotEqual, 2, 1)           \
529   F(Float32x4LessThan, 2, 1)           \
530   F(Float32x4LessThanOrEqual, 2, 1)    \
531   F(Float32x4GreaterThan, 2, 1)        \
532   F(Float32x4GreaterThanOrEqual, 2, 1) \
533   F(Float32x4Select, 3, 1)             \
534   F(Float32x4Swizzle, 5, 1)            \
535   F(Float32x4Shuffle, 6, 1)            \
536   F(Float32x4FromInt32x4, 1, 1)        \
537   F(Float32x4FromUint32x4, 1, 1)       \
538   F(Float32x4FromInt32x4Bits, 1, 1)    \
539   F(Float32x4FromUint32x4Bits, 1, 1)   \
540   F(Float32x4FromInt16x8Bits, 1, 1)    \
541   F(Float32x4FromUint16x8Bits, 1, 1)   \
542   F(Float32x4FromInt8x16Bits, 1, 1)    \
543   F(Float32x4FromUint8x16Bits, 1, 1)   \
544   F(Float32x4Load, 2, 1)               \
545   F(Float32x4Load1, 2, 1)              \
546   F(Float32x4Load2, 2, 1)              \
547   F(Float32x4Load3, 2, 1)              \
548   F(Float32x4Store, 3, 1)              \
549   F(Float32x4Store1, 3, 1)             \
550   F(Float32x4Store2, 3, 1)             \
551   F(Float32x4Store3, 3, 1)             \
552   F(Int32x4Check, 1, 1)                \
553   F(Int32x4ExtractLane, 2, 1)          \
554   F(Int32x4ReplaceLane, 3, 1)          \
555   F(Int32x4Neg, 1, 1)                  \
556   F(Int32x4Add, 2, 1)                  \
557   F(Int32x4Sub, 2, 1)                  \
558   F(Int32x4Mul, 2, 1)                  \
559   F(Int32x4Min, 2, 1)                  \
560   F(Int32x4Max, 2, 1)                  \
561   F(Int32x4And, 2, 1)                  \
562   F(Int32x4Or, 2, 1)                   \
563   F(Int32x4Xor, 2, 1)                  \
564   F(Int32x4Not, 1, 1)                  \
565   F(Int32x4ShiftLeftByScalar, 2, 1)    \
566   F(Int32x4ShiftRightByScalar, 2, 1)   \
567   F(Int32x4Equal, 2, 1)                \
568   F(Int32x4NotEqual, 2, 1)             \
569   F(Int32x4LessThan, 2, 1)             \
570   F(Int32x4LessThanOrEqual, 2, 1)      \
571   F(Int32x4GreaterThan, 2, 1)          \
572   F(Int32x4GreaterThanOrEqual, 2, 1)   \
573   F(Int32x4Select, 3, 1)               \
574   F(Int32x4Swizzle, 5, 1)              \
575   F(Int32x4Shuffle, 6, 1)              \
576   F(Int32x4FromFloat32x4, 1, 1)        \
577   F(Int32x4FromUint32x4, 1, 1)         \
578   F(Int32x4FromFloat32x4Bits, 1, 1)    \
579   F(Int32x4FromUint32x4Bits, 1, 1)     \
580   F(Int32x4FromInt16x8Bits, 1, 1)      \
581   F(Int32x4FromUint16x8Bits, 1, 1)     \
582   F(Int32x4FromInt8x16Bits, 1, 1)      \
583   F(Int32x4FromUint8x16Bits, 1, 1)     \
584   F(Int32x4Load, 2, 1)                 \
585   F(Int32x4Load1, 2, 1)                \
586   F(Int32x4Load2, 2, 1)                \
587   F(Int32x4Load3, 2, 1)                \
588   F(Int32x4Store, 3, 1)                \
589   F(Int32x4Store1, 3, 1)               \
590   F(Int32x4Store2, 3, 1)               \
591   F(Int32x4Store3, 3, 1)               \
592   F(Uint32x4Check, 1, 1)               \
593   F(Uint32x4ExtractLane, 2, 1)         \
594   F(Uint32x4ReplaceLane, 3, 1)         \
595   F(Uint32x4Add, 2, 1)                 \
596   F(Uint32x4Sub, 2, 1)                 \
597   F(Uint32x4Mul, 2, 1)                 \
598   F(Uint32x4Min, 2, 1)                 \
599   F(Uint32x4Max, 2, 1)                 \
600   F(Uint32x4And, 2, 1)                 \
601   F(Uint32x4Or, 2, 1)                  \
602   F(Uint32x4Xor, 2, 1)                 \
603   F(Uint32x4Not, 1, 1)                 \
604   F(Uint32x4ShiftLeftByScalar, 2, 1)   \
605   F(Uint32x4ShiftRightByScalar, 2, 1)  \
606   F(Uint32x4Equal, 2, 1)               \
607   F(Uint32x4NotEqual, 2, 1)            \
608   F(Uint32x4LessThan, 2, 1)            \
609   F(Uint32x4LessThanOrEqual, 2, 1)     \
610   F(Uint32x4GreaterThan, 2, 1)         \
611   F(Uint32x4GreaterThanOrEqual, 2, 1)  \
612   F(Uint32x4Select, 3, 1)              \
613   F(Uint32x4Swizzle, 5, 1)             \
614   F(Uint32x4Shuffle, 6, 1)             \
615   F(Uint32x4FromFloat32x4, 1, 1)       \
616   F(Uint32x4FromInt32x4, 1, 1)         \
617   F(Uint32x4FromFloat32x4Bits, 1, 1)   \
618   F(Uint32x4FromInt32x4Bits, 1, 1)     \
619   F(Uint32x4FromInt16x8Bits, 1, 1)     \
620   F(Uint32x4FromUint16x8Bits, 1, 1)    \
621   F(Uint32x4FromInt8x16Bits, 1, 1)     \
622   F(Uint32x4FromUint8x16Bits, 1, 1)    \
623   F(Uint32x4Load, 2, 1)                \
624   F(Uint32x4Load1, 2, 1)               \
625   F(Uint32x4Load2, 2, 1)               \
626   F(Uint32x4Load3, 2, 1)               \
627   F(Uint32x4Store, 3, 1)               \
628   F(Uint32x4Store1, 3, 1)              \
629   F(Uint32x4Store2, 3, 1)              \
630   F(Uint32x4Store3, 3, 1)              \
631   F(Bool32x4Check, 1, 1)               \
632   F(Bool32x4ExtractLane, 2, 1)         \
633   F(Bool32x4ReplaceLane, 3, 1)         \
634   F(Bool32x4And, 2, 1)                 \
635   F(Bool32x4Or, 2, 1)                  \
636   F(Bool32x4Xor, 2, 1)                 \
637   F(Bool32x4Not, 1, 1)                 \
638   F(Bool32x4AnyTrue, 1, 1)             \
639   F(Bool32x4AllTrue, 1, 1)             \
640   F(Bool32x4Swizzle, 5, 1)             \
641   F(Bool32x4Shuffle, 6, 1)             \
642   F(Bool32x4Equal, 2, 1)               \
643   F(Bool32x4NotEqual, 2, 1)            \
644   F(Int16x8Check, 1, 1)                \
645   F(Int16x8ExtractLane, 2, 1)          \
646   F(Int16x8ReplaceLane, 3, 1)          \
647   F(Int16x8Neg, 1, 1)                  \
648   F(Int16x8Add, 2, 1)                  \
649   F(Int16x8AddSaturate, 2, 1)          \
650   F(Int16x8Sub, 2, 1)                  \
651   F(Int16x8SubSaturate, 2, 1)          \
652   F(Int16x8Mul, 2, 1)                  \
653   F(Int16x8Min, 2, 1)                  \
654   F(Int16x8Max, 2, 1)                  \
655   F(Int16x8And, 2, 1)                  \
656   F(Int16x8Or, 2, 1)                   \
657   F(Int16x8Xor, 2, 1)                  \
658   F(Int16x8Not, 1, 1)                  \
659   F(Int16x8ShiftLeftByScalar, 2, 1)    \
660   F(Int16x8ShiftRightByScalar, 2, 1)   \
661   F(Int16x8Equal, 2, 1)                \
662   F(Int16x8NotEqual, 2, 1)             \
663   F(Int16x8LessThan, 2, 1)             \
664   F(Int16x8LessThanOrEqual, 2, 1)      \
665   F(Int16x8GreaterThan, 2, 1)          \
666   F(Int16x8GreaterThanOrEqual, 2, 1)   \
667   F(Int16x8Select, 3, 1)               \
668   F(Int16x8Swizzle, 9, 1)              \
669   F(Int16x8Shuffle, 10, 1)             \
670   F(Int16x8FromUint16x8, 1, 1)         \
671   F(Int16x8FromFloat32x4Bits, 1, 1)    \
672   F(Int16x8FromInt32x4Bits, 1, 1)      \
673   F(Int16x8FromUint32x4Bits, 1, 1)     \
674   F(Int16x8FromUint16x8Bits, 1, 1)     \
675   F(Int16x8FromInt8x16Bits, 1, 1)      \
676   F(Int16x8FromUint8x16Bits, 1, 1)     \
677   F(Int16x8Load, 2, 1)                 \
678   F(Int16x8Store, 3, 1)                \
679   F(Uint16x8Check, 1, 1)               \
680   F(Uint16x8ExtractLane, 2, 1)         \
681   F(Uint16x8ReplaceLane, 3, 1)         \
682   F(Uint16x8Add, 2, 1)                 \
683   F(Uint16x8AddSaturate, 2, 1)         \
684   F(Uint16x8Sub, 2, 1)                 \
685   F(Uint16x8SubSaturate, 2, 1)         \
686   F(Uint16x8Mul, 2, 1)                 \
687   F(Uint16x8Min, 2, 1)                 \
688   F(Uint16x8Max, 2, 1)                 \
689   F(Uint16x8And, 2, 1)                 \
690   F(Uint16x8Or, 2, 1)                  \
691   F(Uint16x8Xor, 2, 1)                 \
692   F(Uint16x8Not, 1, 1)                 \
693   F(Uint16x8ShiftLeftByScalar, 2, 1)   \
694   F(Uint16x8ShiftRightByScalar, 2, 1)  \
695   F(Uint16x8Equal, 2, 1)               \
696   F(Uint16x8NotEqual, 2, 1)            \
697   F(Uint16x8LessThan, 2, 1)            \
698   F(Uint16x8LessThanOrEqual, 2, 1)     \
699   F(Uint16x8GreaterThan, 2, 1)         \
700   F(Uint16x8GreaterThanOrEqual, 2, 1)  \
701   F(Uint16x8Select, 3, 1)              \
702   F(Uint16x8Swizzle, 9, 1)             \
703   F(Uint16x8Shuffle, 10, 1)            \
704   F(Uint16x8FromInt16x8, 1, 1)         \
705   F(Uint16x8FromFloat32x4Bits, 1, 1)   \
706   F(Uint16x8FromInt32x4Bits, 1, 1)     \
707   F(Uint16x8FromUint32x4Bits, 1, 1)    \
708   F(Uint16x8FromInt16x8Bits, 1, 1)     \
709   F(Uint16x8FromInt8x16Bits, 1, 1)     \
710   F(Uint16x8FromUint8x16Bits, 1, 1)    \
711   F(Uint16x8Load, 2, 1)                \
712   F(Uint16x8Store, 3, 1)               \
713   F(Bool16x8Check, 1, 1)               \
714   F(Bool16x8ExtractLane, 2, 1)         \
715   F(Bool16x8ReplaceLane, 3, 1)         \
716   F(Bool16x8And, 2, 1)                 \
717   F(Bool16x8Or, 2, 1)                  \
718   F(Bool16x8Xor, 2, 1)                 \
719   F(Bool16x8Not, 1, 1)                 \
720   F(Bool16x8AnyTrue, 1, 1)             \
721   F(Bool16x8AllTrue, 1, 1)             \
722   F(Bool16x8Swizzle, 9, 1)             \
723   F(Bool16x8Shuffle, 10, 1)            \
724   F(Bool16x8Equal, 2, 1)               \
725   F(Bool16x8NotEqual, 2, 1)            \
726   F(Int8x16Check, 1, 1)                \
727   F(Int8x16ExtractLane, 2, 1)          \
728   F(Int8x16ReplaceLane, 3, 1)          \
729   F(Int8x16Neg, 1, 1)                  \
730   F(Int8x16Add, 2, 1)                  \
731   F(Int8x16AddSaturate, 2, 1)          \
732   F(Int8x16Sub, 2, 1)                  \
733   F(Int8x16SubSaturate, 2, 1)          \
734   F(Int8x16Mul, 2, 1)                  \
735   F(Int8x16Min, 2, 1)                  \
736   F(Int8x16Max, 2, 1)                  \
737   F(Int8x16And, 2, 1)                  \
738   F(Int8x16Or, 2, 1)                   \
739   F(Int8x16Xor, 2, 1)                  \
740   F(Int8x16Not, 1, 1)                  \
741   F(Int8x16ShiftLeftByScalar, 2, 1)    \
742   F(Int8x16ShiftRightByScalar, 2, 1)   \
743   F(Int8x16Equal, 2, 1)                \
744   F(Int8x16NotEqual, 2, 1)             \
745   F(Int8x16LessThan, 2, 1)             \
746   F(Int8x16LessThanOrEqual, 2, 1)      \
747   F(Int8x16GreaterThan, 2, 1)          \
748   F(Int8x16GreaterThanOrEqual, 2, 1)   \
749   F(Int8x16Select, 3, 1)               \
750   F(Int8x16Swizzle, 17, 1)             \
751   F(Int8x16Shuffle, 18, 1)             \
752   F(Int8x16FromUint8x16, 1, 1)         \
753   F(Int8x16FromFloat32x4Bits, 1, 1)    \
754   F(Int8x16FromInt32x4Bits, 1, 1)      \
755   F(Int8x16FromUint32x4Bits, 1, 1)     \
756   F(Int8x16FromInt16x8Bits, 1, 1)      \
757   F(Int8x16FromUint16x8Bits, 1, 1)     \
758   F(Int8x16FromUint8x16Bits, 1, 1)     \
759   F(Int8x16Load, 2, 1)                 \
760   F(Int8x16Store, 3, 1)                \
761   F(Uint8x16Check, 1, 1)               \
762   F(Uint8x16ExtractLane, 2, 1)         \
763   F(Uint8x16ReplaceLane, 3, 1)         \
764   F(Uint8x16Add, 2, 1)                 \
765   F(Uint8x16AddSaturate, 2, 1)         \
766   F(Uint8x16Sub, 2, 1)                 \
767   F(Uint8x16SubSaturate, 2, 1)         \
768   F(Uint8x16Mul, 2, 1)                 \
769   F(Uint8x16Min, 2, 1)                 \
770   F(Uint8x16Max, 2, 1)                 \
771   F(Uint8x16And, 2, 1)                 \
772   F(Uint8x16Or, 2, 1)                  \
773   F(Uint8x16Xor, 2, 1)                 \
774   F(Uint8x16Not, 1, 1)                 \
775   F(Uint8x16ShiftLeftByScalar, 2, 1)   \
776   F(Uint8x16ShiftRightByScalar, 2, 1)  \
777   F(Uint8x16Equal, 2, 1)               \
778   F(Uint8x16NotEqual, 2, 1)            \
779   F(Uint8x16LessThan, 2, 1)            \
780   F(Uint8x16LessThanOrEqual, 2, 1)     \
781   F(Uint8x16GreaterThan, 2, 1)         \
782   F(Uint8x16GreaterThanOrEqual, 2, 1)  \
783   F(Uint8x16Select, 3, 1)              \
784   F(Uint8x16Swizzle, 17, 1)            \
785   F(Uint8x16Shuffle, 18, 1)            \
786   F(Uint8x16FromInt8x16, 1, 1)         \
787   F(Uint8x16FromFloat32x4Bits, 1, 1)   \
788   F(Uint8x16FromInt32x4Bits, 1, 1)     \
789   F(Uint8x16FromUint32x4Bits, 1, 1)    \
790   F(Uint8x16FromInt16x8Bits, 1, 1)     \
791   F(Uint8x16FromUint16x8Bits, 1, 1)    \
792   F(Uint8x16FromInt8x16Bits, 1, 1)     \
793   F(Uint8x16Load, 2, 1)                \
794   F(Uint8x16Store, 3, 1)               \
795   F(Bool8x16Check, 1, 1)               \
796   F(Bool8x16ExtractLane, 2, 1)         \
797   F(Bool8x16ReplaceLane, 3, 1)         \
798   F(Bool8x16And, 2, 1)                 \
799   F(Bool8x16Or, 2, 1)                  \
800   F(Bool8x16Xor, 2, 1)                 \
801   F(Bool8x16Not, 1, 1)                 \
802   F(Bool8x16AnyTrue, 1, 1)             \
803   F(Bool8x16AllTrue, 1, 1)             \
804   F(Bool8x16Swizzle, 17, 1)            \
805   F(Bool8x16Shuffle, 18, 1)            \
806   F(Bool8x16Equal, 2, 1)               \
807   F(Bool8x16NotEqual, 2, 1)
808 
809 #define FOR_EACH_INTRINSIC_STRINGS(F)     \
810   F(StringReplaceOneCharWithString, 3, 1) \
811   F(StringIndexOf, 3, 1)                  \
812   F(StringLastIndexOf, 2, 1)              \
813   F(SubString, 3, 1)                      \
814   F(StringAdd, 2, 1)                      \
815   F(InternalizeString, 1, 1)              \
816   F(StringCharCodeAtRT, 2, 1)             \
817   F(StringCompare, 2, 1)                  \
818   F(StringBuilderConcat, 3, 1)            \
819   F(StringBuilderJoin, 3, 1)              \
820   F(SparseJoinWithSeparator, 3, 1)        \
821   F(StringToArray, 2, 1)                  \
822   F(StringToLowerCase, 1, 1)              \
823   F(StringToUpperCase, 1, 1)              \
824   F(StringLessThan, 2, 1)                 \
825   F(StringLessThanOrEqual, 2, 1)          \
826   F(StringGreaterThan, 2, 1)              \
827   F(StringGreaterThanOrEqual, 2, 1)       \
828   F(StringEqual, 2, 1)                    \
829   F(StringNotEqual, 2, 1)                 \
830   F(FlattenString, 1, 1)                  \
831   F(StringCharFromCode, 1, 1)             \
832   F(ExternalStringGetChar, 2, 1)          \
833   F(StringCharCodeAt, 2, 1)
834 
835 #define FOR_EACH_INTRINSIC_SYMBOL(F) \
836   F(CreateSymbol, 1, 1)              \
837   F(CreatePrivateSymbol, 1, 1)       \
838   F(SymbolDescription, 1, 1)         \
839   F(SymbolDescriptiveString, 1, 1)   \
840   F(SymbolRegistry, 0, 1)            \
841   F(SymbolIsPrivate, 1, 1)
842 
843 #define FOR_EACH_INTRINSIC_TEST(F)            \
844   F(ConstructDouble, 2, 1)                    \
845   F(DeoptimizeFunction, 1, 1)                 \
846   F(DeoptimizeNow, 0, 1)                      \
847   F(RunningInSimulator, 0, 1)                 \
848   F(IsConcurrentRecompilationSupported, 0, 1) \
849   F(OptimizeFunctionOnNextCall, -1, 1)        \
850   F(InterpretFunctionOnNextCall, 1, 1)        \
851   F(BaselineFunctionOnNextCall, 1, 1)         \
852   F(OptimizeOsr, -1, 1)                       \
853   F(NeverOptimizeFunction, 1, 1)              \
854   F(GetOptimizationStatus, -1, 1)             \
855   F(UnblockConcurrentRecompilation, 0, 1)     \
856   F(GetOptimizationCount, 1, 1)               \
857   F(GetUndetectable, 0, 1)                    \
858   F(GetCallable, 0, 1)                        \
859   F(ClearFunctionTypeFeedback, 1, 1)          \
860   F(CheckWasmWrapperElision, 2, 1)            \
861   F(NotifyContextDisposed, 0, 1)              \
862   F(SetAllocationTimeout, -1 /* 2 || 3 */, 1) \
863   F(DebugPrint, 1, 1)                         \
864   F(DebugTrace, 0, 1)                         \
865   F(GetExceptionDetails, 1, 1)                \
866   F(GlobalPrint, 1, 1)                        \
867   F(SystemBreak, 0, 1)                        \
868   F(SetFlags, 1, 1)                           \
869   F(Abort, 1, 1)                              \
870   F(AbortJS, 1, 1)                            \
871   F(NativeScriptsCount, 0, 1)                 \
872   F(GetV8Version, 0, 1)                       \
873   F(DisassembleFunction, 1, 1)                \
874   F(TraceEnter, 0, 1)                         \
875   F(TraceExit, 1, 1)                          \
876   F(TraceTailCall, 0, 1)                      \
877   F(HaveSameMap, 2, 1)                        \
878   F(InNewSpace, 1, 1)                         \
879   F(HasFastSmiElements, 1, 1)                 \
880   F(HasFastObjectElements, 1, 1)              \
881   F(HasFastSmiOrObjectElements, 1, 1)         \
882   F(HasFastDoubleElements, 1, 1)              \
883   F(HasFastHoleyElements, 1, 1)               \
884   F(HasDictionaryElements, 1, 1)              \
885   F(HasSloppyArgumentsElements, 1, 1)         \
886   F(HasFixedTypedArrayElements, 1, 1)         \
887   F(HasFastProperties, 1, 1)                  \
888   F(HasFixedUint8Elements, 1, 1)              \
889   F(HasFixedInt8Elements, 1, 1)               \
890   F(HasFixedUint16Elements, 1, 1)             \
891   F(HasFixedInt16Elements, 1, 1)              \
892   F(HasFixedUint32Elements, 1, 1)             \
893   F(HasFixedInt32Elements, 1, 1)              \
894   F(HasFixedFloat32Elements, 1, 1)            \
895   F(HasFixedFloat64Elements, 1, 1)            \
896   F(HasFixedUint8ClampedElements, 1, 1)       \
897   F(SpeciesProtector, 0, 1)                   \
898   F(SerializeWasmModule, 1, 1)                \
899   F(DeserializeWasmModule, 2, 1)              \
900   F(IsAsmWasmCode, 1, 1)                      \
901   F(IsNotAsmWasmCode, 1, 1)                   \
902   F(ValidateWasmInstancesChain, 2, 1)         \
903   F(ValidateWasmModuleState, 1, 1)            \
904   F(ValidateWasmOrphanedInstance, 1, 1)
905 
906 #define FOR_EACH_INTRINSIC_TYPEDARRAY(F)     \
907   F(ArrayBufferGetByteLength, 1, 1)          \
908   F(ArrayBufferSliceImpl, 4, 1)              \
909   F(ArrayBufferNeuter, 1, 1)                 \
910   F(TypedArrayInitialize, 6, 1)              \
911   F(TypedArrayInitializeFromArrayLike, 4, 1) \
912   F(ArrayBufferViewGetByteLength, 1, 1)      \
913   F(ArrayBufferViewGetByteOffset, 1, 1)      \
914   F(TypedArrayGetLength, 1, 1)               \
915   F(TypedArrayGetBuffer, 1, 1)               \
916   F(TypedArraySetFastCases, 3, 1)            \
917   F(TypedArrayMaxSizeInHeap, 0, 1)           \
918   F(IsTypedArray, 1, 1)                      \
919   F(IsSharedTypedArray, 1, 1)                \
920   F(IsSharedIntegerTypedArray, 1, 1)         \
921   F(IsSharedInteger32TypedArray, 1, 1)
922 
923 #define FOR_EACH_INTRINSIC_WASM(F) \
924   F(WasmGrowMemory, 1, 1)          \
925   F(WasmMemorySize, 0, 1)          \
926   F(WasmThrowTypeError, 0, 1)      \
927   F(WasmThrow, 2, 1)               \
928   F(WasmGetCaughtExceptionValue, 1, 1)
929 
930 #define FOR_EACH_INTRINSIC_RETURN_PAIR(F) \
931   F(LoadLookupSlotForCall, 1, 2)
932 
933 #define FOR_EACH_INTRINSIC_RETURN_TRIPLE(F) \
934   F(ForInPrepare, 1, 3)
935 
936 // Most intrinsics are implemented in the runtime/ directory, but ICs are
937 // implemented in ic.cc for now.
938 #define FOR_EACH_INTRINSIC_IC(F)             \
939   F(BinaryOpIC_Miss, 2, 1)                   \
940   F(BinaryOpIC_MissWithAllocationSite, 3, 1) \
941   F(CallIC_Miss, 3, 1)                       \
942   F(CompareIC_Miss, 3, 1)                    \
943   F(ElementsTransitionAndStoreIC_Miss, 6, 1) \
944   F(KeyedLoadIC_Miss, 4, 1)                  \
945   F(KeyedLoadIC_MissFromStubFailure, 4, 1)   \
946   F(KeyedStoreIC_Miss, 5, 1)                 \
947   F(KeyedStoreIC_Slow, 5, 1)                 \
948   F(LoadElementWithInterceptor, 2, 1)        \
949   F(LoadGlobalIC_Miss, 2, 1)                 \
950   F(LoadGlobalIC_Slow, 2, 1)                 \
951   F(LoadIC_Miss, 4, 1)                       \
952   F(LoadPropertyWithInterceptor, 3, 1)       \
953   F(LoadPropertyWithInterceptorOnly, 3, 1)   \
954   F(StoreCallbackProperty, 6, 1)             \
955   F(StoreIC_Miss, 5, 1)                      \
956   F(StorePropertyWithInterceptor, 3, 1)      \
957   F(ToBooleanIC_Miss, 1, 1)                  \
958   F(Unreachable, 0, 1)
959 
960 #define FOR_EACH_INTRINSIC_RETURN_OBJECT(F) \
961   FOR_EACH_INTRINSIC_IC(F)                  \
962   FOR_EACH_INTRINSIC_ARRAY(F)               \
963   FOR_EACH_INTRINSIC_ATOMICS(F)             \
964   FOR_EACH_INTRINSIC_CLASSES(F)             \
965   FOR_EACH_INTRINSIC_COLLECTIONS(F)         \
966   FOR_EACH_INTRINSIC_COMPILER(F)            \
967   FOR_EACH_INTRINSIC_DATE(F)                \
968   FOR_EACH_INTRINSIC_DEBUG(F)               \
969   FOR_EACH_INTRINSIC_ERROR(F)               \
970   FOR_EACH_INTRINSIC_FORIN(F)               \
971   FOR_EACH_INTRINSIC_INTERPRETER(F)         \
972   FOR_EACH_INTRINSIC_FUNCTION(F)            \
973   FOR_EACH_INTRINSIC_GENERATOR(F)           \
974   FOR_EACH_INTRINSIC_I18N(F)                \
975   FOR_EACH_INTRINSIC_INTERNAL(F)            \
976   FOR_EACH_INTRINSIC_LITERALS(F)            \
977   FOR_EACH_INTRINSIC_LIVEEDIT(F)            \
978   FOR_EACH_INTRINSIC_MATHS(F)               \
979   FOR_EACH_INTRINSIC_MODULE(F)              \
980   FOR_EACH_INTRINSIC_NUMBERS(F)             \
981   FOR_EACH_INTRINSIC_OBJECT(F)              \
982   FOR_EACH_INTRINSIC_OPERATORS(F)           \
983   FOR_EACH_INTRINSIC_PROXY(F)               \
984   FOR_EACH_INTRINSIC_REGEXP(F)              \
985   FOR_EACH_INTRINSIC_SCOPES(F)              \
986   FOR_EACH_INTRINSIC_SIMD(F)                \
987   FOR_EACH_INTRINSIC_STRINGS(F)             \
988   FOR_EACH_INTRINSIC_SYMBOL(F)              \
989   FOR_EACH_INTRINSIC_TEST(F)                \
990   FOR_EACH_INTRINSIC_TYPEDARRAY(F)          \
991   FOR_EACH_INTRINSIC_WASM(F)
992 
993 // FOR_EACH_INTRINSIC defines the list of all intrinsics, coming in 2 flavors,
994 // either returning an object or a pair.
995 #define FOR_EACH_INTRINSIC(F)         \
996   FOR_EACH_INTRINSIC_RETURN_TRIPLE(F) \
997   FOR_EACH_INTRINSIC_RETURN_PAIR(F)   \
998   FOR_EACH_INTRINSIC_RETURN_OBJECT(F)
999 
1000 
1001 #define F(name, nargs, ressize)                                 \
1002   Object* Runtime_##name(int args_length, Object** args_object, \
1003                          Isolate* isolate);
FOR_EACH_INTRINSIC_RETURN_OBJECT(F)1004 FOR_EACH_INTRINSIC_RETURN_OBJECT(F)
1005 #undef F
1006 
1007 //---------------------------------------------------------------------------
1008 // Runtime provides access to all C++ runtime functions.
1009 
1010 class Runtime : public AllStatic {
1011  public:
1012   enum FunctionId {
1013 #define F(name, nargs, ressize) k##name,
1014 #define I(name, nargs, ressize) kInline##name,
1015   FOR_EACH_INTRINSIC(F)
1016   FOR_EACH_INTRINSIC(I)
1017 #undef I
1018 #undef F
1019     kNumFunctions,
1020   };
1021 
1022   enum IntrinsicType { RUNTIME, INLINE };
1023 
1024   // Intrinsic function descriptor.
1025   struct Function {
1026     FunctionId function_id;
1027     IntrinsicType intrinsic_type;
1028     // The JS name of the function.
1029     const char* name;
1030 
1031     // For RUNTIME functions, this is the C++ entry point.
1032     // For INLINE functions this is the C++ entry point of the fall back.
1033     Address entry;
1034 
1035     // The number of arguments expected. nargs is -1 if the function takes
1036     // a variable number of arguments.
1037     int8_t nargs;
1038     // Size of result.  Most functions return a single pointer, size 1.
1039     int8_t result_size;
1040   };
1041 
1042   static const int kNotFound = -1;
1043 
1044   // Get the intrinsic function with the given name.
1045   static const Function* FunctionForName(const unsigned char* name, int length);
1046 
1047   // Get the intrinsic function with the given FunctionId.
1048   V8_EXPORT_PRIVATE static const Function* FunctionForId(FunctionId id);
1049 
1050   // Get the intrinsic function with the given function entry address.
1051   static const Function* FunctionForEntry(Address ref);
1052 
1053   // Get the runtime intrinsic function table.
1054   static const Function* RuntimeFunctionTable(Isolate* isolate);
1055 
1056   MUST_USE_RESULT static Maybe<bool> DeleteObjectProperty(
1057       Isolate* isolate, Handle<JSReceiver> receiver, Handle<Object> key,
1058       LanguageMode language_mode);
1059 
1060   MUST_USE_RESULT static MaybeHandle<Object> SetObjectProperty(
1061       Isolate* isolate, Handle<Object> object, Handle<Object> key,
1062       Handle<Object> value, LanguageMode language_mode);
1063 
1064   MUST_USE_RESULT static MaybeHandle<Object> GetObjectProperty(
1065       Isolate* isolate, Handle<Object> object, Handle<Object> key,
1066       bool* is_found_out = nullptr);
1067 
1068   enum TypedArrayId {
1069     // arrayIds below should be synchronized with typedarray.js natives.
1070     ARRAY_ID_UINT8 = 1,
1071     ARRAY_ID_INT8 = 2,
1072     ARRAY_ID_UINT16 = 3,
1073     ARRAY_ID_INT16 = 4,
1074     ARRAY_ID_UINT32 = 5,
1075     ARRAY_ID_INT32 = 6,
1076     ARRAY_ID_FLOAT32 = 7,
1077     ARRAY_ID_FLOAT64 = 8,
1078     ARRAY_ID_UINT8_CLAMPED = 9,
1079     ARRAY_ID_FIRST = ARRAY_ID_UINT8,
1080     ARRAY_ID_LAST = ARRAY_ID_UINT8_CLAMPED
1081   };
1082 
1083   static void ArrayIdToTypeAndSize(int array_id, ExternalArrayType* type,
1084                                    ElementsKind* fixed_elements_kind,
1085                                    size_t* element_size);
1086 
1087   static MaybeHandle<JSArray> GetInternalProperties(Isolate* isolate,
1088                                                     Handle<Object>);
1089 };
1090 
1091 
1092 class RuntimeState {
1093  public:
to_upper_mapping()1094   unibrow::Mapping<unibrow::ToUppercase, 128>* to_upper_mapping() {
1095     return &to_upper_mapping_;
1096   }
to_lower_mapping()1097   unibrow::Mapping<unibrow::ToLowercase, 128>* to_lower_mapping() {
1098     return &to_lower_mapping_;
1099   }
1100 
redirected_intrinsic_functions()1101   Runtime::Function* redirected_intrinsic_functions() {
1102     return redirected_intrinsic_functions_.get();
1103   }
1104 
set_redirected_intrinsic_functions(Runtime::Function * redirected_intrinsic_functions)1105   void set_redirected_intrinsic_functions(
1106       Runtime::Function* redirected_intrinsic_functions) {
1107     redirected_intrinsic_functions_.reset(redirected_intrinsic_functions);
1108   }
1109 
1110  private:
RuntimeState()1111   RuntimeState() {}
1112   unibrow::Mapping<unibrow::ToUppercase, 128> to_upper_mapping_;
1113   unibrow::Mapping<unibrow::ToLowercase, 128> to_lower_mapping_;
1114 
1115   std::unique_ptr<Runtime::Function[]> redirected_intrinsic_functions_;
1116 
1117   friend class Isolate;
1118   friend class Runtime;
1119 
1120   DISALLOW_COPY_AND_ASSIGN(RuntimeState);
1121 };
1122 
1123 V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream&, Runtime::FunctionId);
1124 
1125 //---------------------------------------------------------------------------
1126 // Constants used by interface to runtime functions.
1127 
1128 class AllocateDoubleAlignFlag : public BitField<bool, 0, 1> {};
1129 class AllocateTargetSpace : public BitField<AllocationSpace, 1, 3> {};
1130 
1131 class DeclareGlobalsEvalFlag : public BitField<bool, 0, 1> {};
1132 class DeclareGlobalsNativeFlag : public BitField<bool, 1, 1> {};
1133 STATIC_ASSERT(LANGUAGE_END == 2);
1134 class DeclareGlobalsLanguageMode : public BitField<LanguageMode, 2, 1> {};
1135 
1136 }  // namespace internal
1137 }  // namespace v8
1138 
1139 #endif  // V8_RUNTIME_RUNTIME_H_
1140