runtime.h 45.6 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
#include "src/allocation.h"
9
#include "src/objects.h"
10
#include "src/zone.h"
11

12 13
namespace v8 {
namespace internal {
14 15 16 17

// The interface to C++ runtime functions.

// ----------------------------------------------------------------------------
18 19 20
// RUNTIME_FUNCTION_LIST_ALWAYS defines runtime calls available in both
// release and debug mode.
// This macro should only be used by the macro RUNTIME_FUNCTION_LIST.
21

22 23 24
// WARNING: RUNTIME_FUNCTION_LIST_ALWAYS_* is a very large macro that caused
// MSVC Intellisense to crash.  It was broken into two macros to work around
// this problem. Please avoid large recursive macros whenever possible.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
#define RUNTIME_FUNCTION_LIST_ALWAYS_1(F)                  \
  /* Property access */                                    \
  F(GetProperty, 2, 1)                                     \
  F(KeyedGetProperty, 2, 1)                                \
  F(DeleteProperty, 3, 1)                                  \
  F(HasOwnProperty, 2, 1)                                  \
  F(HasProperty, 2, 1)                                     \
  F(HasElement, 2, 1)                                      \
  F(IsPropertyEnumerable, 2, 1)                            \
  F(GetPropertyNames, 1, 1)                                \
  F(GetPropertyNamesFast, 1, 1)                            \
  F(GetOwnPropertyNames, 2, 1)                             \
  F(GetOwnElementNames, 1, 1)                              \
  F(GetInterceptorInfo, 1, 1)                              \
  F(GetNamedInterceptorPropertyNames, 1, 1)                \
  F(GetIndexedInterceptorElementNames, 1, 1)               \
  F(GetArgumentsProperty, 1, 1)                            \
  F(ToFastProperties, 1, 1)                                \
  F(FinishArrayPrototypeSetup, 1, 1)                       \
  F(SpecialArrayFunctions, 0, 1)                           \
  F(IsSloppyModeFunction, 1, 1)                            \
  F(GetDefaultReceiver, 1, 1)                              \
                                                           \
  F(SetPrototype, 2, 1)                                    \
  F(InternalSetPrototype, 2, 1)                            \
  F(IsInPrototypeChain, 2, 1)                              \
                                                           \
  F(GetOwnProperty, 2, 1)                                  \
                                                           \
  F(IsExtensible, 1, 1)                                    \
  F(PreventExtensions, 1, 1)                               \
                                                           \
  /* Utilities */                                          \
  F(CheckIsBootstrapping, 0, 1)                            \
  F(GetRootNaN, 0, 1)                                      \
  F(Call, -1 /* >= 2 */, 1)                                \
  F(Apply, 5, 1)                                           \
  F(GetFunctionDelegate, 1, 1)                             \
  F(GetConstructorDelegate, 1, 1)                          \
  F(DeoptimizeFunction, 1, 1)                              \
  F(ClearFunctionTypeFeedback, 1, 1)                       \
  F(RunningInSimulator, 0, 1)                              \
  F(IsConcurrentRecompilationSupported, 0, 1)              \
  F(OptimizeFunctionOnNextCall, -1, 1)                     \
69
  F(OptimizeOsr, 0, 1)                                     \
70 71 72 73 74 75 76
  F(NeverOptimizeFunction, 1, 1)                           \
  F(GetOptimizationStatus, -1, 1)                          \
  F(GetOptimizationCount, 1, 1)                            \
  F(UnblockConcurrentRecompilation, 0, 1)                  \
  F(CompileForOnStackReplacement, 1, 1)                    \
  F(SetAllocationTimeout, -1 /* 2 || 3 */, 1)              \
  F(SetNativeFlag, 1, 1)                                   \
77
  F(IsConstructor, 1, 1)                                   \
78 79 80 81 82 83 84
  F(SetInlineBuiltinFlag, 1, 1)                            \
  F(StoreArrayLiteralElement, 5, 1)                        \
  F(DebugPrepareStepInIfStepping, 1, 1)                    \
  F(DebugPushPromise, 1, 1)                                \
  F(DebugPopPromise, 0, 1)                                 \
  F(DebugPromiseEvent, 1, 1)                               \
  F(DebugAsyncTaskEvent, 1, 1)                             \
85 86 87
  F(PromiseRejectEvent, 3, 1)                              \
  F(PromiseRevokeReject, 1, 1)                             \
  F(PromiseHasHandlerSymbol, 0, 1)                         \
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
  F(FlattenString, 1, 1)                                   \
  F(LoadMutableDouble, 2, 1)                               \
  F(TryMigrateInstance, 1, 1)                              \
  F(NotifyContextDisposed, 0, 1)                           \
                                                           \
  /* Array join support */                                 \
  F(PushIfAbsent, 2, 1)                                    \
  F(ArrayConcat, 1, 1)                                     \
                                                           \
  /* Conversions */                                        \
  F(ToBool, 1, 1)                                          \
  F(Typeof, 1, 1)                                          \
                                                           \
  F(Booleanize, 2, 1) /* TODO(turbofan): Only temporary */ \
                                                           \
  F(StringToNumber, 1, 1)                                  \
  F(StringParseInt, 2, 1)                                  \
  F(StringParseFloat, 1, 1)                                \
  F(StringToLowerCase, 1, 1)                               \
  F(StringToUpperCase, 1, 1)                               \
  F(StringSplit, 3, 1)                                     \
  F(CharFromCode, 1, 1)                                    \
  F(URIEscape, 1, 1)                                       \
  F(URIUnescape, 1, 1)                                     \
                                                           \
  F(NumberToInteger, 1, 1)                                 \
  F(NumberToIntegerMapMinusZero, 1, 1)                     \
  F(NumberToJSUint32, 1, 1)                                \
  F(NumberToJSInt32, 1, 1)                                 \
                                                           \
  /* Arithmetic operations */                              \
  F(NumberAdd, 2, 1)                                       \
  F(NumberSub, 2, 1)                                       \
  F(NumberMul, 2, 1)                                       \
  F(NumberDiv, 2, 1)                                       \
  F(NumberMod, 2, 1)                                       \
  F(NumberUnaryMinus, 1, 1)                                \
  F(NumberImul, 2, 1)                                      \
                                                           \
  F(StringBuilderConcat, 3, 1)                             \
  F(StringBuilderJoin, 3, 1)                               \
  F(SparseJoinWithSeparator, 3, 1)                         \
                                                           \
  /* Bit operations */                                     \
  F(NumberOr, 2, 1)                                        \
  F(NumberAnd, 2, 1)                                       \
  F(NumberXor, 2, 1)                                       \
                                                           \
  F(NumberShl, 2, 1)                                       \
  F(NumberShr, 2, 1)                                       \
  F(NumberSar, 2, 1)                                       \
                                                           \
  /* Comparisons */                                        \
  F(NumberEquals, 2, 1)                                    \
  F(StringEquals, 2, 1)                                    \
                                                           \
  F(NumberCompare, 3, 1)                                   \
  F(SmiLexicographicCompare, 2, 1)                         \
                                                           \
  /* Math */                                               \
  F(MathAcos, 1, 1)                                        \
  F(MathAsin, 1, 1)                                        \
  F(MathAtan, 1, 1)                                        \
  F(MathFloorRT, 1, 1)                                     \
  F(MathAtan2, 2, 1)                                       \
  F(MathExpRT, 1, 1)                                       \
  F(RoundNumber, 1, 1)                                     \
  F(MathFround, 1, 1)                                      \
156
  F(RemPiO2, 2, 1)                                         \
157 158
                                                           \
  /* Regular expressions */                                \
159
  F(RegExpInitializeAndCompile, 3, 1)                      \
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
  F(RegExpExecMultiple, 4, 1)                              \
                                                           \
  /* JSON */                                               \
  F(ParseJson, 1, 1)                                       \
  F(BasicJSONStringify, 1, 1)                              \
  F(QuoteJSONString, 1, 1)                                 \
                                                           \
  /* Strings */                                            \
  F(StringIndexOf, 3, 1)                                   \
  F(StringLastIndexOf, 3, 1)                               \
  F(StringLocaleCompare, 2, 1)                             \
  F(StringReplaceGlobalRegExpWithString, 4, 1)             \
  F(StringReplaceOneCharWithString, 3, 1)                  \
  F(StringMatch, 3, 1)                                     \
  F(StringTrim, 3, 1)                                      \
  F(StringToArray, 2, 1)                                   \
  F(NewStringWrapper, 1, 1)                                \
  F(NewString, 2, 1)                                       \
  F(TruncateString, 2, 1)                                  \
                                                           \
  /* Numbers */                                            \
  F(NumberToRadixString, 2, 1)                             \
  F(NumberToFixed, 2, 1)                                   \
  F(NumberToExponential, 2, 1)                             \
  F(NumberToPrecision, 2, 1)                               \
  F(IsValidSmi, 1, 1)                                      \
                                                           \
  /* Classes support */                                    \
  F(ToMethod, 2, 1)                                        \
189
  F(HomeObjectSymbol, 0, 1)                                \
190
  F(DefineClass, 6, 1)                                     \
191
  F(DefineClassMethod, 3, 1)                               \
192
  F(ClassGetSourceCode, 1, 1)                              \
193
  F(LoadFromSuper, 3, 1)                                   \
194
  F(LoadKeyedFromSuper, 3, 1)                              \
195 196 197
  F(ThrowConstructorNonCallableError, 0, 1)                \
  F(ThrowNonMethodError, 0, 1)                             \
  F(ThrowUnsupportedSuperError, 0, 1)                      \
198
  F(HandleStepInForDerivedConstructors, 1, 1)              \
199
  F(StoreToSuper_Strict, 4, 1)                             \
200
  F(StoreToSuper_Sloppy, 4, 1)                             \
201
  F(StoreKeyedToSuper_Strict, 4, 1)                        \
202
  F(StoreKeyedToSuper_Sloppy, 4, 1)
203

204

205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 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
#define RUNTIME_FUNCTION_LIST_ALWAYS_2(F)              \
  /* Reflection */                                     \
  F(FunctionSetInstanceClassName, 2, 1)                \
  F(FunctionSetLength, 2, 1)                           \
  F(FunctionSetPrototype, 2, 1)                        \
  F(FunctionGetName, 1, 1)                             \
  F(FunctionSetName, 2, 1)                             \
  F(FunctionNameShouldPrintAsAnonymous, 1, 1)          \
  F(FunctionMarkNameShouldPrintAsAnonymous, 1, 1)      \
  F(FunctionIsGenerator, 1, 1)                         \
  F(FunctionIsArrow, 1, 1)                             \
  F(FunctionIsConciseMethod, 1, 1)                     \
  F(FunctionBindArguments, 4, 1)                       \
  F(BoundFunctionGetBindings, 1, 1)                    \
  F(FunctionRemovePrototype, 1, 1)                     \
  F(FunctionGetSourceCode, 1, 1)                       \
  F(FunctionGetScript, 1, 1)                           \
  F(FunctionGetScriptSourcePosition, 1, 1)             \
  F(FunctionGetPositionForOffset, 2, 1)                \
  F(FunctionIsAPIFunction, 1, 1)                       \
  F(FunctionIsBuiltin, 1, 1)                           \
  F(GetScript, 1, 1)                                   \
  F(CollectStackTrace, 2, 1)                           \
  F(GetV8Version, 0, 1)                                \
  F(GeneratorGetFunction, 1, 1)                        \
  F(GeneratorGetContext, 1, 1)                         \
  F(GeneratorGetReceiver, 1, 1)                        \
  F(GeneratorGetContinuation, 1, 1)                    \
  F(GeneratorGetSourcePosition, 1, 1)                  \
                                                       \
  F(SetCode, 2, 1)                                     \
                                                       \
  F(DisableAccessChecks, 1, 1)                         \
  F(EnableAccessChecks, 1, 1)                          \
                                                       \
  /* Dates */                                          \
  F(DateCurrentTime, 0, 1)                             \
  F(DateParseString, 2, 1)                             \
  F(DateLocalTimezone, 1, 1)                           \
  F(DateToUTC, 1, 1)                                   \
  F(DateMakeDay, 2, 1)                                 \
  F(DateSetValue, 3, 1)                                \
  F(DateCacheVersion, 0, 1)                            \
                                                       \
  /* Globals */                                        \
250
  F(CompileString, 3, 1)                               \
251 252 253 254 255 256 257 258 259 260
                                                       \
  /* Eval */                                           \
  F(GlobalProxy, 1, 1)                                 \
                                                       \
  F(AddNamedProperty, 4, 1)                            \
  F(SetProperty, 4, 1)                                 \
  F(AddElement, 4, 1)                                  \
  F(DefineDataPropertyUnchecked, 4, 1)                 \
  F(DefineAccessorPropertyUnchecked, 5, 1)             \
  F(GetDataProperty, 2, 1)                             \
261 262
  F(DefineGetterPropertyUnchecked, 4, 1)               \
  F(DefineSetterPropertyUnchecked, 4, 1)               \
263 264 265 266 267 268 269
                                                       \
  /* Arrays */                                         \
  F(RemoveArrayHoles, 2, 1)                            \
  F(GetArrayKeys, 2, 1)                                \
  F(MoveArrayContents, 2, 1)                           \
  F(EstimateNumberOfElements, 1, 1)                    \
  F(NormalizeElements, 1, 1)                           \
270
  F(HasComplexElements, 1, 1)                          \
271 272 273 274 275
                                                       \
  /* Getters and Setters */                            \
  F(LookupAccessor, 3, 1)                              \
                                                       \
  /* ES5 */                                            \
276
  F(ObjectSeal, 1, 1)                                  \
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
  F(ObjectFreeze, 1, 1)                                \
                                                       \
  /* Harmony modules */                                \
  F(IsJSModule, 1, 1)                                  \
                                                       \
  /* Harmony symbols */                                \
  F(CreateSymbol, 1, 1)                                \
  F(CreatePrivateSymbol, 1, 1)                         \
  F(CreateGlobalPrivateOwnSymbol, 1, 1)                \
  F(CreatePrivateOwnSymbol, 1, 1)                      \
  F(NewSymbolWrapper, 1, 1)                            \
  F(SymbolDescription, 1, 1)                           \
  F(SymbolRegistry, 0, 1)                              \
  F(SymbolIsPrivate, 1, 1)                             \
                                                       \
  /* Harmony proxies */                                \
  F(CreateJSProxy, 2, 1)                               \
  F(CreateJSFunctionProxy, 4, 1)                       \
  F(IsJSFunctionProxy, 1, 1)                           \
  F(GetHandler, 1, 1)                                  \
  F(GetCallTrap, 1, 1)                                 \
  F(GetConstructTrap, 1, 1)                            \
  F(Fix, 1, 1)                                         \
                                                       \
301
  /* ES6 collection iterators */                       \
302
  F(SetIteratorInitialize, 3, 1)                       \
303
  F(SetIteratorClone, 1, 1)                            \
304
  F(SetIteratorNext, 2, 1)                             \
305
  F(SetIteratorDetails, 1, 1)                          \
306
  F(MapIteratorInitialize, 3, 1)                       \
307
  F(MapIteratorClone, 1, 1)                            \
308
  F(MapIteratorNext, 2, 1)                             \
309
  F(MapIteratorDetails, 1, 1)                          \
310 311 312 313 314 315 316 317
                                                       \
  /* Harmony weak maps and sets */                     \
  F(WeakCollectionInitialize, 1, 1)                    \
  F(WeakCollectionGet, 2, 1)                           \
  F(WeakCollectionHas, 2, 1)                           \
  F(WeakCollectionDelete, 2, 1)                        \
  F(WeakCollectionSet, 3, 1)                           \
                                                       \
318 319
  F(GetWeakMapEntries, 2, 1)                           \
  F(GetWeakSetValues, 2, 1)                            \
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
                                                       \
  /* Harmony events */                                 \
  F(EnqueueMicrotask, 1, 1)                            \
  F(RunMicrotasks, 0, 1)                               \
                                                       \
  /* Harmony observe */                                \
  F(IsObserved, 1, 1)                                  \
  F(SetIsObserved, 1, 1)                               \
  F(GetObservationState, 0, 1)                         \
  F(ObservationWeakMapCreate, 0, 1)                    \
  F(ObserverObjectAndRecordHaveSameOrigin, 3, 1)       \
  F(ObjectWasCreatedInCurrentOrigin, 1, 1)             \
  F(GetObjectContextObjectObserve, 1, 1)               \
  F(GetObjectContextObjectGetNotifier, 1, 1)           \
  F(GetObjectContextNotifierPerformChange, 1, 1)       \
335
  F(DeliverObservationChangeRecords, 2, 1)             \
336 337 338 339 340 341 342
                                                       \
  /* Harmony typed arrays */                           \
  F(ArrayBufferInitialize, 2, 1)                       \
  F(ArrayBufferSliceImpl, 3, 1)                        \
  F(ArrayBufferIsView, 1, 1)                           \
  F(ArrayBufferNeuter, 1, 1)                           \
                                                       \
343
  F(IsTypedArray, 1, 1)                                \
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
  F(TypedArrayInitializeFromArrayLike, 4, 1)           \
  F(TypedArrayGetBuffer, 1, 1)                         \
  F(TypedArraySetFastCases, 3, 1)                      \
                                                       \
  F(DataViewGetBuffer, 1, 1)                           \
  F(DataViewGetInt8, 3, 1)                             \
  F(DataViewGetUint8, 3, 1)                            \
  F(DataViewGetInt16, 3, 1)                            \
  F(DataViewGetUint16, 3, 1)                           \
  F(DataViewGetInt32, 3, 1)                            \
  F(DataViewGetUint32, 3, 1)                           \
  F(DataViewGetFloat32, 3, 1)                          \
  F(DataViewGetFloat64, 3, 1)                          \
                                                       \
  F(DataViewSetInt8, 4, 1)                             \
  F(DataViewSetUint8, 4, 1)                            \
  F(DataViewSetInt16, 4, 1)                            \
  F(DataViewSetUint16, 4, 1)                           \
  F(DataViewSetInt32, 4, 1)                            \
  F(DataViewSetUint32, 4, 1)                           \
  F(DataViewSetFloat32, 4, 1)                          \
  F(DataViewSetFloat64, 4, 1)                          \
                                                       \
  /* Statements */                                     \
  F(NewObjectFromBound, 1, 1)                          \
                                                       \
  /* Declarations and initialization */                \
  F(InitializeVarGlobal, 3, 1)                         \
  F(OptimizeObjectForAddingMultipleProperties, 2, 1)   \
                                                       \
  /* Debugging */                                      \
  F(DebugPrint, 1, 1)                                  \
  F(GlobalPrint, 1, 1)                                 \
  F(DebugTrace, 0, 1)                                  \
  F(TraceEnter, 0, 1)                                  \
  F(TraceExit, 1, 1)                                   \
  F(Abort, 1, 1)                                       \
  F(AbortJS, 1, 1)                                     \
382
  F(NativeScriptsCount, 0, 1)                          \
383
  F(RenderCallSite, 0, 1)                              \
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
  /* ES5 */                                            \
  F(OwnKeys, 1, 1)                                     \
                                                       \
  /* Message objects */                                \
  F(MessageGetStartPosition, 1, 1)                     \
  F(MessageGetScript, 1, 1)                            \
                                                       \
  /* Pseudo functions - handled as macros by parser */ \
  F(IS_VAR, 1, 1)                                      \
                                                       \
  /* expose boolean functions from objects-inl.h */    \
  F(HasFastSmiElements, 1, 1)                          \
  F(HasFastSmiOrObjectElements, 1, 1)                  \
  F(HasFastObjectElements, 1, 1)                       \
  F(HasFastDoubleElements, 1, 1)                       \
  F(HasFastHoleyElements, 1, 1)                        \
  F(HasDictionaryElements, 1, 1)                       \
  F(HasSloppyArgumentsElements, 1, 1)                  \
  F(HasExternalUint8ClampedElements, 1, 1)             \
  F(HasExternalArrayElements, 1, 1)                    \
  F(HasExternalInt8Elements, 1, 1)                     \
  F(HasExternalUint8Elements, 1, 1)                    \
  F(HasExternalInt16Elements, 1, 1)                    \
  F(HasExternalUint16Elements, 1, 1)                   \
  F(HasExternalInt32Elements, 1, 1)                    \
  F(HasExternalUint32Elements, 1, 1)                   \
  F(HasExternalFloat32Elements, 1, 1)                  \
  F(HasExternalFloat64Elements, 1, 1)                  \
  F(HasFixedUint8ClampedElements, 1, 1)                \
  F(HasFixedInt8Elements, 1, 1)                        \
  F(HasFixedUint8Elements, 1, 1)                       \
  F(HasFixedInt16Elements, 1, 1)                       \
  F(HasFixedUint16Elements, 1, 1)                      \
  F(HasFixedInt32Elements, 1, 1)                       \
  F(HasFixedUint32Elements, 1, 1)                      \
  F(HasFixedFloat32Elements, 1, 1)                     \
  F(HasFixedFloat64Elements, 1, 1)                     \
  F(HasFastProperties, 1, 1)                           \
  F(TransitionElementsKind, 2, 1)                      \
  F(HaveSameMap, 2, 1)                                 \
  F(IsJSGlobalProxy, 1, 1)                             \
425 426 427
  F(ForInCacheArrayLength, 2, 1) /* TODO(turbofan): Only temporary */


428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461
#define RUNTIME_FUNCTION_LIST_ALWAYS_3(F)                    \
  /* String and Regexp */                                    \
  F(NumberToStringRT, 1, 1)                                  \
  F(RegExpConstructResult, 3, 1)                             \
  F(RegExpExecRT, 4, 1)                                      \
  F(StringAdd, 2, 1)                                         \
  F(SubString, 3, 1)                                         \
  F(InternalizeString, 1, 1)                                 \
  F(StringCompare, 2, 1)                                     \
  F(StringCharCodeAtRT, 2, 1)                                \
  F(GetFromCache, 2, 1)                                      \
                                                             \
  /* Compilation */                                          \
  F(CompileLazy, 1, 1)                                       \
  F(CompileOptimized, 2, 1)                                  \
  F(TryInstallOptimizedCode, 1, 1)                           \
  F(NotifyDeoptimized, 1, 1)                                 \
  F(NotifyStubFailure, 0, 1)                                 \
                                                             \
  /* Utilities */                                            \
  F(AllocateInNewSpace, 1, 1)                                \
  F(AllocateInTargetSpace, 2, 1)                             \
  F(AllocateHeapNumber, 0, 1)                                \
  F(NumberToSmi, 1, 1)                                       \
  F(NumberToStringSkipCache, 1, 1)                           \
                                                             \
  F(NewArguments, 1, 1) /* TODO(turbofan): Only temporary */ \
  F(NewSloppyArguments, 3, 1)                                \
  F(NewStrictArguments, 3, 1)                                \
                                                             \
  /* Harmony generators */                                   \
  F(CreateJSGeneratorObject, 0, 1)                           \
  F(SuspendJSGeneratorObject, 1, 1)                          \
  F(ResumeJSGeneratorObject, 3, 1)                           \
462
  F(GeneratorClose, 1, 1)                                    \
463 464 465 466 467 468 469 470 471 472 473 474 475 476
                                                             \
  /* Arrays */                                               \
  F(ArrayConstructor, -1, 1)                                 \
  F(InternalArrayConstructor, -1, 1)                         \
                                                             \
  /* Literals */                                             \
  F(MaterializeRegExpLiteral, 4, 1)                          \
  F(CreateObjectLiteral, 4, 1)                               \
  F(CreateArrayLiteral, 4, 1)                                \
  F(CreateArrayLiteralStubBailout, 3, 1)                     \
                                                             \
  /* Statements */                                           \
  F(NewClosure, 3, 1)                                        \
  F(NewClosureFromStubFailure, 1, 1)                         \
477 478
  F(NewObject, 2, 1)                                         \
  F(NewObjectWithAllocationSite, 3, 1)                       \
479 480 481 482 483
  F(FinalizeInstanceSize, 1, 1)                              \
  F(Throw, 1, 1)                                             \
  F(ReThrow, 1, 1)                                           \
  F(ThrowReferenceError, 1, 1)                               \
  F(ThrowNotDateError, 0, 1)                                 \
484
  F(ThrowConstAssignError, 0, 1)                             \
485 486 487 488 489
  F(StackGuard, 0, 1)                                        \
  F(Interrupt, 0, 1)                                         \
  F(PromoteScheduledException, 0, 1)                         \
                                                             \
  /* Contexts */                                             \
490
  F(NewScriptContext, 2, 1)                                  \
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
  F(NewFunctionContext, 1, 1)                                \
  F(PushWithContext, 2, 1)                                   \
  F(PushCatchContext, 3, 1)                                  \
  F(PushBlockContext, 2, 1)                                  \
  F(PushModuleContext, 2, 1)                                 \
  F(DeleteLookupSlot, 2, 1)                                  \
  F(StoreLookupSlot, 4, 1)                                   \
                                                             \
  /* Declarations and initialization */                      \
  F(DeclareGlobals, 3, 1)                                    \
  F(DeclareModules, 1, 1)                                    \
  F(DeclareLookupSlot, 4, 1)                                 \
  F(InitializeConstGlobal, 2, 1)                             \
  F(InitializeLegacyConstLookupSlot, 3, 1)                   \
                                                             \
  /* Maths */                                                \
  F(MathPowSlow, 2, 1)                                       \
508 509 510
  F(MathPowRT, 2, 1)


511 512 513
#define RUNTIME_FUNCTION_LIST_RETURN_PAIR(F)              \
  F(LoadLookupSlot, 2, 2)                                 \
  F(LoadLookupSlotNoReferenceError, 2, 2)                 \
514
  F(ResolvePossiblyDirectEval, 6, 2)                      \
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564
  F(ForInInit, 2, 2) /* TODO(turbofan): Only temporary */ \
  F(ForInNext, 4, 2) /* TODO(turbofan): Only temporary */


#define RUNTIME_FUNCTION_LIST_DEBUGGER(F)           \
  /* Debugger support*/                             \
  F(DebugBreak, 0, 1)                               \
  F(SetDebugEventListener, 2, 1)                    \
  F(Break, 0, 1)                                    \
  F(DebugGetPropertyDetails, 2, 1)                  \
  F(DebugGetProperty, 2, 1)                         \
  F(DebugPropertyTypeFromDetails, 1, 1)             \
  F(DebugPropertyAttributesFromDetails, 1, 1)       \
  F(DebugPropertyIndexFromDetails, 1, 1)            \
  F(DebugNamedInterceptorPropertyValue, 2, 1)       \
  F(DebugIndexedInterceptorElementValue, 2, 1)      \
  F(CheckExecutionState, 1, 1)                      \
  F(GetFrameCount, 1, 1)                            \
  F(GetFrameDetails, 2, 1)                          \
  F(GetScopeCount, 2, 1)                            \
  F(GetStepInPositions, 2, 1)                       \
  F(GetScopeDetails, 4, 1)                          \
  F(GetAllScopesDetails, 4, 1)                      \
  F(GetFunctionScopeCount, 1, 1)                    \
  F(GetFunctionScopeDetails, 2, 1)                  \
  F(SetScopeVariableValue, 6, 1)                    \
  F(DebugPrintScopes, 0, 1)                         \
  F(GetThreadCount, 1, 1)                           \
  F(GetThreadDetails, 2, 1)                         \
  F(SetDisableBreak, 1, 1)                          \
  F(GetBreakLocations, 2, 1)                        \
  F(SetFunctionBreakPoint, 3, 1)                    \
  F(SetScriptBreakPoint, 4, 1)                      \
  F(ClearBreakPoint, 1, 1)                          \
  F(ChangeBreakOnException, 2, 1)                   \
  F(IsBreakOnException, 1, 1)                       \
  F(PrepareStep, 4, 1)                              \
  F(ClearStepping, 0, 1)                            \
  F(DebugEvaluate, 6, 1)                            \
  F(DebugEvaluateGlobal, 4, 1)                      \
  F(DebugGetLoadedScripts, 0, 1)                    \
  F(DebugReferencedBy, 3, 1)                        \
  F(DebugConstructedBy, 2, 1)                       \
  F(DebugGetPrototype, 1, 1)                        \
  F(DebugSetScriptSource, 2, 1)                     \
  F(DebugCallbackSupportsStepping, 1, 1)            \
  F(SystemBreak, 0, 1)                              \
  F(DebugDisassembleFunction, 1, 1)                 \
  F(DebugDisassembleConstructor, 1, 1)              \
  F(FunctionGetInferredName, 1, 1)                  \
565
  F(LiveEditFindSharedFunctionInfosForScript, 1, 1) \
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581
  F(LiveEditGatherCompileInfo, 2, 1)                \
  F(LiveEditReplaceScript, 3, 1)                    \
  F(LiveEditReplaceFunctionCode, 2, 1)              \
  F(LiveEditFunctionSourceUpdated, 1, 1)            \
  F(LiveEditFunctionSetScript, 2, 1)                \
  F(LiveEditReplaceRefToNestedFunction, 3, 1)       \
  F(LiveEditPatchFunctionPositions, 2, 1)           \
  F(LiveEditCheckAndDropActivations, 2, 1)          \
  F(LiveEditCompareStrings, 2, 1)                   \
  F(LiveEditRestartFrame, 2, 1)                     \
  F(GetFunctionCodePositionFromSource, 2, 1)        \
  F(ExecuteInDebugContext, 2, 1)                    \
                                                    \
  F(SetFlags, 1, 1)                                 \
  F(CollectGarbage, 1, 1)                           \
  F(GetHeapUsage, 0, 1)
582

583 584 585

#ifdef V8_I18N_SUPPORT
#define RUNTIME_FUNCTION_LIST_I18N_SUPPORT(F) \
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 613 614 615 616 617 618 619 620
  /* i18n support */                          \
  /* Standalone, helper methods. */           \
  F(CanonicalizeLanguageTag, 1, 1)            \
  F(AvailableLocalesOf, 1, 1)                 \
  F(GetDefaultICULocale, 0, 1)                \
  F(GetLanguageTagVariants, 1, 1)             \
  F(IsInitializedIntlObject, 1, 1)            \
  F(IsInitializedIntlObjectOfType, 2, 1)      \
  F(MarkAsInitializedIntlObjectOfType, 3, 1)  \
  F(GetImplFromInitializedIntlObject, 1, 1)   \
                                              \
  /* Date format and parse. */                \
  F(CreateDateTimeFormat, 3, 1)               \
  F(InternalDateFormat, 2, 1)                 \
  F(InternalDateParse, 2, 1)                  \
                                              \
  /* Number format and parse. */              \
  F(CreateNumberFormat, 3, 1)                 \
  F(InternalNumberFormat, 2, 1)               \
  F(InternalNumberParse, 2, 1)                \
                                              \
  /* Collator. */                             \
  F(CreateCollator, 3, 1)                     \
  F(InternalCompare, 3, 1)                    \
                                              \
  /* String.prototype.normalize. */           \
  F(StringNormalize, 2, 1)                    \
                                              \
  /* Break iterator. */                       \
  F(CreateBreakIterator, 3, 1)                \
  F(BreakIteratorAdoptText, 2, 1)             \
  F(BreakIteratorFirst, 1, 1)                 \
  F(BreakIteratorNext, 1, 1)                  \
  F(BreakIteratorCurrent, 1, 1)               \
  F(BreakIteratorBreakType, 1, 1)
621 622 623 624 625 626

#else
#define RUNTIME_FUNCTION_LIST_I18N_SUPPORT(F)
#endif


627 628 629 630
// ----------------------------------------------------------------------------
// RUNTIME_FUNCTION_LIST defines all runtime functions accessed
// either directly by id (via the code generator), or indirectly
// via a native call by name (from within JS code).
631
// Entries have the form F(name, number of arguments, number of return values).
632

633 634 635 636 637
#define RUNTIME_FUNCTION_LIST_RETURN_OBJECT(F) \
  RUNTIME_FUNCTION_LIST_ALWAYS_1(F)            \
  RUNTIME_FUNCTION_LIST_ALWAYS_2(F)            \
  RUNTIME_FUNCTION_LIST_ALWAYS_3(F)            \
  RUNTIME_FUNCTION_LIST_DEBUGGER(F)            \
638 639
  RUNTIME_FUNCTION_LIST_I18N_SUPPORT(F)

640 641 642 643 644

#define RUNTIME_FUNCTION_LIST(F)         \
  RUNTIME_FUNCTION_LIST_RETURN_OBJECT(F) \
  RUNTIME_FUNCTION_LIST_RETURN_PAIR(F)

645
// ----------------------------------------------------------------------------
646 647 648
// INLINE_FUNCTION_LIST defines all inlined functions accessed
// with a native call of the form %_name from within JS code.
// Entries have the form F(name, number of arguments, number of return values).
649 650 651 652 653
#define INLINE_FUNCTION_LIST(F)                             \
  F(IsSmi, 1, 1)                                            \
  F(IsNonNegativeSmi, 1, 1)                                 \
  F(IsArray, 1, 1)                                          \
  F(IsRegExp, 1, 1)                                         \
654
  F(IsJSProxy, 1, 1)                                        \
655 656
  F(IsConstructCall, 0, 1)                                  \
  F(CallFunction, -1 /* receiver + n args + function */, 1) \
657
  F(DefaultConstructorCallSuper, 0, 1)                      \
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689
  F(ArgumentsLength, 0, 1)                                  \
  F(Arguments, 1, 1)                                        \
  F(ValueOf, 1, 1)                                          \
  F(SetValueOf, 2, 1)                                       \
  F(DateField, 2 /* date object, field index */, 1)         \
  F(StringCharFromCode, 1, 1)                               \
  F(StringCharAt, 2, 1)                                     \
  F(OneByteSeqStringSetChar, 3, 1)                          \
  F(TwoByteSeqStringSetChar, 3, 1)                          \
  F(ObjectEquals, 2, 1)                                     \
  F(IsObject, 1, 1)                                         \
  F(IsFunction, 1, 1)                                       \
  F(IsUndetectableObject, 1, 1)                             \
  F(IsSpecObject, 1, 1)                                     \
  F(IsStringWrapperSafeForDefaultValueOf, 1, 1)             \
  F(MathPow, 2, 1)                                          \
  F(IsMinusZero, 1, 1)                                      \
  F(HasCachedArrayIndex, 1, 1)                              \
  F(GetCachedArrayIndex, 1, 1)                              \
  F(FastOneByteArrayJoin, 2, 1)                             \
  F(GeneratorNext, 2, 1)                                    \
  F(GeneratorThrow, 2, 1)                                   \
  F(DebugBreakInOptimizedCode, 0, 1)                        \
  F(ClassOf, 1, 1)                                          \
  F(StringCharCodeAt, 2, 1)                                 \
  F(StringAdd, 2, 1)                                        \
  F(SubString, 3, 1)                                        \
  F(StringCompare, 2, 1)                                    \
  F(RegExpExec, 4, 1)                                       \
  F(RegExpConstructResult, 3, 1)                            \
  F(GetFromCache, 2, 1)                                     \
  F(NumberToString, 1, 1)                                   \
690
  F(DebugIsActive, 0, 1)
691 692 693 694 695 696


// ----------------------------------------------------------------------------
// INLINE_OPTIMIZED_FUNCTION_LIST defines all inlined functions accessed
// with a native call of the form %_name from within JS code that also have
// a corresponding runtime function, that is called from non-optimized code.
697 698
// For the benefit of (fuzz) tests, the runtime version can also be called
// directly as %name (i.e. without the leading underscore).
699 700
// Entries have the form F(name, number of arguments, number of return values).
#define INLINE_OPTIMIZED_FUNCTION_LIST(F) \
701 702 703 704 705 706 707 708 709 710 711 712 713 714 715
  /* Typed Arrays */                      \
  F(TypedArrayInitialize, 5, 1)           \
  F(DataViewInitialize, 4, 1)             \
  F(MaxSmi, 0, 1)                         \
  F(TypedArrayMaxSizeInHeap, 0, 1)        \
  F(ArrayBufferViewGetByteLength, 1, 1)   \
  F(ArrayBufferViewGetByteOffset, 1, 1)   \
  F(TypedArrayGetLength, 1, 1)            \
  /* ArrayBuffer */                       \
  F(ArrayBufferGetByteLength, 1, 1)       \
  /* Maths */                             \
  F(ConstructDouble, 2, 1)                \
  F(DoubleHi, 1, 1)                       \
  F(DoubleLo, 1, 1)                       \
  F(MathSqrtRT, 1, 1)                     \
716 717
  F(MathLogRT, 1, 1)                      \
  /* ES6 Collections */                   \
718
  F(MapClear, 1, 1)                       \
719
  F(MapDelete, 2, 1)                      \
720 721 722
  F(MapGet, 2, 1)                         \
  F(MapGetSize, 1, 1)                     \
  F(MapHas, 2, 1)                         \
723
  F(MapInitialize, 1, 1)                  \
724 725
  F(MapSet, 3, 1)                         \
  F(SetAdd, 2, 1)                         \
726
  F(SetClear, 1, 1)                       \
727
  F(SetDelete, 2, 1)                      \
728
  F(SetGetSize, 1, 1)                     \
729
  F(SetHas, 2, 1)                         \
730
  F(SetInitialize, 1, 1)                  \
731
  /* Arrays */                            \
arv's avatar
arv committed
732 733
  F(HasFastPackedElements, 1, 1)          \
  F(GetPrototype, 1, 1)
734 735 736


//---------------------------------------------------------------------------
737 738
// Runtime provides access to all C++ runtime functions.

739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759
class RuntimeState {
 public:
  unibrow::Mapping<unibrow::ToUppercase, 128>* to_upper_mapping() {
    return &to_upper_mapping_;
  }
  unibrow::Mapping<unibrow::ToLowercase, 128>* to_lower_mapping() {
    return &to_lower_mapping_;
  }

