runtime.h 32.2 KB
Newer Older
1
// Copyright 2012 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4

5 6
#ifndef V8_RUNTIME_RUNTIME_H_
#define V8_RUNTIME_RUNTIME_H_
7

8 9
#include <memory>

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 18
namespace v8 {
namespace internal {
19

20
// * Each intrinsic is exposed in JavaScript via:
21
//    * %#name, which is always a runtime call.
22 23
//    * (optionally) %_#name, which can be inlined or just a runtime call, the
//      compiler in question decides.
24 25 26 27 28 29 30 31 32 33 34
//
// * IntrinsicTypes are Runtime::RUNTIME and Runtime::INLINE, respectively.
//
// * IDs are Runtime::k##name and Runtime::kInline##name, respectively.
//
// * All intrinsics have a C++ implementation Runtime_##name.
//
// * Each compiler has an explicit list of intrisics it supports, falling back
//   to a simple runtime call if necessary.

// 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 37 38
// are specified by inline comments. To declare only the runtime version (no
// inline), use the F macro below. To declare the runtime version and the inline
// version simultaneously, use the I macro below.
39

40
#define FOR_EACH_INTRINSIC_ARRAY(F, I)    \
41 42 43 44 45 46 47 48
  F(ArrayIncludes_Slow, 3, 1)             \
  F(ArrayIndexOf, 3, 1)                   \
  F(ArrayIsArray, 1, 1)                   \
  F(ArraySpeciesConstructor, 1, 1)        \
  F(EstimateNumberOfElements, 1, 1)       \
  F(GetArrayKeys, 2, 1)                   \
  F(GrowArrayElements, 2, 1)              \
  F(HasComplexElements, 1, 1)             \
49
  I(IsArray, 1, 1)                        \
50 51 52 53 54 55
  F(MoveArrayContents, 2, 1)              \
  F(NewArray, -1 /* >= 3 */, 1)           \
  F(NormalizeElements, 1, 1)              \
  F(PrepareElementsForSort, 2, 1)         \
  F(TransitionElementsKind, 2, 1)         \
  F(TransitionElementsKindWithKind, 2, 1) \
56 57
  F(TrySliceSimpleNonFastElements, 3, 1)

58 59 60 61 62 63 64 65 66 67 68
#define FOR_EACH_INTRINSIC_ATOMICS(F, I) \
  F(AtomicsLoad64, 2, 1)                 \
  F(AtomicsStore64, 3, 1)                \
  F(AtomicsAdd, 3, 1)                    \
  F(AtomicsAnd, 3, 1)                    \
  F(AtomicsCompareExchange, 4, 1)        \
  F(AtomicsExchange, 3, 1)               \
  F(AtomicsNumWaitersForTesting, 2, 1)   \
  F(AtomicsOr, 3, 1)                     \
  F(AtomicsSub, 3, 1)                    \
  F(AtomicsXor, 3, 1)                    \
69
  F(SetAllowAtomicsWait, 1, 1)
binji's avatar
binji committed
70

71 72 73 74 75 76 77 78 79 80 81
#define FOR_EACH_INTRINSIC_BIGINT(F, I) \
  F(BigIntBinaryOp, 3, 1)               \
  F(BigIntCompareToBigInt, 3, 1)        \
  F(BigIntCompareToNumber, 3, 1)        \
  F(BigIntCompareToString, 3, 1)        \
  F(BigIntEqualToBigInt, 2, 1)          \
  F(BigIntEqualToNumber, 2, 1)          \
  F(BigIntEqualToString, 2, 1)          \
  F(BigIntToBoolean, 1, 1)              \
  F(BigIntToNumber, 1, 1)               \
  F(BigIntUnaryOp, 2, 1)                \
82
  F(ToBigInt, 1, 1)
83

84
#define FOR_EACH_INTRINSIC_CLASSES(F, I)    \
85
  F(DefineClass, -1 /* >= 3 */, 1)          \
86
  F(HomeObjectSymbol, 0, 1)                 \
87 88 89
  F(LoadFromSuper, 3, 1)                    \
  F(LoadKeyedFromSuper, 3, 1)               \
  F(StoreKeyedToSuper_Sloppy, 4, 1)         \
90 91 92 93 94 95 96 97 98
  F(StoreKeyedToSuper_Strict, 4, 1)         \
  F(StoreToSuper_Sloppy, 4, 1)              \
  F(StoreToSuper_Strict, 4, 1)              \
  F(ThrowConstructorNonCallableError, 1, 1) \
  F(ThrowNotSuperConstructor, 2, 1)         \
  F(ThrowStaticPrototypeError, 0, 1)        \
  F(ThrowSuperAlreadyCalledError, 0, 1)     \
  F(ThrowSuperNotCalled, 0, 1)              \
  F(ThrowUnsupportedSuperError, 0, 1)
99

100 101 102 103 104 105 106
#define FOR_EACH_INTRINSIC_COLLECTIONS(F, I) \
  F(MapGrow, 1, 1)                           \
  F(MapShrink, 1, 1)                         \
  F(SetGrow, 1, 1)                           \
  F(SetShrink, 1, 1)                         \
  F(TheHole, 0, 1)                           \
  F(WeakCollectionDelete, 3, 1)              \
107
  F(WeakCollectionSet, 4, 1)
108

109
#define FOR_EACH_INTRINSIC_COMPILER(F, I) \
110
  F(CompileForOnStackReplacement, 1, 1)   \
111 112 113
  F(CompileLazy, 1, 1)                    \
  F(CompileOptimized_Concurrent, 1, 1)    \
  F(CompileOptimized_NotConcurrent, 1, 1) \
114
  F(EvictOptimizedCodeSlot, 1, 1)         \
115 116
  F(FunctionFirstExecution, 1, 1)         \
  F(InstantiateAsmJs, 4, 1)               \
117
  F(NotifyDeoptimized, 0, 1)              \
118
  F(ResolvePossiblyDirectEval, 6, 1)
119

120
#define FOR_EACH_INTRINSIC_DATE(F, I) F(DateCurrentTime, 0, 1)
121

122
#define FOR_EACH_INTRINSIC_DEBUG(F, I)          \
123
  F(ClearStepping, 0, 1)                        \
124 125 126
  F(CollectGarbage, 1, 1)                       \
  F(DebugBreakAtEntry, 1, 1)                    \
  F(DebugCollectCoverage, 0, 1)                 \
127
  F(DebugGetLoadedScriptIds, 0, 1)              \
128
  F(DebugOnFunctionCall, 2, 1)                  \
129 130 131
  F(DebugPopPromise, 0, 1)                      \
  F(DebugPrepareStepInSuspendedGenerator, 0, 1) \
  F(DebugPushPromise, 1, 1)                     \
132 133
  F(DebugAsyncFunctionSuspended, 1, 1)          \
  F(DebugAsyncFunctionFinished, 2, 1)           \
134 135 136 137 138 139
  F(DebugToggleBlockCoverage, 1, 1)             \
  F(DebugTogglePreciseCoverage, 1, 1)           \
  F(FunctionGetInferredName, 1, 1)              \
  F(GetBreakLocations, 1, 1)                    \
  F(GetGeneratorScopeCount, 1, 1)               \
  F(GetGeneratorScopeDetails, 2, 1)             \
140
  F(GetHeapUsage, 0, 1)                         \
141 142 143 144
  F(HandleDebuggerStatement, 0, 1)              \
  F(IncBlockCounter, 2, 1)                      \
  F(IsBreakOnException, 1, 1)                   \
  F(ScheduleBreak, 0, 1)                        \
145
  F(ScriptLocationFromLine2, 4, 1)              \
146 147
  F(SetGeneratorScopeVariableValue, 4, 1)       \
  F(LiveEditPatchScript, 2, 1)
148

149 150
#define FOR_EACH_INTRINSIC_FORIN(F, I) \
  F(ForInEnumerate, 1, 1)              \
151
  F(ForInHasProperty, 2, 1)
152

153
#ifdef V8_TRACE_IGNITION
154 155
#define FOR_EACH_INTRINSIC_INTERPRETER_TRACE(F, I) \
  F(InterpreterTraceBytecodeEntry, 3, 1)           \
156 157
  F(InterpreterTraceBytecodeExit, 3, 1)
#else
158
#define FOR_EACH_INTRINSIC_INTERPRETER_TRACE(F, I)
159 160
#endif

161
#ifdef V8_TRACE_FEEDBACK_UPDATES
162
#define FOR_EACH_INTRINSIC_INTERPRETER_TRACE_FEEDBACK(F, I) \
163 164
  F(InterpreterTraceUpdateFeedback, 3, 1)
#else
165
#define FOR_EACH_INTRINSIC_INTERPRETER_TRACE_FEEDBACK(F, I)
166 167
#endif

168 169 170
#define FOR_EACH_INTRINSIC_INTERPRETER(F, I)          \
  FOR_EACH_INTRINSIC_INTERPRETER_TRACE(F, I)          \
  FOR_EACH_INTRINSIC_INTERPRETER_TRACE_FEEDBACK(F, I) \
171
  F(InterpreterDeserializeLazy, 2, 1)
172

173 174
#define FOR_EACH_INTRINSIC_FUNCTION(F, I)  \
  I(Call, -1 /* >= 2 */, 1)                \
175
  F(FunctionGetScriptSource, 1, 1)         \
176
  F(FunctionGetScriptId, 1, 1)             \
177
  F(FunctionGetScriptSourcePosition, 1, 1) \
178
  F(FunctionGetSourceCode, 1, 1)           \
179 180
  F(FunctionIsAPIFunction, 1, 1)           \
  F(IsFunction, 1, 1)                      \
181 182
  F(SetNativeFlag, 1, 1)

183
#define FOR_EACH_INTRINSIC_GENERATOR(F, I)    \
184 185
  I(AsyncFunctionAwaitCaught, 2, 1)           \
  I(AsyncFunctionAwaitUncaught, 2, 1)         \
186 187 188
  I(AsyncFunctionEnter, 2, 1)                 \
  I(AsyncFunctionReject, 3, 1)                \
  I(AsyncFunctionResolve, 3, 1)               \
189 190
  I(AsyncGeneratorAwaitCaught, 2, 1)          \
  I(AsyncGeneratorAwaitUncaught, 2, 1)        \
191
  F(AsyncGeneratorHasCatchHandlerForPC, 1, 1) \
192 193 194 195 196
  I(AsyncGeneratorReject, 2, 1)               \
  I(AsyncGeneratorResolve, 3, 1)              \
  I(AsyncGeneratorYield, 3, 1)                \
  I(CreateJSGeneratorObject, 2, 1)            \
  I(GeneratorClose, 1, 1)                     \
197
  F(GeneratorGetFunction, 1, 1)               \
198
  I(GeneratorGetResumeMode, 1, 1)
199

200
#ifdef V8_INTL_SUPPORT
201 202 203 204 205 206 207 208
#define FOR_EACH_INTRINSIC_INTL(F, I) \
  F(AvailableLocalesOf, 1, 1)         \
  F(CanonicalizeLanguageTag, 1, 1)    \
  F(DateCacheVersion, 0, 1)           \
  F(FormatList, 2, 1)                 \
  F(FormatListToParts, 2, 1)          \
  F(GetDefaultICULocale, 0, 1)        \
  F(StringToLowerCaseIntl, 1, 1)      \
209
  F(StringToUpperCaseIntl, 1, 1)  // End of macro.
210
#else
211
#define FOR_EACH_INTRINSIC_INTL(F, I)
212
#endif  // V8_INTL_SUPPORT
213

214
#define FOR_EACH_INTRINSIC_INTERNAL(F, I)          \
215 216 217 218 219 220
  F(AllocateInNewSpace, 1, 1)                      \
  F(AllocateInTargetSpace, 2, 1)                   \
  F(AllocateSeqOneByteString, 1, 1)                \
  F(AllocateSeqTwoByteString, 1, 1)                \
  F(AllowDynamicFunction, 1, 1)                    \
  F(CheckIsBootstrapping, 0, 1)                    \
221
  I(CreateAsyncFromSyncIterator, 1, 1)             \
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
  F(CreateListFromArrayLike, 1, 1)                 \
  F(CreateTemplateObject, 1, 1)                    \
  F(DeserializeLazy, 1, 1)                         \
  F(ExportFromRuntime, 1, 1)                       \
  F(GetAndResetRuntimeCallStats, -1 /* <= 2 */, 1) \
  F(IncrementUseCounter, 1, 1)                     \
  F(InstallToContext, 1, 1)                        \
  F(Interrupt, 0, 1)                               \
  F(IS_VAR, 1, 1)                                  \
  F(NewReferenceError, 2, 1)                       \
  F(NewSyntaxError, 2, 1)                          \
  F(NewTypeError, 2, 1)                            \
  F(OrdinaryHasInstance, 2, 1)                     \
  F(PromoteScheduledException, 0, 1)               \
  F(ReportMessage, 1, 1)                           \
  F(ReThrow, 1, 1)                                 \
  F(RunMicrotaskCallback, 2, 1)                    \
  F(RunMicrotasks, 0, 1)                           \
  F(StackGuard, 0, 1)                              \
  F(Throw, 1, 1)                                   \
  F(ThrowApplyNonFunction, 1, 1)                   \
  F(ThrowCalledNonCallable, 1, 1)                  \
  F(ThrowConstructedNonConstructable, 1, 1)        \
  F(ThrowConstructorReturnedNonObject, 0, 1)       \
  F(ThrowInvalidStringLength, 0, 1)                \
  F(ThrowInvalidTypedArrayAlignment, 2, 1)         \
  F(ThrowIteratorError, 1, 1)                      \
  F(ThrowIteratorResultNotAnObject, 1, 1)          \
  F(ThrowNotConstructor, 1, 1)                     \
  F(ThrowRangeError, -1 /* >= 1 */, 1)             \
  F(ThrowReferenceError, 1, 1)                     \
  F(ThrowStackOverflow, 0, 1)                      \
  F(ThrowSymbolAsyncIteratorInvalid, 0, 1)         \
  F(ThrowSymbolIteratorInvalid, 0, 1)              \
  F(ThrowThrowMethodMissing, 0, 1)                 \
  F(ThrowTypeError, -1 /* >= 1 */, 1)              \
  F(Typeof, 1, 1)                                  \
259
  F(UnwindAndFindExceptionHandler, 0, 1)
260

261
#define FOR_EACH_INTRINSIC_LITERALS(F, I)           \
262
  F(CreateArrayLiteral, 4, 1)                       \
263
  F(CreateArrayLiteralWithoutAllocationSite, 2, 1)  \
264 265
  F(CreateObjectLiteral, 4, 1)                      \
  F(CreateObjectLiteralWithoutAllocationSite, 2, 1) \
266
  F(CreateRegExpLiteral, 4, 1)
267

268 269 270
#define FOR_EACH_INTRINSIC_MODULE(F, I) \
  F(DynamicImportCall, 2, 1)            \
  I(GetImportMetaObject, 0, 1)          \
271
  F(GetModuleNamespace, 1, 1)
272

273 274 275 276 277 278 279 280 281 282
#define FOR_EACH_INTRINSIC_NUMBERS(F, I) \
  F(GetHoleNaNLower, 0, 1)               \
  F(GetHoleNaNUpper, 0, 1)               \
  I(IsSmi, 1, 1)                         \
  F(IsValidSmi, 1, 1)                    \
  F(MaxSmi, 0, 1)                        \
  F(NumberToString, 1, 1)                \
  F(SmiLexicographicCompare, 2, 1)       \
  F(StringParseFloat, 1, 1)              \
  F(StringParseInt, 2, 1)                \
283
  F(StringToNumber, 1, 1)
284

285
#define FOR_EACH_INTRINSIC_OBJECT(F, I)                         \
286
  F(AddDictionaryProperty, 3, 1)                                \
287
  F(AddElement, 3, 1)                                           \
288 289
  F(AddNamedProperty, 4, 1)                                     \
  F(AddPrivateField, 3, 1)                                      \
290 291
  F(AllocateHeapNumber, 0, 1)                                   \
  F(ClassOf, 1, 1)                                              \
292 293
  F(CollectTypeProfile, 3, 1)                                   \
  F(CompleteInobjectSlackTrackingForMap, 1, 1)                  \
294 295
  F(CopyDataProperties, 2, 1)                                   \
  F(CopyDataPropertiesWithExcludedProperties, -1 /* >= 1 */, 1) \
296 297
  I(CreateDataProperty, 3, 1)                                   \
  I(CreateIterResultObject, 2, 1)                               \
298 299
  F(DefineAccessorPropertyUnchecked, 5, 1)                      \
  F(DefineDataPropertyInLiteral, 6, 1)                          \
300
  F(DefineGetterPropertyUnchecked, 4, 1)                        \
301
  F(DefineMethodsInternal, 3, 1)                                \
302 303 304 305 306 307 308 309
  F(DefineSetterPropertyUnchecked, 4, 1)                        \
  F(DeleteProperty, 3, 1)                                       \
  F(GetFunctionName, 1, 1)                                      \
  F(GetOwnPropertyDescriptor, 2, 1)                             \
  F(GetOwnPropertyKeys, 2, 1)                                   \
  F(GetProperty, 2, 1)                                          \
  F(HasFastPackedElements, 1, 1)                                \
  F(HasInPrototypeChain, 2, 1)                                  \
310
  I(HasProperty, 2, 1)                                          \
311
  F(InternalSetPrototype, 2, 1)                                 \
312
  I(IsJSReceiver, 1, 1)                                         \
313 314 315 316 317 318
  F(NewObject, 2, 1)                                            \
  F(ObjectCreate, 2, 1)                                         \
  F(ObjectEntries, 1, 1)                                        \
  F(ObjectEntriesSkipFastPath, 1, 1)                            \
  F(ObjectHasOwnProperty, 2, 1)                                 \
  F(ObjectKeys, 1, 1)                                           \
319 320
  F(ObjectGetOwnPropertyNames, 1, 1)                            \
  F(ObjectGetOwnPropertyNamesTryFast, 1, 1)                     \
321 322 323
  F(ObjectValues, 1, 1)                                         \
  F(ObjectValuesSkipFastPath, 1, 1)                             \
  F(OptimizeObjectForAddingMultipleProperties, 2, 1)            \
324
  F(PerformSideEffectCheckForObject, 1, 1)                      \
325
  F(SetDataProperties, 2, 1)                                    \
326 327
  F(SetKeyedProperty, 4, 1)                                     \
  F(SetNamedProperty, 4, 1)                                     \
328
  F(StoreDataPropertyInLiteral, 3, 1)                           \
329 330
  F(ShrinkPropertyDictionary, 1, 1)                             \
  F(ToFastProperties, 1, 1)                                     \
331
  I(ToLength, 1, 1)                                             \
332
  F(ToName, 1, 1)                                               \
333
  I(ToNumber, 1, 1)                                             \
334
  F(ToNumeric, 1, 1)                                            \
335 336
  I(ToObject, 1, 1)                                             \
  I(ToString, 1, 1)                                             \
337
  F(TryMigrateInstance, 1, 1)
338

339 340 341 342 343 344 345 346 347
#define FOR_EACH_INTRINSIC_OPERATORS(F, I) \
  F(Add, 2, 1)                             \
  F(Equal, 2, 1)                           \
  F(GreaterThan, 2, 1)                     \
  F(GreaterThanOrEqual, 2, 1)              \
  F(LessThan, 2, 1)                        \
  F(LessThanOrEqual, 2, 1)                 \
  F(NotEqual, 2, 1)                        \
  F(StrictEqual, 2, 1)                     \
348
  F(StrictNotEqual, 2, 1)
349

350 351 352 353 354
#define FOR_EACH_INTRINSIC_PROMISE(F, I) \
  F(EnqueueMicrotask, 1, 1)              \
  F(PromiseHookAfter, 1, 1)              \
  F(PromiseHookBefore, 1, 1)             \
  F(PromiseHookInit, 2, 1)               \
355
  F(AwaitPromisesInit, 5, 1)             \
356 357 358 359 360
  F(PromiseMarkAsHandled, 1, 1)          \
  F(PromiseRejectEventFromStack, 2, 1)   \
  F(PromiseResult, 1, 1)                 \
  F(PromiseRevokeReject, 1, 1)           \
  F(PromiseStatus, 1, 1)                 \
361 362
  F(RejectPromise, 3, 1)                 \
  F(ResolvePromise, 2, 1)                \
363
  F(PromiseRejectAfterResolved, 2, 1)    \
364
  F(PromiseResolveAfterResolved, 2, 1)
365

366 367 368 369 370 371 372
#define FOR_EACH_INTRINSIC_PROXY(F, I) \
  F(CheckProxyGetSetTrapResult, 2, 1)  \
  F(CheckProxyHasTrap, 2, 1)           \
  F(GetPropertyWithReceiver, 3, 1)     \
  F(IsJSProxy, 1, 1)                   \
  F(JSProxyGetHandler, 1, 1)           \
  F(JSProxyGetTarget, 1, 1)            \
373
  F(SetPropertyWithReceiver, 5, 1)
374

375 376
#define FOR_EACH_INTRINSIC_REGEXP(F, I)             \
  I(IsRegExp, 1, 1)                                 \
377
  F(RegExpExec, 4, 1)                               \
378
  F(RegExpExecMultiple, 4, 1)                       \
379
  F(RegExpInitializeAndCompile, 3, 1)               \
380 381
  F(RegExpInternalReplace, 3, 1)                    \
  F(RegExpReplace, 3, 1)                            \
382
  F(RegExpSplit, 3, 1)                              \
383 384
  F(StringReplaceNonGlobalRegExpWithFunction, 3, 1) \
  F(StringSplit, 3, 1)
385

386
#define FOR_EACH_INTRINSIC_SCOPES(F, I)   \
387 388
  F(DeclareEvalFunction, 2, 1)            \
  F(DeclareEvalVar, 1, 1)                 \
389 390 391 392
  F(DeclareGlobals, 3, 1)                 \
  F(DeleteLookupSlot, 1, 1)               \
  F(LoadLookupSlot, 1, 1)                 \
  F(LoadLookupSlotInsideTypeof, 1, 1)     \
393
  F(NewArgumentsElements, 3, 1)           \
394
                                          \
395 396
  F(NewClosure, 2, 1)                     \
  F(NewClosure_Tenured, 2, 1)             \
397
  F(NewFunctionContext, 1, 1)             \
398
  F(NewRestParameter, 1, 1)               \
399
  F(NewScriptContext, 1, 1)               \
400 401 402
  F(NewSloppyArguments, 3, 1)             \
  F(NewSloppyArguments_Generic, 1, 1)     \
  F(NewStrictArguments, 1, 1)             \
403
  F(PushBlockContext, 1, 1)               \
404
  F(PushCatchContext, 2, 1)               \
405 406
  F(PushModuleContext, 2, 1)              \
  F(PushWithContext, 2, 1)                \
407 408
  F(StoreLookupSlot_Sloppy, 2, 1)         \
  F(StoreLookupSlot_SloppyHoisting, 2, 1) \
409 410
  F(StoreLookupSlot_Strict, 2, 1)         \
  F(ThrowConstAssignError, 0, 1)
411

412
#define FOR_EACH_INTRINSIC_STRINGS(F, I)  \
413
  F(FlattenString, 1, 1)                  \
414
  F(GetSubstitution, 5, 1)                \
415 416 417 418 419 420 421 422 423
  F(InternalizeString, 1, 1)              \
  F(SparseJoinWithSeparator, 3, 1)        \
  F(StringAdd, 2, 1)                      \
  F(StringBuilderConcat, 3, 1)            \
  F(StringBuilderJoin, 3, 1)              \
  F(StringCharCodeAt, 2, 1)               \
  F(StringEqual, 2, 1)                    \
  F(StringGreaterThan, 2, 1)              \
  F(StringGreaterThanOrEqual, 2, 1)       \
424
  F(StringIncludes, 3, 1)                 \
425
  F(StringIndexOf, 3, 1)                  \
426
  F(StringIndexOfUnchecked, 3, 1)         \
427
  F(StringLastIndexOf, 2, 1)              \
428 429
  F(StringLessThan, 2, 1)                 \
  F(StringLessThanOrEqual, 2, 1)          \
430 431 432 433 434
  F(StringMaxLength, 0, 1)                \
  F(StringReplaceOneCharWithString, 3, 1) \
  F(StringSubstring, 3, 1)                \
  F(StringToArray, 2, 1)                  \
  F(StringTrim, 2, 1)
435

436
#define FOR_EACH_INTRINSIC_SYMBOL(F, I)    \
437
  F(CreatePrivateFieldSymbol, 0, 1)        \
438
  F(CreatePrivateSymbol, -1 /* <= 1 */, 1) \
439
  F(SymbolDescriptiveString, 1, 1)         \
440 441
  F(SymbolIsPrivate, 1, 1)

442
#define FOR_EACH_INTRINSIC_TEST(F, I)         \
443 444 445 446 447
  F(Abort, 1, 1)                              \
  F(AbortJS, 1, 1)                            \
  F(ClearFunctionFeedback, 1, 1)              \
  F(CompleteInobjectSlackTracking, 1, 1)      \
  F(ConstructConsString, 2, 1)                \
448
  F(ConstructSlicedString, 2, 1)              \
449
  F(ConstructDouble, 2, 1)                    \
450 451
  F(DebugPrint, 1, 1)                         \
  F(DebugTrace, 0, 1)                         \
452
  F(DebugTrackRetainingPath, -1, 1)           \
453
  F(DeoptimizeFunction, 1, 1)                 \
454
  I(DeoptimizeNow, 0, 1)                      \
455 456 457 458 459 460 461
  F(DeserializeWasmModule, 2, 1)              \
  F(DisallowCodegenFromStrings, 1, 1)         \
  F(DisallowWasmCodegen, 1, 1)                \
  F(DisassembleFunction, 1, 1)                \
  F(FreezeWasmLazyCompilation, 1, 1)          \
  F(GetCallable, 0, 1)                        \
  F(GetDeoptCount, 1, 1)                      \
462
  F(GetInitializerFunction, 1, 1)             \
463 464
  F(GetOptimizationStatus, -1, 1)             \
  F(GetUndetectable, 0, 1)                    \
465
  F(GetWasmExceptionId, 2, 1)                 \
466
  F(GetWasmExceptionValues, 1, 1)             \
467
  F(GetWasmRecoveredTrapCount, 0, 1)          \
468 469
  F(GlobalPrint, 1, 1)                        \
  F(HasDictionaryElements, 1, 1)              \
470 471
  F(HasDoubleElements, 1, 1)                  \
  F(HasFastElements, 1, 1)                    \
472
  F(HasFastProperties, 1, 1)                  \
473 474
  F(HasFixedBigInt64Elements, 1, 1)           \
  F(HasFixedBigUint64Elements, 1, 1)          \
475 476 477 478
  F(HasFixedFloat32Elements, 1, 1)            \
  F(HasFixedFloat64Elements, 1, 1)            \
  F(HasFixedInt16Elements, 1, 1)              \
  F(HasFixedInt32Elements, 1, 1)              \
479 480 481
  F(HasFixedInt8Elements, 1, 1)               \
  F(HasFixedUint16Elements, 1, 1)             \
  F(HasFixedUint32Elements, 1, 1)             \
482
  F(HasFixedUint8ClampedElements, 1, 1)       \
483 484 485 486 487 488 489 490 491
  F(HasFixedUint8Elements, 1, 1)              \
  F(HasHoleyElements, 1, 1)                   \
  F(HasObjectElements, 1, 1)                  \
  F(HasSloppyArgumentsElements, 1, 1)         \
  F(HasSmiElements, 1, 1)                     \
  F(HasSmiOrObjectElements, 1, 1)             \
  F(HaveSameMap, 2, 1)                        \
  F(HeapObjectVerify, 1, 1)                   \
  F(InNewSpace, 1, 1)                         \
492
  F(IsAsmWasmCode, 1, 1)                      \
493
  F(IsConcurrentRecompilationSupported, 0, 1) \
494
  F(WasmTierUpFunction, 2, 1)                 \
495
  F(IsLiftoffFunction, 1, 1)                  \
496
  F(IsWasmCode, 1, 1)                         \
497
  F(IsWasmTrapHandlerEnabled, 0, 1)           \
498 499 500 501 502 503 504 505 506 507 508 509
  F(NeverOptimizeFunction, 1, 1)              \
  F(NotifyContextDisposed, 0, 1)              \
  F(OptimizeFunctionOnNextCall, -1, 1)        \
  F(OptimizeOsr, -1, 1)                       \
  F(PrintWithNameForAssert, 2, 1)             \
  F(RedirectToWasmInterpreter, 2, 1)          \
  F(RunningInSimulator, 0, 1)                 \
  F(SerializeWasmModule, 1, 1)                \
  F(SetAllocationTimeout, -1 /* 2 || 3 */, 1) \
  F(SetForceSlowPath, 1, 1)                   \
  F(SetWasmCompileControls, 2, 1)             \
  F(SetWasmInstantiateControls, 0, 1)         \
510 511 512
  F(ArraySpeciesProtector, 0, 1)              \
  F(TypedArraySpeciesProtector, 0, 1)         \
  F(PromiseSpeciesProtector, 0, 1)            \
513 514
  F(MapIteratorProtector, 0, 1)               \
  F(SetIteratorProtector, 0, 1)               \
515
  F(StringIteratorProtector, 0, 1)            \
516 517 518 519
  F(SystemBreak, 0, 1)                        \
  F(TraceEnter, 0, 1)                         \
  F(TraceExit, 1, 1)                          \
  F(UnblockConcurrentRecompilation, 0, 1)     \
520
  F(WasmGetNumberOfInstances, 1, 1)           \
521
  F(WasmNumInterpretedCalls, 1, 1)            \
522
  F(WasmTraceMemory, 1, 1)                    \
523 524
  F(WasmMemoryHasFullGuardRegion, 1, 1)       \
  F(SetWasmThreadsEnabled, 1, 1)
525

526 527 528 529 530 531 532 533
#define FOR_EACH_INTRINSIC_TYPEDARRAY(F, I) \
  F(ArrayBufferNeuter, 1, 1)                \
  F(ArrayBufferViewWasNeutered, 1, 1)       \
  I(IsTypedArray, 1, 1)                     \
  F(TypedArrayCopyElements, 3, 1)           \
  F(TypedArrayGetBuffer, 1, 1)              \
  F(TypedArrayGetLength, 1, 1)              \
  F(TypedArraySet, 2, 1)                    \
534
  F(TypedArraySortFast, 1, 1)
535

536 537 538 539 540 541 542 543 544 545 546
#define FOR_EACH_INTRINSIC_WASM(F, I) \
  F(ThrowWasmError, 1, 1)             \
  F(ThrowWasmStackOverflow, 0, 1)     \
  F(WasmExceptionGetElement, 2, 1)    \
  F(WasmExceptionSetElement, 3, 1)    \
  F(WasmExceptionGetTag, 1, 1)        \
  F(WasmGrowMemory, 2, 1)             \
  F(WasmRunInterpreter, 2, 1)         \
  F(WasmStackGuard, 0, 1)             \
  F(WasmThrowCreate, 2, 1)            \
  F(WasmThrowTypeError, 0, 1)         \
547
  F(WasmCompileLazy, 2, 1)
548

549 550
#define FOR_EACH_INTRINSIC_RETURN_PAIR_IMPL(F, I) \
  F(DebugBreakOnBytecode, 1, 2)                   \
551
  F(LoadLookupSlotForCall, 1, 2)
552

553 554
// Most intrinsics are implemented in the runtime/ directory, but ICs are
// implemented in ic.cc for now.
555
#define FOR_EACH_INTRINSIC_IC(F, I)          \
556 557 558 559
  F(ElementsTransitionAndStoreIC_Miss, 6, 1) \
  F(KeyedLoadIC_Miss, 4, 1)                  \
  F(KeyedStoreIC_Miss, 5, 1)                 \
  F(KeyedStoreIC_Slow, 5, 1)                 \
560 561
  F(LoadAccessorProperty, 4, 1)              \
  F(LoadCallbackProperty, 4, 1)              \
562
  F(LoadElementWithInterceptor, 2, 1)        \
563
  F(LoadGlobalIC_Miss, 3, 1)                 \
564
  F(LoadGlobalIC_Slow, 3, 1)                 \
565
  F(LoadIC_Miss, 4, 1)                       \
566
  F(LoadPropertyWithInterceptor, 5, 1)       \
567
  F(StoreCallbackProperty, 6, 1)             \
568
  F(StoreGlobalIC_Miss, 4, 1)                \
569
  F(StoreGlobalIC_Slow, 5, 1)                \
570
  F(StoreIC_Miss, 5, 1)                      \
571
  F(StoreInArrayLiteralIC_Slow, 5, 1)        \
572 573 574
  F(StorePropertyWithInterceptor, 5, 1)      \
  F(CloneObjectIC_Miss, 4, 1)                \
  F(CloneObjectIC_Slow, 2, 1)
575

576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612
#define FOR_EACH_INTRINSIC_RETURN_OBJECT_IMPL(F, I) \
  FOR_EACH_INTRINSIC_ARRAY(F, I)                    \
  FOR_EACH_INTRINSIC_ATOMICS(F, I)                  \
  FOR_EACH_INTRINSIC_BIGINT(F, I)                   \
  FOR_EACH_INTRINSIC_CLASSES(F, I)                  \
  FOR_EACH_INTRINSIC_COLLECTIONS(F, I)              \
  FOR_EACH_INTRINSIC_COMPILER(F, I)                 \
  FOR_EACH_INTRINSIC_DATE(F, I)                     \
  FOR_EACH_INTRINSIC_DEBUG(F, I)                    \
  FOR_EACH_INTRINSIC_FORIN(F, I)                    \
  FOR_EACH_INTRINSIC_FUNCTION(F, I)                 \
  FOR_EACH_INTRINSIC_GENERATOR(F, I)                \
  FOR_EACH_INTRINSIC_IC(F, I)                       \
  FOR_EACH_INTRINSIC_INTERNAL(F, I)                 \
  FOR_EACH_INTRINSIC_INTERPRETER(F, I)              \
  FOR_EACH_INTRINSIC_INTL(F, I)                     \
  FOR_EACH_INTRINSIC_LITERALS(F, I)                 \
  FOR_EACH_INTRINSIC_MODULE(F, I)                   \
  FOR_EACH_INTRINSIC_NUMBERS(F, I)                  \
  FOR_EACH_INTRINSIC_OBJECT(F, I)                   \
  FOR_EACH_INTRINSIC_OPERATORS(F, I)                \
  FOR_EACH_INTRINSIC_PROMISE(F, I)                  \
  FOR_EACH_INTRINSIC_PROXY(F, I)                    \
  FOR_EACH_INTRINSIC_REGEXP(F, I)                   \
  FOR_EACH_INTRINSIC_SCOPES(F, I)                   \
  FOR_EACH_INTRINSIC_STRINGS(F, I)                  \
  FOR_EACH_INTRINSIC_SYMBOL(F, I)                   \
  FOR_EACH_INTRINSIC_TEST(F, I)                     \
  FOR_EACH_INTRINSIC_TYPEDARRAY(F, I)               \
  FOR_EACH_INTRINSIC_WASM(F, I)

// Defines the list of all intrinsics, coming in 2 flavors, either returning an
// object or a pair.
#define FOR_EACH_INTRINSIC_IMPL(F, I)       \
  FOR_EACH_INTRINSIC_RETURN_PAIR_IMPL(F, I) \
  FOR_EACH_INTRINSIC_RETURN_OBJECT_IMPL(F, I)

613
#define FOR_EACH_INTRINSIC_RETURN_OBJECT(F) \
614
  FOR_EACH_INTRINSIC_RETURN_OBJECT_IMPL(F, F)
615

616 617 618 619 620 621 622 623 624
#define FOR_EACH_INTRINSIC_RETURN_PAIR(F) \
  FOR_EACH_INTRINSIC_RETURN_PAIR_IMPL(F, F)

// The list of all intrinsics, including those that have inline versions, but
// not the inline versions themselves.
#define FOR_EACH_INTRINSIC(F) FOR_EACH_INTRINSIC_IMPL(F, F)

// The list of all inline intrinsics only.
#define FOR_EACH_INLINE_INTRINSIC(I) FOR_EACH_INTRINSIC_IMPL(NOTHING, I)
625

626 627 628 629 630 631
#define F(name, nargs, ressize)                                 \
  Object* Runtime_##name(int args_length, Object** args_object, \
                         Isolate* isolate);
FOR_EACH_INTRINSIC_RETURN_OBJECT(F)
#undef F

632
//---------------------------------------------------------------------------
633 634 635 636
// Runtime provides access to all C++ runtime functions.

class Runtime : public AllStatic {
 public:
637
  enum FunctionId : int32_t {
638
#define F(name, nargs, ressize) k##name,
639
#define I(name, nargs, ressize) kInline##name,
640
    FOR_EACH_INTRINSIC(F) FOR_EACH_INLINE_INTRINSIC(I)
641
#undef I
642
#undef F
643
        kNumFunctions,
644 645
  };

646 647 648 649 650
  static constexpr int kNumInlineFunctions =
#define COUNT(...) +1
      FOR_EACH_INLINE_INTRINSIC(COUNT);
#undef COUNT

651
  enum IntrinsicType { RUNTIME, INLINE };
652

653
  // Intrinsic function descriptor.
654
  struct Function {
655 656
    FunctionId function_id;
    IntrinsicType intrinsic_type;
657 658 659
    // The JS name of the function.
    const char* name;

660 661 662
    // For RUNTIME functions, this is the C++ entry point.
    // For INLINE functions this is the C++ entry point of the fall back.
    Address entry;
663

664 665
    // The number of arguments expected. nargs is -1 if the function takes
    // a variable number of arguments.
666
    int8_t nargs;
667
    // Size of result.  Most functions return a single pointer, size 1.
668
    int8_t result_size;
669 670
  };

671 672
  static const int kNotFound = -1;

673 674 675 676 677
  // Checks whether the runtime function with the given {id} depends on the
  // "current context", i.e. because it does scoped lookups, or whether it's
  // fine to just pass any context within the same "native context".
  static bool NeedsExactContext(FunctionId id);

678 679 680 681 682 683
  // Checks whether the runtime function with the given {id} never returns
  // to it's caller normally, i.e. whether it'll always raise an exception.
  // More specifically: The C++ implementation returns the Heap::exception
  // sentinel, always.
  static bool IsNonReturning(FunctionId id);

684 685
  // Get the intrinsic function with the given name.
  static const Function* FunctionForName(const unsigned char* name, int length);
686

687
  // Get the intrinsic function with the given FunctionId.
688
  V8_EXPORT_PRIVATE static const Function* FunctionForId(FunctionId id);
689

690 691 692
  // Get the intrinsic function with the given function entry address.
  static const Function* FunctionForEntry(Address ref);

693 694 695
  // Get the runtime intrinsic function table.
  static const Function* RuntimeFunctionTable(Isolate* isolate);

696
  V8_WARN_UNUSED_RESULT static Maybe<bool> DeleteObjectProperty(
697 698 699
      Isolate* isolate, Handle<JSReceiver> receiver, Handle<Object> key,
      LanguageMode language_mode);

700
  V8_WARN_UNUSED_RESULT static MaybeHandle<Object> SetObjectProperty(
701
      Isolate* isolate, Handle<Object> object, Handle<Object> key,
702 703
      Handle<Object> value, LanguageMode language_mode,
      StoreOrigin store_origin);
704

705
  V8_WARN_UNUSED_RESULT static MaybeHandle<Object> GetObjectProperty(
706
      Isolate* isolate, Handle<Object> object, Handle<Object> key,
707
      bool* is_found_out = nullptr);
708

709
  V8_WARN_UNUSED_RESULT static MaybeHandle<JSArray> GetInternalProperties(
710
      Isolate* isolate, Handle<Object>);
711

712
  V8_WARN_UNUSED_RESULT static MaybeHandle<Object> ThrowIteratorError(
713
      Isolate* isolate, Handle<Object> object);
714 715
};

716

717 718
class RuntimeState {
 public:
719
#ifndef V8_INTL_SUPPORT
720 721 722 723 724 725
  unibrow::Mapping<unibrow::ToUppercase, 128>* to_upper_mapping() {
    return &to_upper_mapping_;
  }
  unibrow::Mapping<unibrow::ToLowercase, 128>* to_lower_mapping() {
    return &to_lower_mapping_;
  }
726
#endif
727 728 729 730 731 732 733

