V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
runtime.h
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 exposed in JavaScript via:
21 // * %#name, which is always a runtime call.
22 // * (optionally) %_#name, which can be inlined or just a runtime call, the
23 // compiler in 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 // Entries have the form F(name, number of arguments, number of values):
35 // A variable number of arguments is specified by a -1, additional restrictions
36 // are specified by inline comments. To declare only the runtime version (no
37 // inline), use the F macro below. To declare the runtime version and the inline
38 // version simultaneously, use the I macro below.
39 
40 #define FOR_EACH_INTRINSIC_ARRAY(F, I) \
41  F(ArrayIncludes_Slow, 3, 1) \
42  F(ArrayIndexOf, 3, 1) \
43  F(ArrayIsArray, 1, 1) \
44  F(ArraySpeciesConstructor, 1, 1) \
45  F(EstimateNumberOfElements, 1, 1) \
46  F(GetArrayKeys, 2, 1) \
47  F(GrowArrayElements, 2, 1) \
48  F(HasComplexElements, 1, 1) \
49  I(IsArray, 1, 1) \
50  F(NewArray, -1 /* >= 3 */, 1) \
51  F(NormalizeElements, 1, 1) \
52  F(PrepareElementsForSort, 2, 1) \
53  F(TransitionElementsKind, 2, 1) \
54  F(TransitionElementsKindWithKind, 2, 1) \
55  F(TrySliceSimpleNonFastElements, 3, 1)
56 
57 #define FOR_EACH_INTRINSIC_ATOMICS(F, I) \
58  F(AtomicsLoad64, 2, 1) \
59  F(AtomicsStore64, 3, 1) \
60  F(AtomicsAdd, 3, 1) \
61  F(AtomicsAnd, 3, 1) \
62  F(AtomicsCompareExchange, 4, 1) \
63  F(AtomicsExchange, 3, 1) \
64  F(AtomicsNumWaitersForTesting, 2, 1) \
65  F(AtomicsOr, 3, 1) \
66  F(AtomicsSub, 3, 1) \
67  F(AtomicsXor, 3, 1) \
68  F(SetAllowAtomicsWait, 1, 1)
69 
70 #define FOR_EACH_INTRINSIC_BIGINT(F, I) \
71  F(BigIntBinaryOp, 3, 1) \
72  F(BigIntCompareToBigInt, 3, 1) \
73  F(BigIntCompareToNumber, 3, 1) \
74  F(BigIntCompareToString, 3, 1) \
75  F(BigIntEqualToBigInt, 2, 1) \
76  F(BigIntEqualToNumber, 2, 1) \
77  F(BigIntEqualToString, 2, 1) \
78  F(BigIntToBoolean, 1, 1) \
79  F(BigIntToNumber, 1, 1) \
80  F(BigIntUnaryOp, 2, 1) \
81  F(ToBigInt, 1, 1)
82 
83 #define FOR_EACH_INTRINSIC_CLASSES(F, I) \
84  F(DefineClass, -1 /* >= 3 */, 1) \
85  F(HomeObjectSymbol, 0, 1) \
86  F(LoadFromSuper, 3, 1) \
87  F(LoadKeyedFromSuper, 3, 1) \
88  F(StoreKeyedToSuper_Sloppy, 4, 1) \
89  F(StoreKeyedToSuper_Strict, 4, 1) \
90  F(StoreToSuper_Sloppy, 4, 1) \
91  F(StoreToSuper_Strict, 4, 1) \
92  F(ThrowConstructorNonCallableError, 1, 1) \
93  F(ThrowNotSuperConstructor, 2, 1) \
94  F(ThrowStaticPrototypeError, 0, 1) \
95  F(ThrowSuperAlreadyCalledError, 0, 1) \
96  F(ThrowSuperNotCalled, 0, 1) \
97  F(ThrowUnsupportedSuperError, 0, 1)
98 
99 #define FOR_EACH_INTRINSIC_COLLECTIONS(F, I) \
100  F(MapGrow, 1, 1) \
101  F(MapShrink, 1, 1) \
102  F(SetGrow, 1, 1) \
103  F(SetShrink, 1, 1) \
104  F(TheHole, 0, 1) \
105  F(WeakCollectionDelete, 3, 1) \
106  F(WeakCollectionSet, 4, 1)
107 
108 #define FOR_EACH_INTRINSIC_COMPILER(F, I) \
109  F(CompileForOnStackReplacement, 1, 1) \
110  F(CompileLazy, 1, 1) \
111  F(CompileOptimized_Concurrent, 1, 1) \
112  F(CompileOptimized_NotConcurrent, 1, 1) \
113  F(EvictOptimizedCodeSlot, 1, 1) \
114  F(FunctionFirstExecution, 1, 1) \
115  F(InstantiateAsmJs, 4, 1) \
116  F(NotifyDeoptimized, 0, 1) \
117  F(ResolvePossiblyDirectEval, 6, 1)
118 
119 #define FOR_EACH_INTRINSIC_DATE(F, I) F(DateCurrentTime, 0, 1)
120 
121 #define FOR_EACH_INTRINSIC_DEBUG(F, I) \
122  F(ClearStepping, 0, 1) \
123  F(CollectGarbage, 1, 1) \
124  F(DebugBreakAtEntry, 1, 1) \
125  F(DebugCollectCoverage, 0, 1) \
126  F(DebugGetLoadedScriptIds, 0, 1) \
127  F(DebugOnFunctionCall, 2, 1) \
128  F(DebugPopPromise, 0, 1) \
129  F(DebugPrepareStepInSuspendedGenerator, 0, 1) \
130  F(DebugPushPromise, 1, 1) \
131  F(DebugAsyncFunctionEntered, 1, 1) \
132  F(DebugAsyncFunctionFinished, 2, 1) \
133  F(DebugAsyncFunctionSuspended, 1, 1) \
134  F(DebugToggleBlockCoverage, 1, 1) \
135  F(DebugTogglePreciseCoverage, 1, 1) \
136  F(FunctionGetInferredName, 1, 1) \
137  F(GetBreakLocations, 1, 1) \
138  F(GetGeneratorScopeCount, 1, 1) \
139  F(GetGeneratorScopeDetails, 2, 1) \
140  F(GetHeapUsage, 0, 1) \
141  F(HandleDebuggerStatement, 0, 1) \
142  F(IncBlockCounter, 2, 1) \
143  F(IsBreakOnException, 1, 1) \
144  F(ScheduleBreak, 0, 1) \
145  F(ScriptLocationFromLine2, 4, 1) \
146  F(SetGeneratorScopeVariableValue, 4, 1) \
147  F(LiveEditPatchScript, 2, 1)
148 
149 #define FOR_EACH_INTRINSIC_FORIN(F, I) \
150  F(ForInEnumerate, 1, 1) \
151  F(ForInHasProperty, 2, 1)
152 
153 #ifdef V8_TRACE_IGNITION
154 #define FOR_EACH_INTRINSIC_INTERPRETER_TRACE(F, I) \
155  F(InterpreterTraceBytecodeEntry, 3, 1) \
156  F(InterpreterTraceBytecodeExit, 3, 1)
157 #else
158 #define FOR_EACH_INTRINSIC_INTERPRETER_TRACE(F, I)
159 #endif
160 
161 #ifdef V8_TRACE_FEEDBACK_UPDATES
162 #define FOR_EACH_INTRINSIC_INTERPRETER_TRACE_FEEDBACK(F, I) \
163  F(InterpreterTraceUpdateFeedback, 3, 1)
164 #else
165 #define FOR_EACH_INTRINSIC_INTERPRETER_TRACE_FEEDBACK(F, I)
166 #endif
167 
168 #define FOR_EACH_INTRINSIC_INTERPRETER(F, I) \
169  FOR_EACH_INTRINSIC_INTERPRETER_TRACE(F, I) \
170  FOR_EACH_INTRINSIC_INTERPRETER_TRACE_FEEDBACK(F, I)
171 
172 #define FOR_EACH_INTRINSIC_FUNCTION(F, I) \
173  I(Call, -1 /* >= 2 */, 1) \
174  F(FunctionGetScriptSource, 1, 1) \
175  F(FunctionGetScriptId, 1, 1) \
176  F(FunctionGetScriptSourcePosition, 1, 1) \
177  F(FunctionGetSourceCode, 1, 1) \
178  F(FunctionIsAPIFunction, 1, 1) \
179  F(IsFunction, 1, 1) \
180  F(SetNativeFlag, 1, 1)
181 
182 #define FOR_EACH_INTRINSIC_GENERATOR(F, I) \
183  I(AsyncFunctionAwaitCaught, 2, 1) \
184  I(AsyncFunctionAwaitUncaught, 2, 1) \
185  I(AsyncFunctionEnter, 2, 1) \
186  I(AsyncFunctionReject, 3, 1) \
187  I(AsyncFunctionResolve, 3, 1) \
188  I(AsyncGeneratorAwaitCaught, 2, 1) \
189  I(AsyncGeneratorAwaitUncaught, 2, 1) \
190  F(AsyncGeneratorHasCatchHandlerForPC, 1, 1) \
191  I(AsyncGeneratorReject, 2, 1) \
192  I(AsyncGeneratorResolve, 3, 1) \
193  I(AsyncGeneratorYield, 3, 1) \
194  I(CreateJSGeneratorObject, 2, 1) \
195  I(GeneratorClose, 1, 1) \
196  F(GeneratorGetFunction, 1, 1) \
197  I(GeneratorGetResumeMode, 1, 1)
198 
199 #ifdef V8_INTL_SUPPORT
200 #define FOR_EACH_INTRINSIC_INTL(F, I) \
201  F(CanonicalizeLanguageTag, 1, 1) \
202  F(FormatList, 2, 1) \
203  F(FormatListToParts, 2, 1) \
204  F(GetDefaultICULocale, 0, 1) \
205  F(StringToLowerCaseIntl, 1, 1) \
206  F(StringToUpperCaseIntl, 1, 1) // End of macro.
207 #else
208 #define FOR_EACH_INTRINSIC_INTL(F, I)
209 #endif // V8_INTL_SUPPORT
210 
211 #define FOR_EACH_INTRINSIC_INTERNAL(F, I) \
212  F(AllocateInNewSpace, 1, 1) \
213  F(AllocateInTargetSpace, 2, 1) \
214  F(AllocateSeqOneByteString, 1, 1) \
215  F(AllocateSeqTwoByteString, 1, 1) \
216  F(AllowDynamicFunction, 1, 1) \
217  F(CheckIsBootstrapping, 0, 1) \
218  I(CreateAsyncFromSyncIterator, 1, 1) \
219  F(CreateListFromArrayLike, 1, 1) \
220  F(CreateTemplateObject, 1, 1) \
221  F(ExportFromRuntime, 1, 1) \
222  F(GetAndResetRuntimeCallStats, -1 /* <= 2 */, 1) \
223  F(IncrementUseCounter, 1, 1) \
224  F(InstallToContext, 1, 1) \
225  F(Interrupt, 0, 1) \
226  F(NewReferenceError, 2, 1) \
227  F(NewSyntaxError, 2, 1) \
228  F(NewTypeError, 2, 1) \
229  F(OrdinaryHasInstance, 2, 1) \
230  F(PromoteScheduledException, 0, 1) \
231  F(ReportMessage, 1, 1) \
232  F(ReThrow, 1, 1) \
233  F(RunMicrotaskCallback, 2, 1) \
234  F(RunMicrotasks, 0, 1) \
235  F(StackGuard, 0, 1) \
236  F(Throw, 1, 1) \
237  F(ThrowApplyNonFunction, 1, 1) \
238  F(ThrowCalledNonCallable, 1, 1) \
239  F(ThrowConstructedNonConstructable, 1, 1) \
240  F(ThrowConstructorReturnedNonObject, 0, 1) \
241  F(ThrowInvalidStringLength, 0, 1) \
242  F(ThrowInvalidTypedArrayAlignment, 2, 1) \
243  F(ThrowIteratorError, 1, 1) \
244  F(ThrowIteratorResultNotAnObject, 1, 1) \
245  F(ThrowNotConstructor, 1, 1) \
246  F(ThrowRangeError, -1 /* >= 1 */, 1) \
247  F(ThrowReferenceError, 1, 1) \
248  F(ThrowStackOverflow, 0, 1) \
249  F(ThrowSymbolAsyncIteratorInvalid, 0, 1) \
250  F(ThrowSymbolIteratorInvalid, 0, 1) \
251  F(ThrowThrowMethodMissing, 0, 1) \
252  F(ThrowTypeError, -1 /* >= 1 */, 1) \
253  F(Typeof, 1, 1) \
254  F(UnwindAndFindExceptionHandler, 0, 1) \
255  F(WeakFactoryCleanupJob, 1, 1)
256 
257 #define FOR_EACH_INTRINSIC_LITERALS(F, I) \
258  F(CreateArrayLiteral, 4, 1) \
259  F(CreateArrayLiteralWithoutAllocationSite, 2, 1) \
260  F(CreateObjectLiteral, 4, 1) \
261  F(CreateObjectLiteralWithoutAllocationSite, 2, 1) \
262  F(CreateRegExpLiteral, 4, 1)
263 
264 #define FOR_EACH_INTRINSIC_MODULE(F, I) \
265  F(DynamicImportCall, 2, 1) \
266  I(GetImportMetaObject, 0, 1) \
267  F(GetModuleNamespace, 1, 1)
268 
269 #define FOR_EACH_INTRINSIC_NUMBERS(F, I) \
270  F(GetHoleNaNLower, 0, 1) \
271  F(GetHoleNaNUpper, 0, 1) \
272  I(IsSmi, 1, 1) \
273  F(IsValidSmi, 1, 1) \
274  F(MaxSmi, 0, 1) \
275  F(NumberToString, 1, 1) \
276  F(SmiLexicographicCompare, 2, 1) \
277  F(StringParseFloat, 1, 1) \
278  F(StringParseInt, 2, 1) \
279  F(StringToNumber, 1, 1)
280 
281 #define FOR_EACH_INTRINSIC_OBJECT(F, I) \
282  F(AddDictionaryProperty, 3, 1) \
283  F(AddElement, 3, 1) \
284  F(AddNamedProperty, 4, 1) \
285  F(AddPrivateField, 3, 1) \
286  F(AllocateHeapNumber, 0, 1) \
287  F(ClassOf, 1, 1) \
288  F(CollectTypeProfile, 3, 1) \
289  F(CompleteInobjectSlackTrackingForMap, 1, 1) \
290  F(CopyDataProperties, 2, 1) \
291  F(CopyDataPropertiesWithExcludedProperties, -1 /* >= 1 */, 1) \
292  I(CreateDataProperty, 3, 1) \
293  I(CreateIterResultObject, 2, 1) \
294  F(DefineAccessorPropertyUnchecked, 5, 1) \
295  F(DefineDataPropertyInLiteral, 6, 1) \
296  F(DefineGetterPropertyUnchecked, 4, 1) \
297  F(DefineMethodsInternal, 3, 1) \
298  F(DefineSetterPropertyUnchecked, 4, 1) \
299  F(DeleteProperty, 3, 1) \
300  F(GetFunctionName, 1, 1) \
301  F(GetOwnPropertyDescriptor, 2, 1) \
302  F(GetOwnPropertyKeys, 2, 1) \
303  F(GetProperty, 2, 1) \
304  F(HasFastPackedElements, 1, 1) \
305  F(HasInPrototypeChain, 2, 1) \
306  I(HasProperty, 2, 1) \
307  F(InternalSetPrototype, 2, 1) \
308  I(IsJSReceiver, 1, 1) \
309  F(NewObject, 2, 1) \
310  F(ObjectCreate, 2, 1) \
311  F(ObjectEntries, 1, 1) \
312  F(ObjectEntriesSkipFastPath, 1, 1) \
313  F(ObjectHasOwnProperty, 2, 1) \
314  F(ObjectKeys, 1, 1) \
315  F(ObjectGetOwnPropertyNames, 1, 1) \
316  F(ObjectGetOwnPropertyNamesTryFast, 1, 1) \
317  F(ObjectValues, 1, 1) \
318  F(ObjectValuesSkipFastPath, 1, 1) \
319  F(OptimizeObjectForAddingMultipleProperties, 2, 1) \
320  F(PerformSideEffectCheckForObject, 1, 1) \
321  F(SetDataProperties, 2, 1) \
322  F(SetKeyedProperty, 4, 1) \
323  F(SetNamedProperty, 4, 1) \
324  F(StoreDataPropertyInLiteral, 3, 1) \
325  F(ShrinkPropertyDictionary, 1, 1) \
326  F(ToFastProperties, 1, 1) \
327  I(ToLength, 1, 1) \
328  F(ToName, 1, 1) \
329  I(ToNumber, 1, 1) \
330  F(ToNumeric, 1, 1) \
331  I(ToObject, 1, 1) \
332  I(ToString, 1, 1) \
333  F(TryMigrateInstance, 1, 1)
334 
335 #define FOR_EACH_INTRINSIC_OPERATORS(F, I) \
336  F(Add, 2, 1) \
337  F(Equal, 2, 1) \
338  F(GreaterThan, 2, 1) \
339  F(GreaterThanOrEqual, 2, 1) \
340  F(LessThan, 2, 1) \
341  F(LessThanOrEqual, 2, 1) \
342  F(NotEqual, 2, 1) \
343  F(StrictEqual, 2, 1) \
344  F(StrictNotEqual, 2, 1)
345 
346 #define FOR_EACH_INTRINSIC_PROMISE(F, I) \
347  F(EnqueueMicrotask, 1, 1) \
348  F(PromiseHookAfter, 1, 1) \
349  F(PromiseHookBefore, 1, 1) \
350  F(PromiseHookInit, 2, 1) \
351  F(AwaitPromisesInit, 5, 1) \
352  F(AwaitPromisesInitOld, 5, 1) \
353  F(PromiseMarkAsHandled, 1, 1) \
354  F(PromiseRejectEventFromStack, 2, 1) \
355  F(PromiseRevokeReject, 1, 1) \
356  F(PromiseStatus, 1, 1) \
357  F(RejectPromise, 3, 1) \
358  F(ResolvePromise, 2, 1) \
359  F(PromiseRejectAfterResolved, 2, 1) \
360  F(PromiseResolveAfterResolved, 2, 1)
361 
362 #define FOR_EACH_INTRINSIC_PROXY(F, I) \
363  F(CheckProxyGetSetTrapResult, 2, 1) \
364  F(CheckProxyHasTrap, 2, 1) \
365  F(GetPropertyWithReceiver, 3, 1) \
366  F(IsJSProxy, 1, 1) \
367  F(JSProxyGetHandler, 1, 1) \
368  F(JSProxyGetTarget, 1, 1) \
369  F(SetPropertyWithReceiver, 5, 1)
370 
371 #define FOR_EACH_INTRINSIC_REGEXP(F, I) \
372  I(IsRegExp, 1, 1) \
373  F(RegExpExec, 4, 1) \
374  F(RegExpExecMultiple, 4, 1) \
375  F(RegExpInitializeAndCompile, 3, 1) \
376  F(RegExpInternalReplace, 3, 1) \
377  F(RegExpReplace, 3, 1) \
378  F(RegExpSplit, 3, 1) \
379  F(StringReplaceNonGlobalRegExpWithFunction, 3, 1) \
380  F(StringSplit, 3, 1)
381 
382 #define FOR_EACH_INTRINSIC_SCOPES(F, I) \
383  F(DeclareEvalFunction, 2, 1) \
384  F(DeclareEvalVar, 1, 1) \
385  F(DeclareGlobals, 3, 1) \
386  F(DeleteLookupSlot, 1, 1) \
387  F(LoadLookupSlot, 1, 1) \
388  F(LoadLookupSlotInsideTypeof, 1, 1) \
389  F(NewArgumentsElements, 3, 1) \
390  \
391  F(NewClosure, 2, 1) \
392  F(NewClosure_Tenured, 2, 1) \
393  F(NewFunctionContext, 1, 1) \
394  F(NewRestParameter, 1, 1) \
395  F(NewScriptContext, 1, 1) \
396  F(NewSloppyArguments, 3, 1) \
397  F(NewSloppyArguments_Generic, 1, 1) \
398  F(NewStrictArguments, 1, 1) \
399  F(PushBlockContext, 1, 1) \
400  F(PushCatchContext, 2, 1) \
401  F(PushModuleContext, 2, 1) \
402  F(PushWithContext, 2, 1) \
403  F(StoreLookupSlot_Sloppy, 2, 1) \
404  F(StoreLookupSlot_SloppyHoisting, 2, 1) \
405  F(StoreLookupSlot_Strict, 2, 1) \
406  F(ThrowConstAssignError, 0, 1)
407 
408 #define FOR_EACH_INTRINSIC_STRINGS(F, I) \
409  F(FlattenString, 1, 1) \
410  F(GetSubstitution, 5, 1) \
411  F(InternalizeString, 1, 1) \
412  F(SparseJoinWithSeparator, 3, 1) \
413  F(StringAdd, 2, 1) \
414  F(StringBuilderConcat, 3, 1) \
415  F(StringBuilderJoin, 3, 1) \
416  F(StringCharCodeAt, 2, 1) \
417  F(StringEqual, 2, 1) \
418  F(StringGreaterThan, 2, 1) \
419  F(StringGreaterThanOrEqual, 2, 1) \
420  F(StringIncludes, 3, 1) \
421  F(StringIndexOf, 3, 1) \
422  F(StringIndexOfUnchecked, 3, 1) \
423  F(StringLastIndexOf, 2, 1) \
424  F(StringLessThan, 2, 1) \
425  F(StringLessThanOrEqual, 2, 1) \
426  F(StringMaxLength, 0, 1) \
427  F(StringReplaceOneCharWithString, 3, 1) \
428  F(StringSubstring, 3, 1) \
429  F(StringToArray, 2, 1) \
430  F(StringTrim, 2, 1)
431 
432 #define FOR_EACH_INTRINSIC_SYMBOL(F, I) \
433  F(CreatePrivateNameSymbol, 0, 1) \
434  F(CreatePrivateSymbol, -1 /* <= 1 */, 1) \
435  F(SymbolDescriptiveString, 1, 1) \
436  F(SymbolIsPrivate, 1, 1)
437 
438 #define FOR_EACH_INTRINSIC_TEST(F, I) \
439  F(Abort, 1, 1) \
440  F(AbortJS, 1, 1) \
441  F(ClearFunctionFeedback, 1, 1) \
442  F(CompleteInobjectSlackTracking, 1, 1) \
443  F(ConstructConsString, 2, 1) \
444  F(ConstructSlicedString, 2, 1) \
445  F(ConstructDouble, 2, 1) \
446  F(DebugPrint, 1, 1) \
447  F(DebugTrace, 0, 1) \
448  F(DebugTrackRetainingPath, -1, 1) \
449  F(DeoptimizeFunction, 1, 1) \
450  I(DeoptimizeNow, 0, 1) \
451  F(DeserializeWasmModule, 2, 1) \
452  F(DisallowCodegenFromStrings, 1, 1) \
453  F(DisallowWasmCodegen, 1, 1) \
454  F(DisassembleFunction, 1, 1) \
455  F(FreezeWasmLazyCompilation, 1, 1) \
456  F(GetCallable, 0, 1) \
457  F(GetDeoptCount, 1, 1) \
458  F(GetInitializerFunction, 1, 1) \
459  F(GetOptimizationStatus, -1, 1) \
460  F(GetUndetectable, 0, 1) \
461  F(GetWasmExceptionId, 2, 1) \
462  F(GetWasmExceptionValues, 1, 1) \
463  F(GetWasmRecoveredTrapCount, 0, 1) \
464  F(GlobalPrint, 1, 1) \
465  F(HasDictionaryElements, 1, 1) \
466  F(HasDoubleElements, 1, 1) \
467  F(HasFastElements, 1, 1) \
468  F(HasFastProperties, 1, 1) \
469  F(HasFixedBigInt64Elements, 1, 1) \
470  F(HasFixedBigUint64Elements, 1, 1) \
471  F(HasFixedFloat32Elements, 1, 1) \
472  F(HasFixedFloat64Elements, 1, 1) \
473  F(HasFixedInt16Elements, 1, 1) \
474  F(HasFixedInt32Elements, 1, 1) \
475  F(HasFixedInt8Elements, 1, 1) \
476  F(HasFixedUint16Elements, 1, 1) \
477  F(HasFixedUint32Elements, 1, 1) \
478  F(HasFixedUint8ClampedElements, 1, 1) \
479  F(HasFixedUint8Elements, 1, 1) \
480  F(HasHoleyElements, 1, 1) \
481  F(HasObjectElements, 1, 1) \
482  F(HasSloppyArgumentsElements, 1, 1) \
483  F(HasSmiElements, 1, 1) \
484  F(HasSmiOrObjectElements, 1, 1) \
485  F(HaveSameMap, 2, 1) \
486  F(HeapObjectVerify, 1, 1) \
487  F(ICsAreEnabled, 0, 1) \
488  F(InNewSpace, 1, 1) \
489  F(IsAsmWasmCode, 1, 1) \
490  F(IsConcurrentRecompilationSupported, 0, 1) \
491  F(WasmTierUpFunction, 2, 1) \
492  F(IsLiftoffFunction, 1, 1) \
493  F(IsWasmCode, 1, 1) \
494  F(IsWasmTrapHandlerEnabled, 0, 1) \
495  F(IsThreadInWasm, 0, 1) \
496  F(NeverOptimizeFunction, 1, 1) \
497  F(NotifyContextDisposed, 0, 1) \
498  F(OptimizeFunctionOnNextCall, -1, 1) \
499  F(OptimizeOsr, -1, 1) \
500  F(PrintWithNameForAssert, 2, 1) \
501  F(RedirectToWasmInterpreter, 2, 1) \
502  F(RunningInSimulator, 0, 1) \
503  F(SerializeWasmModule, 1, 1) \
504  F(SetAllocationTimeout, -1 /* 2 || 3 */, 1) \
505  F(SetForceSlowPath, 1, 1) \
506  F(SetWasmCompileControls, 2, 1) \
507  F(SetWasmInstantiateControls, 0, 1) \
508  F(ArraySpeciesProtector, 0, 1) \
509  F(MapIteratorProtector, 0, 1) \
510  F(SetIteratorProtector, 0, 1) \
511  F(StringIteratorProtector, 0, 1) \
512  F(SystemBreak, 0, 1) \
513  F(TraceEnter, 0, 1) \
514  F(TraceExit, 1, 1) \
515  F(UnblockConcurrentRecompilation, 0, 1) \
516  F(WasmGetNumberOfInstances, 1, 1) \
517  F(WasmNumInterpretedCalls, 1, 1) \
518  F(WasmTraceMemory, 1, 1) \
519  F(WasmMemoryHasFullGuardRegion, 1, 1) \
520  F(SetWasmThreadsEnabled, 1, 1)
521 
522 #define FOR_EACH_INTRINSIC_TYPEDARRAY(F, I) \
523  F(ArrayBufferNeuter, 1, 1) \
524  F(ArrayBufferViewWasNeutered, 1, 1) \
525  I(IsTypedArray, 1, 1) \
526  F(TypedArrayCopyElements, 3, 1) \
527  F(TypedArrayGetBuffer, 1, 1) \
528  F(TypedArrayGetLength, 1, 1) \
529  F(TypedArraySet, 2, 1) \
530  F(TypedArraySortFast, 1, 1)
531 
532 #define FOR_EACH_INTRINSIC_WASM(F, I) \
533  F(ThrowWasmError, 1, 1) \
534  F(ThrowWasmStackOverflow, 0, 1) \
535  F(WasmI32AtomicWait, 4, 1) \
536  F(WasmAtomicWake, 3, 1) \
537  F(WasmExceptionGetValues, 1, 1) \
538  F(WasmExceptionGetTag, 1, 1) \
539  F(WasmMemoryGrow, 2, 1) \
540  F(WasmRunInterpreter, 2, 1) \
541  F(WasmStackGuard, 0, 1) \
542  F(WasmThrowCreate, 2, 1) \
543  F(WasmThrowTypeError, 0, 1) \
544  F(WasmCompileLazy, 2, 1)
545 
546 #define FOR_EACH_INTRINSIC_RETURN_PAIR_IMPL(F, I) \
547  F(DebugBreakOnBytecode, 1, 2) \
548  F(LoadLookupSlotForCall, 1, 2)
549 
550 // Most intrinsics are implemented in the runtime/ directory, but ICs are
551 // implemented in ic.cc for now.
552 #define FOR_EACH_INTRINSIC_IC(F, I) \
553  F(ElementsTransitionAndStoreIC_Miss, 6, 1) \
554  F(KeyedLoadIC_Miss, 4, 1) \
555  F(KeyedStoreIC_Miss, 5, 1) \
556  F(KeyedStoreIC_Slow, 5, 1) \
557  F(LoadAccessorProperty, 4, 1) \
558  F(LoadCallbackProperty, 4, 1) \
559  F(LoadElementWithInterceptor, 2, 1) \
560  F(LoadGlobalIC_Miss, 3, 1) \
561  F(LoadGlobalIC_Slow, 3, 1) \
562  F(LoadIC_Miss, 4, 1) \
563  F(LoadPropertyWithInterceptor, 5, 1) \
564  F(StoreCallbackProperty, 6, 1) \
565  F(StoreGlobalIC_Miss, 4, 1) \
566  F(StoreGlobalIC_Slow, 5, 1) \
567  F(StoreIC_Miss, 5, 1) \
568  F(StoreInArrayLiteralIC_Slow, 5, 1) \
569  F(StorePropertyWithInterceptor, 5, 1) \
570  F(CloneObjectIC_Miss, 4, 1)
571 
572 #define FOR_EACH_INTRINSIC_RETURN_OBJECT_IMPL(F, I) \
573  FOR_EACH_INTRINSIC_ARRAY(F, I) \
574  FOR_EACH_INTRINSIC_ATOMICS(F, I) \
575  FOR_EACH_INTRINSIC_BIGINT(F, I) \
576  FOR_EACH_INTRINSIC_CLASSES(F, I) \
577  FOR_EACH_INTRINSIC_COLLECTIONS(F, I) \
578  FOR_EACH_INTRINSIC_COMPILER(F, I) \
579  FOR_EACH_INTRINSIC_DATE(F, I) \
580  FOR_EACH_INTRINSIC_DEBUG(F, I) \
581  FOR_EACH_INTRINSIC_FORIN(F, I) \
582  FOR_EACH_INTRINSIC_FUNCTION(F, I) \
583  FOR_EACH_INTRINSIC_GENERATOR(F, I) \
584  FOR_EACH_INTRINSIC_IC(F, I) \
585  FOR_EACH_INTRINSIC_INTERNAL(F, I) \
586  FOR_EACH_INTRINSIC_INTERPRETER(F, I) \
587  FOR_EACH_INTRINSIC_INTL(F, I) \
588  FOR_EACH_INTRINSIC_LITERALS(F, I) \
589  FOR_EACH_INTRINSIC_MODULE(F, I) \
590  FOR_EACH_INTRINSIC_NUMBERS(F, I) \
591  FOR_EACH_INTRINSIC_OBJECT(F, I) \
592  FOR_EACH_INTRINSIC_OPERATORS(F, I) \
593  FOR_EACH_INTRINSIC_PROMISE(F, I) \
594  FOR_EACH_INTRINSIC_PROXY(F, I) \
595  FOR_EACH_INTRINSIC_REGEXP(F, I) \
596  FOR_EACH_INTRINSIC_SCOPES(F, I) \
597  FOR_EACH_INTRINSIC_STRINGS(F, I) \
598  FOR_EACH_INTRINSIC_SYMBOL(F, I) \
599  FOR_EACH_INTRINSIC_TEST(F, I) \
600  FOR_EACH_INTRINSIC_TYPEDARRAY(F, I) \
601  FOR_EACH_INTRINSIC_WASM(F, I)
602 
603 // Defines the list of all intrinsics, coming in 2 flavors, either returning an
604 // object or a pair.
605 #define FOR_EACH_INTRINSIC_IMPL(F, I) \
606  FOR_EACH_INTRINSIC_RETURN_PAIR_IMPL(F, I) \
607  FOR_EACH_INTRINSIC_RETURN_OBJECT_IMPL(F, I)
608 
609 #define FOR_EACH_INTRINSIC_RETURN_OBJECT(F) \
610  FOR_EACH_INTRINSIC_RETURN_OBJECT_IMPL(F, F)
611 
612 #define FOR_EACH_INTRINSIC_RETURN_PAIR(F) \
613  FOR_EACH_INTRINSIC_RETURN_PAIR_IMPL(F, F)
614 
615 // The list of all intrinsics, including those that have inline versions, but
616 // not the inline versions themselves.
617 #define FOR_EACH_INTRINSIC(F) FOR_EACH_INTRINSIC_IMPL(F, F)
618 
619 // The list of all inline intrinsics only.
620 #define FOR_EACH_INLINE_INTRINSIC(I) FOR_EACH_INTRINSIC_IMPL(NOTHING, I)
621 
622 #define F(name, nargs, ressize) \
623  Object* Runtime_##name(int args_length, Address* args_object, \
624  Isolate* isolate);
625 FOR_EACH_INTRINSIC_RETURN_OBJECT(F)
626 #undef F
627 
628 //---------------------------------------------------------------------------
629 // Runtime provides access to all C++ runtime functions.
630 
631 class Runtime : public AllStatic {
632  public:
633  enum FunctionId : int32_t {
634 #define F(name, nargs, ressize) k##name,
635 #define I(name, nargs, ressize) kInline##name,
636  FOR_EACH_INTRINSIC(F) FOR_EACH_INLINE_INTRINSIC(I)
637 #undef I
638 #undef F
639  kNumFunctions,
640  };
641 
642  static constexpr int kNumInlineFunctions =
643 #define COUNT(...) +1
644  FOR_EACH_INLINE_INTRINSIC(COUNT);
645 #undef COUNT
646 
647  enum IntrinsicType { RUNTIME, INLINE };
648 
649  // Intrinsic function descriptor.
650  struct Function {
651  FunctionId function_id;
652  IntrinsicType intrinsic_type;
653  // The JS name of the function.
654  const char* name;
655 
656  // For RUNTIME functions, this is the C++ entry point.
657  // For INLINE functions this is the C++ entry point of the fall back.
658  Address entry;
659 
660  // The number of arguments expected. nargs is -1 if the function takes
661  // a variable number of arguments.
662  int8_t nargs;
663  // Size of result. Most functions return a single pointer, size 1.
664  int8_t result_size;
665  };
666 
667  static const int kNotFound = -1;
668 
669  // Checks whether the runtime function with the given {id} depends on the
670  // "current context", i.e. because it does scoped lookups, or whether it's
671  // fine to just pass any context within the same "native context".
672  static bool NeedsExactContext(FunctionId id);
673 
674  // Checks whether the runtime function with the given {id} never returns
675  // to it's caller normally, i.e. whether it'll always raise an exception.
676  // More specifically: The C++ implementation returns the Heap::exception
677  // sentinel, always.
678  static bool IsNonReturning(FunctionId id);
679 
680  // Get the intrinsic function with the given name.
681  static const Function* FunctionForName(const unsigned char* name, int length);
682 
683  // Get the intrinsic function with the given FunctionId.
684  V8_EXPORT_PRIVATE static const Function* FunctionForId(FunctionId id);
685 
686  // Get the intrinsic function with the given function entry address.
687  static const Function* FunctionForEntry(Address ref);
688 
689  // Get the runtime intrinsic function table.
690  static const Function* RuntimeFunctionTable(Isolate* isolate);
691 
692  V8_WARN_UNUSED_RESULT static Maybe<bool> DeleteObjectProperty(
693  Isolate* isolate, Handle<JSReceiver> receiver, Handle<Object> key,
694  LanguageMode language_mode);
695 
696  V8_WARN_UNUSED_RESULT static MaybeHandle<Object> SetObjectProperty(
697  Isolate* isolate, Handle<Object> object, Handle<Object> key,
698  Handle<Object> value, LanguageMode language_mode,
699  StoreOrigin store_origin);
700 
701  V8_WARN_UNUSED_RESULT static MaybeHandle<Object> GetObjectProperty(
702  Isolate* isolate, Handle<Object> object, Handle<Object> key,
703  bool* is_found_out = nullptr);
704 
705  V8_WARN_UNUSED_RESULT static MaybeHandle<JSArray> GetInternalProperties(
706  Isolate* isolate, Handle<Object>);
707 
708  V8_WARN_UNUSED_RESULT static MaybeHandle<Object> ThrowIteratorError(
709  Isolate* isolate, Handle<Object> object);
710 };
711 
712 
714  public:
715 #ifndef V8_INTL_SUPPORT
716  unibrow::Mapping<unibrow::ToUppercase, 128>* to_upper_mapping() {
717  return &to_upper_mapping_;
718  }
719  unibrow::Mapping<unibrow::ToLowercase, 128>* to_lower_mapping() {
720  return &to_lower_mapping_;
721  }
722 #endif
723 
724  Runtime::Function* redirected_intrinsic_functions() {
725  return redirected_intrinsic_functions_.get();
726  }
727 
728  void set_redirected_intrinsic_functions(
729  Runtime::Function* redirected_intrinsic_functions) {
730  redirected_intrinsic_functions_.reset(redirected_intrinsic_functions);
731  }
732 
733  private:
734  RuntimeState() = default;
735 #ifndef V8_INTL_SUPPORT
738 #endif
739 
740  std::unique_ptr<Runtime::Function[]> redirected_intrinsic_functions_;
741 
742  friend class Isolate;
743  friend class Runtime;
744 
745  DISALLOW_COPY_AND_ASSIGN(RuntimeState);
746 };
747 
748 V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream&, Runtime::FunctionId);
749 
750 //---------------------------------------------------------------------------
751 // Constants used by interface to runtime functions.
752 
753 class AllocateDoubleAlignFlag : public BitField<bool, 0, 1> {};
754 class AllocateTargetSpace : public BitField<AllocationSpace, 1, 3> {};
755 
756 class DeclareGlobalsEvalFlag : public BitField<bool, 0, 1> {};
757 class DeclareGlobalsNativeFlag : public BitField<bool, 1, 1> {};
758 
759 // A set of bits returned by Runtime_GetOptimizationStatus.
760 // These bits must be in sync with bits defined in test/mjsunit/mjsunit.js
761 enum class OptimizationStatus {
762  kIsFunction = 1 << 0,
763  kNeverOptimize = 1 << 1,
764  kAlwaysOptimize = 1 << 2,
765  kMaybeDeopted = 1 << 3,
766  kOptimized = 1 << 4,
767  kTurboFanned = 1 << 5,
768  kInterpreted = 1 << 6,
769  kMarkedForOptimization = 1 << 7,
770  kMarkedForConcurrentOptimization = 1 << 8,
771  kOptimizingConcurrently = 1 << 9,
772  kIsExecuting = 1 << 10,
773  kTopmostFrameIsTurboFanned = 1 << 11,
774  kLiteMode = 1 << 12,
775 };
776 
777 } // namespace internal
778 } // namespace v8
779 
780 #endif // V8_RUNTIME_RUNTIME_H_
Definition: v8.h:56
Definition: libplatform.h:13