 private:
  RuntimeState() {}
  unibrow::Mapping<unibrow::ToUppercase, 128> to_upper_mapping_;
  unibrow::Mapping<unibrow::ToLowercase, 128> to_lower_mapping_;

  friend class Isolate;
  friend class Runtime;

  DISALLOW_COPY_AND_ASSIGN(RuntimeState);
};


760 761 762
class JavaScriptFrameIterator;  // Forward declaration.


763 764 765
class Runtime : public AllStatic {
 public:
  enum FunctionId {
766
#define F(name, nargs, ressize) k##name,
767
    RUNTIME_FUNCTION_LIST(F) INLINE_OPTIMIZED_FUNCTION_LIST(F)
768
#undef F
769 770
#define F(name, nargs, ressize) kInline##name,
    INLINE_FUNCTION_LIST(F)
771 772 773
#undef F
#define F(name, nargs, ressize) kInlineOptimized##name,
    INLINE_OPTIMIZED_FUNCTION_LIST(F)
774 775 776 777 778
#undef F
    kNumFunctions,
    kFirstInlineFunction = kInlineIsSmi
  };

779
  enum IntrinsicType { RUNTIME, INLINE, INLINE_OPTIMIZED };
780

781
  // Intrinsic function descriptor.
782
  struct Function {
783 784
    FunctionId function_id;
    IntrinsicType intrinsic_type;
785 786 787
    // The JS name of the function.
    const char* name;

788
    // The C++ (native) entry point.  NULL if the function is inlined.
789 790
    byte* entry;

791 792
    // The number of arguments expected. nargs is -1 if the function takes
    // a variable number of arguments.
793
    int nargs;
794
    // Size of result.  Most functions return a single pointer, size 1.
795
    int result_size;
796 797
  };

798 799
  static const int kNotFound = -1;

800 801
  // Add internalized strings for all the intrinsic function names to a
  // StringDictionary.
802 803
  static void InitializeIntrinsicFunctionNames(Isolate* isolate,
                                               Handle<NameDictionary> dict);
804

805 806
  // Get the intrinsic function with the given name, which must be internalized.
  static const Function* FunctionForName(Handle<String> name);
807

808
  // Get the intrinsic function with the given FunctionId.
809
  static const Function* FunctionForId(FunctionId id);
810

811 812 813
  // Get the intrinsic function with the given function entry address.
  static const Function* FunctionForEntry(Address ref);

814 815
  // TODO(1240886): Some of the following methods are *not* handle safe, but
  // accept handle arguments. This seems fragile.
816 817 818