  Runtime::Function* redirected_intrinsic_functions() {
    return redirected_intrinsic_functions_.get();
  }

  void set_redirected_intrinsic_functions(
      Runtime::Function* redirected_intrinsic_functions) {
734
    redirected_intrinsic_functions_.reset(redirected_intrinsic_functions);
735 736 737
  }

 private:
738
  RuntimeState() = default;
739
#ifndef V8_INTL_SUPPORT
740 741
  unibrow::Mapping<unibrow::ToUppercase, 128> to_upper_mapping_;
  unibrow::Mapping<unibrow::ToLowercase, 128> to_lower_mapping_;
742
#endif
743

744
  std::unique_ptr<Runtime::Function[]> redirected_intrinsic_functions_;
745 746 747 748 749 750 751

  friend class Isolate;
  friend class Runtime;

  DISALLOW_COPY_AND_ASSIGN(RuntimeState);
};

752
V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream&, Runtime::FunctionId);
753

754 755 756
//---------------------------------------------------------------------------
// Constants used by interface to runtime functions.

757 758
class AllocateDoubleAlignFlag : public BitField<bool, 0, 1> {};
class AllocateTargetSpace : public BitField<AllocationSpace, 1, 3> {};
759

760 761
class DeclareGlobalsEvalFlag : public BitField<bool, 0, 1> {};
class DeclareGlobalsNativeFlag : public BitField<bool, 1, 1> {};
762

763 764 765 766 767 768 769 770 771 772
// A set of bits returned by Runtime_GetOptimizationStatus.
// These bits must be in sync with bits defined in test/mjsunit/mjsunit.js
enum class OptimizationStatus {
  kIsFunction = 1 << 0,
  kNeverOptimize = 1 << 1,
  kAlwaysOptimize = 1 << 2,
  kMaybeDeopted = 1 << 3,
  kOptimized = 1 << 4,
  kTurboFanned = 1 << 5,
  kInterpreted = 1 << 6,
773 774 775 776 777
  kMarkedForOptimization = 1 << 7,
  kMarkedForConcurrentOptimization = 1 << 8,
  kOptimizingConcurrently = 1 << 9,
  kIsExecuting = 1 << 10,
  kTopmostFrameIsTurboFanned = 1 << 11,
778 779
};

780 781
Smi* SmiLexicographicCompare(Smi* x_value, Smi* y_value);

782 783
}  // namespace internal
}  // namespace v8
784

785
#endif  // V8_RUNTIME_RUNTIME_H_