  // Support getting the characters in a string using [] notation as
  // in Firefox/SpiderMonkey, Safari and Opera.
819
  MUST_USE_RESULT static MaybeHandle<Object> GetElementOrCharAt(
820
      Isolate* isolate, Handle<Object> object, uint32_t index);
821

822
  MUST_USE_RESULT static MaybeHandle<Object> SetObjectProperty(
823
      Isolate* isolate, Handle<Object> object, Handle<Object> key,
824
      Handle<Object> value, LanguageMode language_mode);
825

826
  MUST_USE_RESULT static MaybeHandle<Object> DefineObjectProperty(
827 828
      Handle<JSObject> object, Handle<Object> key, Handle<Object> value,
      PropertyAttributes attr);
829

830
  MUST_USE_RESULT static MaybeHandle<Object> GetObjectProperty(
831
      Isolate* isolate, Handle<Object> object, Handle<Object> key);
832

833 834 835
  MUST_USE_RESULT static MaybeHandle<Object> GetPrototype(
      Isolate* isolate, Handle<Object> object);

836 837 838
  MUST_USE_RESULT static MaybeHandle<Name> ToName(Isolate* isolate,
                                                  Handle<Object> key);

839
  static void SetupArrayBuffer(Isolate* isolate,
840
                               Handle<JSArrayBuffer> array_buffer,
841
                               bool is_external, void* data,
842 843
                               size_t allocated_length);

844 845 846 847
  static bool SetupArrayBufferAllocatingData(Isolate* isolate,
                                             Handle<JSArrayBuffer> array_buffer,
                                             size_t allocated_length,
                                             bool initialize = true);
848

849 850
  static void NeuterArrayBuffer(Handle<JSArrayBuffer> array_buffer);

851 852
  static void FreeArrayBuffer(Isolate* isolate,
                              JSArrayBuffer* phantom_array_buffer);
853

854 855
  static int FindIndexedNonNativeFrame(JavaScriptFrameIterator* it, int index);

856 857 858 859 860 861 862 863 864 865
  enum TypedArrayId {
    // arrayIds below should be synchromized with typedarray.js natives.
    ARRAY_ID_UINT8 = 1,
    ARRAY_ID_INT8 = 2,
    ARRAY_ID_UINT16 = 3,
    ARRAY_ID_INT16 = 4,
    ARRAY_ID_UINT32 = 5,
    ARRAY_ID_INT32 = 6,
    ARRAY_ID_FLOAT32 = 7,
    ARRAY_ID_FLOAT64 = 8,
866 867 868
    ARRAY_ID_UINT8_CLAMPED = 9,
    ARRAY_ID_FIRST = ARRAY_ID_UINT8,
    ARRAY_ID_LAST = ARRAY_ID_UINT8_CLAMPED
869 870
  };

871 872 873 874
  static void ArrayIdToTypeAndSize(int array_id, ExternalArrayType* type,
                                   ElementsKind* external_elements_kind,
                                   ElementsKind* fixed_elements_kind,
                                   size_t* element_size);
875

876
  // Used in runtime.cc and hydrogen's VisitArrayLiteral.
877
  MUST_USE_RESULT static MaybeHandle<Object> CreateArrayLiteralBoilerplate(
878
      Isolate* isolate, Handle<FixedArray> literals,
879
      Handle<FixedArray> elements);
yurys's avatar
yurys committed
880 881 882 883 884 885 886

  static void WeakCollectionInitialize(
      Isolate* isolate, Handle<JSWeakCollection> weak_collection);
  static void WeakCollectionSet(Handle<JSWeakCollection> weak_collection,
                                Handle<Object> key, Handle<Object> value);
  static bool WeakCollectionDelete(Handle<JSWeakCollection> weak_collection,
                                   Handle<Object> key);
887 888
};

889

890 891
std::ostream& operator<<(std::ostream&, Runtime::FunctionId);

892 893 894
//---------------------------------------------------------------------------
// Constants used by interface to runtime functions.

895 896
class AllocateDoubleAlignFlag : public BitField<bool, 0, 1> {};
class AllocateTargetSpace : public BitField<AllocationSpace, 1, 3> {};
897

898 899
class DeclareGlobalsEvalFlag : public BitField<bool, 0, 1> {};
class DeclareGlobalsNativeFlag : public BitField<bool, 1, 1> {};
marja's avatar
marja committed
900 901
STATIC_ASSERT(LANGUAGE_END == 3);
class DeclareGlobalsLanguageMode : public BitField<LanguageMode, 2, 2> {};
902 903 904

}  // namespace internal
}  // namespace v8
905

906
#endif  // V8_RUNTIME_RUNTIME_H_