runtime.h 28.7 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 7

#ifndef V8_RUNTIME_H_
#define V8_RUNTIME_H_

8 9
#include "src/allocation.h"
#include "src/zone.h"
10

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

// The interface to C++ runtime functions.

// ----------------------------------------------------------------------------
17 18 19
// 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.
20

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.
#define RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
25
  /* Property access */ \
26 27
  F(GetProperty, 2, 1) \
  F(KeyedGetProperty, 2, 1) \
28
  F(DeleteProperty, 3, 1) \
29
  F(HasOwnProperty, 2, 1) \
30 31 32 33 34
  F(HasProperty, 2, 1) \
  F(HasElement, 2, 1) \
  F(IsPropertyEnumerable, 2, 1) \
  F(GetPropertyNames, 1, 1) \
  F(GetPropertyNamesFast, 1, 1) \
35 36
  F(GetOwnPropertyNames, 2, 1) \
  F(GetOwnElementNames, 1, 1) \
37 38 39
  F(GetInterceptorInfo, 1, 1) \
  F(GetNamedInterceptorPropertyNames, 1, 1) \
  F(GetIndexedInterceptorElementNames, 1, 1) \
40 41
  F(GetArgumentsProperty, 1, 1) \
  F(ToFastProperties, 1, 1) \
42
  F(FinishArrayPrototypeSetup, 1, 1) \
43
  F(SpecialArrayFunctions, 0, 1) \
44
  F(IsSloppyModeFunction, 1, 1) \
45
  F(GetDefaultReceiver, 1, 1) \
46
  \
47
  F(GetPrototype, 1, 1) \
48
  F(SetPrototype, 2, 1) \
49 50
  F(IsInPrototypeChain, 2, 1) \
  \
51 52
  F(GetOwnProperty, 2, 1) \
  \
53
  F(IsExtensible, 1, 1) \
54
  F(PreventExtensions, 1, 1)\
55
  \
56
  /* Utilities */ \
57
  F(CheckIsBootstrapping, 0, 1) \
58
  F(GetRootNaN, 0, 1) \
59
  F(Call, -1 /* >= 2 */, 1) \
60
  F(Apply, 5, 1) \
61 62
  F(GetFunctionDelegate, 1, 1) \
  F(GetConstructorDelegate, 1, 1) \
63
  F(DeoptimizeFunction, 1, 1) \
64
  F(ClearFunctionTypeFeedback, 1, 1) \
65
  F(RunningInSimulator, 0, 1) \
66
  F(IsConcurrentRecompilationSupported, 0, 1) \
67
  F(OptimizeFunctionOnNextCall, -1, 1) \
68
  F(NeverOptimizeFunction, 1, 1) \
69
  F(GetOptimizationStatus, -1, 1) \
70
  F(GetOptimizationCount, 1, 1) \
71
  F(UnblockConcurrentRecompilation, 0, 1) \
72
  F(CompileForOnStackReplacement, 1, 1) \
73
  F(SetAllocationTimeout, -1 /* 2 || 3 */, 1) \
74
  F(SetNativeFlag, 1, 1) \
75
  F(SetInlineBuiltinFlag, 1, 1) \
76
  F(StoreArrayLiteralElement, 5, 1) \
77
  F(DebugPrepareStepInIfStepping, 1, 1) \
78 79
  F(DebugPromiseHandlePrologue, 1, 1) \
  F(DebugPromiseHandleEpilogue, 0, 1) \
80
  F(FlattenString, 1, 1) \
81
  F(LoadMutableDouble, 2, 1) \
82
  F(TryMigrateInstance, 1, 1) \
83
  F(NotifyContextDisposed, 0, 1) \
84
  \
85
  /* Array join support */ \
86 87
  F(PushIfAbsent, 2, 1) \
  F(ArrayConcat, 1, 1) \
88
  \
89
  /* Conversions */ \
90 91 92 93 94 95 96 97
  F(ToBool, 1, 1) \
  F(Typeof, 1, 1) \
  \
  F(StringToNumber, 1, 1) \
  F(StringParseInt, 2, 1) \
  F(StringParseFloat, 1, 1) \
  F(StringToLowerCase, 1, 1) \
  F(StringToUpperCase, 1, 1) \
98
  F(StringSplit, 3, 1) \
99 100 101 102 103
  F(CharFromCode, 1, 1) \
  F(URIEscape, 1, 1) \
  F(URIUnescape, 1, 1) \
  \
  F(NumberToInteger, 1, 1) \
104
  F(NumberToIntegerMapMinusZero, 1, 1) \
105 106
  F(NumberToJSUint32, 1, 1) \
  F(NumberToJSInt32, 1, 1) \
107 108
  \
  /* Arithmetic operations */ \
109 110 111 112 113 114
  F(NumberAdd, 2, 1) \
  F(NumberSub, 2, 1) \
  F(NumberMul, 2, 1) \
  F(NumberDiv, 2, 1) \
  F(NumberMod, 2, 1) \
  F(NumberUnaryMinus, 1, 1) \
115
  F(NumberImul, 2, 1) \
116
  \
117
  F(StringBuilderConcat, 3, 1) \
118
  F(StringBuilderJoin, 3, 1) \
119
  F(SparseJoinWithSeparator, 3, 1) \
120 121
  \
  /* Bit operations */ \
122 123 124
  F(NumberOr, 2, 1) \
  F(NumberAnd, 2, 1) \
  F(NumberXor, 2, 1) \
125
  \
126 127 128
  F(NumberShl, 2, 1) \
  F(NumberShr, 2, 1) \
  F(NumberSar, 2, 1) \
129 130
  \
  /* Comparisons */ \
131 132
  F(NumberEquals, 2, 1) \
  F(StringEquals, 2, 1) \
133
  \
134 135
  F(NumberCompare, 3, 1) \
  F(SmiLexicographicCompare, 2, 1) \
136 137
  \
  /* Math */ \
138 139 140
  F(MathAcos, 1, 1) \
  F(MathAsin, 1, 1) \
  F(MathAtan, 1, 1) \
141
  F(MathFloorRT, 1, 1) \
142
  F(MathAtan2, 2, 1) \
143
  F(MathExpRT, 1, 1) \
144
  F(RoundNumber, 1, 1) \
145
  F(MathFround, 1, 1) \
146 147
  \
  /* Regular expressions */ \
148
  F(RegExpCompile, 3, 1) \
149
  F(RegExpExecMultiple, 4, 1) \
150
  F(RegExpInitializeObject, 5, 1) \
151
  \
152 153
  /* JSON */ \
  F(ParseJson, 1, 1) \
154 155
  F(BasicJSONStringify, 1, 1) \
  F(QuoteJSONString, 1, 1) \
156
  \
157
  /* Strings */ \
158 159 160
  F(StringIndexOf, 3, 1) \
  F(StringLastIndexOf, 3, 1) \
  F(StringLocaleCompare, 2, 1) \
161
  F(StringReplaceGlobalRegExpWithString, 4, 1) \
162
  F(StringReplaceOneCharWithString, 3, 1) \
163
  F(StringMatch, 3, 1) \
164
  F(StringTrim, 3, 1) \
165
  F(StringToArray, 2, 1) \
166
  F(NewStringWrapper, 1, 1) \
167 168
  F(NewString, 2, 1) \
  F(TruncateString, 2, 1) \
169 170
  \
  /* Numbers */ \
171 172 173
  F(NumberToRadixString, 2, 1) \
  F(NumberToFixed, 2, 1) \
  F(NumberToExponential, 2, 1) \
174 175
  F(NumberToPrecision, 2, 1) \
  F(IsValidSmi, 1, 1)
176

177

178
#define RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
179
  /* Reflection */ \
180 181 182 183 184
  F(FunctionSetInstanceClassName, 2, 1) \
  F(FunctionSetLength, 2, 1) \
  F(FunctionSetPrototype, 2, 1) \
  F(FunctionGetName, 1, 1) \
  F(FunctionSetName, 2, 1) \
185 186
  F(FunctionNameShouldPrintAsAnonymous, 1, 1) \
  F(FunctionMarkNameShouldPrintAsAnonymous, 1, 1) \
187
  F(FunctionIsGenerator, 1, 1) \
188 189
  F(FunctionBindArguments, 4, 1) \
  F(BoundFunctionGetBindings, 1, 1) \
190
  F(FunctionRemovePrototype, 1, 1) \
191 192 193 194 195
  F(FunctionGetSourceCode, 1, 1) \
  F(FunctionGetScript, 1, 1) \
  F(FunctionGetScriptSourcePosition, 1, 1) \
  F(FunctionGetPositionForOffset, 2, 1) \
  F(FunctionIsAPIFunction, 1, 1) \
196
  F(FunctionIsBuiltin, 1, 1) \
197
  F(GetScript, 1, 1) \
198
  F(CollectStackTrace, 3, 1) \
199
  F(GetAndClearOverflowedStackTrace, 1, 1) \
200
  F(GetV8Version, 0, 1) \
201 202 203
  \
  F(SetCode, 2, 1) \
  \
204
  F(CreateApiFunction, 2, 1) \
205 206 207 208
  F(IsTemplate, 1, 1) \
  F(GetTemplateField, 2, 1) \
  F(DisableAccessChecks, 1, 1) \
  F(EnableAccessChecks, 1, 1) \
209
  F(SetAccessorProperty, 6, 1) \
210 211
  \
  /* Dates */ \
212 213 214
  F(DateCurrentTime, 0, 1) \
  F(DateParseString, 2, 1) \
  F(DateLocalTimezone, 1, 1) \
215
  F(DateToUTC, 1, 1) \
216
  F(DateMakeDay, 2, 1) \
217
  F(DateSetValue, 3, 1) \
218
  F(DateCacheVersion, 0, 1) \
219 220
  \
  /* Globals */ \
221
  F(CompileString, 2, 1) \
222 223
  \
  /* Eval */ \
224
  F(GlobalReceiver, 1, 1) \
225
  F(IsAttachedGlobal, 1, 1) \
226
  \
227
  F(SetProperty, -1 /* 4 or 5 */, 1) \
228 229
  F(DefineOrRedefineDataProperty, 4, 1) \
  F(DefineOrRedefineAccessorProperty, 5, 1) \
230
  F(IgnoreAttributesAndSetProperty, -1 /* 3 or 4 */, 1) \
231
  F(GetDataProperty, 2, 1) \
232
  F(SetHiddenProperty, 3, 1) \
233 234
  \
  /* Arrays */ \
235 236 237 238
  F(RemoveArrayHoles, 2, 1) \
  F(GetArrayKeys, 2, 1) \
  F(MoveArrayContents, 2, 1) \
  F(EstimateNumberOfElements, 1, 1) \
239 240
  \
  /* Getters and Setters */ \
241
  F(LookupAccessor, 3, 1) \
242
  \
243 244 245
  /* ES5 */ \
  F(ObjectFreeze, 1, 1) \
  \
246 247 248
  /* Harmony modules */ \
  F(IsJSModule, 1, 1) \
  \
249
  /* Harmony symbols */ \
250
  F(CreateSymbol, 1, 1) \
251
  F(CreatePrivateSymbol, 1, 1) \
252
  F(CreateGlobalPrivateSymbol, 1, 1) \
253 254
  F(NewSymbolWrapper, 1, 1) \
  F(SymbolDescription, 1, 1) \
255
  F(SymbolRegistry, 0, 1) \
256
  F(SymbolIsPrivate, 1, 1) \
257
  \
258 259
  /* Harmony proxies */ \
  F(CreateJSProxy, 2, 1) \
260
  F(CreateJSFunctionProxy, 4, 1) \
261
  F(IsJSProxy, 1, 1) \
262
  F(IsJSFunctionProxy, 1, 1) \
263
  F(GetHandler, 1, 1) \
264 265
  F(GetCallTrap, 1, 1) \
  F(GetConstructTrap, 1, 1) \
266
  F(Fix, 1, 1) \
267
  \
268 269 270 271 272
  /* Harmony sets */ \
  F(SetInitialize, 1, 1) \
  F(SetAdd, 2, 1) \
  F(SetHas, 2, 1) \
  F(SetDelete, 2, 1) \
273
  F(SetClear, 1, 1) \
274
  F(SetGetSize, 1, 1) \
275
  \
276
  F(SetIteratorInitialize, 3, 1) \
277
  F(SetIteratorNext, 1, 1) \
278 279 280 281
  \
  /* Harmony maps */ \
  F(MapInitialize, 1, 1) \
  F(MapGet, 2, 1) \
282 283
  F(MapHas, 2, 1) \
  F(MapDelete, 2, 1) \
284
  F(MapClear, 1, 1) \
285
  F(MapSet, 3, 1) \
286
  F(MapGetSize, 1, 1) \
287
  \
288
  F(MapIteratorInitialize, 3, 1) \
289
  F(MapIteratorNext, 1, 1) \
290
  \
291 292 293 294 295 296
  /* 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) \
297
  \
rossberg@chromium.org's avatar
rossberg@chromium.org committed
298
  /* Harmony events */ \
299
  F(EnqueueMicrotask, 1, 1) \
300
  F(RunMicrotasks, 0, 1) \
rossberg@chromium.org's avatar
rossberg@chromium.org committed
301
  \
302 303
  /* Harmony observe */ \
  F(IsObserved, 1, 1) \
304
  F(SetIsObserved, 1, 1) \
305
  F(GetObservationState, 0, 1) \
306
  F(ObservationWeakMapCreate, 0, 1) \
307 308
  F(ObserverObjectAndRecordHaveSameOrigin, 3, 1) \
  F(ObjectWasCreatedInCurrentOrigin, 1, 1) \
309 310 311
  F(GetObjectContextObjectObserve, 1, 1) \
  F(GetObjectContextObjectGetNotifier, 1, 1) \
  F(GetObjectContextNotifierPerformChange, 1, 1) \
312
  \
313 314 315
  /* Harmony typed arrays */ \
  F(ArrayBufferInitialize, 2, 1)\
  F(ArrayBufferSliceImpl, 3, 1) \
316
  F(ArrayBufferIsView, 1, 1) \
317
  F(ArrayBufferNeuter, 1, 1) \
318
  \
319
  F(TypedArrayInitializeFromArrayLike, 4, 1) \
320
  F(TypedArrayGetBuffer, 1, 1) \
321
  F(TypedArraySetFastCases, 3, 1) \
322
  \
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
  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) \
  \
342
  /* Statements */ \
343
  F(NewObjectFromBound, 1, 1) \
344 345
  \
  /* Declarations and initialization */ \
346
  F(InitializeVarGlobal, -1 /* 2 or 3 */, 1) \
347
  F(OptimizeObjectForAddingMultipleProperties, 2, 1) \
348 349
  \
  /* Debugging */ \
350
  F(DebugPrint, 1, 1) \
351
  F(GlobalPrint, 1, 1) \
352 353 354
  F(DebugTrace, 0, 1) \
  F(TraceEnter, 0, 1) \
  F(TraceExit, 1, 1) \
355
  F(Abort, 1, 1) \
rossberg@chromium.org's avatar
rossberg@chromium.org committed
356
  F(AbortJS, 1, 1) \
357
  /* ES5 */ \
358
  F(OwnKeys, 1, 1) \
359
  \
360 361 362 363
  /* Message objects */ \
  F(MessageGetStartPosition, 1, 1) \
  F(MessageGetScript, 1, 1) \
  \
364
  /* Pseudo functions - handled as macros by parser */ \
365 366 367
  F(IS_VAR, 1, 1) \
  \
  /* expose boolean functions from objects-inl.h */ \
368 369 370
  F(HasFastSmiElements, 1, 1) \
  F(HasFastSmiOrObjectElements, 1, 1) \
  F(HasFastObjectElements, 1, 1) \
371
  F(HasFastDoubleElements, 1, 1) \
372
  F(HasFastHoleyElements, 1, 1) \
373
  F(HasDictionaryElements, 1, 1) \
374
  F(HasSloppyArgumentsElements, 1, 1) \
375
  F(HasExternalUint8ClampedElements, 1, 1) \
376
  F(HasExternalArrayElements, 1, 1) \
377 378 379 380 381 382 383 384
  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) \
385 386 387 388 389 390 391 392 393
  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) \
394
  F(HasFastProperties, 1, 1) \
395
  F(TransitionElementsKind, 2, 1) \
396
  F(HaveSameMap, 2, 1) \
397
  F(IsJSGlobalProxy, 1, 1)
398

399

400
#define RUNTIME_FUNCTION_LIST_DEBUGGER(F) \
401
  /* Debugger support*/ \
402 403 404 405 406 407 408 409 410 411 412 413 414 415
  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) \
416
  F(GetStepInPositions, 2, 1) \
417
  F(GetScopeDetails, 4, 1) \
418
  F(GetAllScopesDetails, 4, 1) \
419 420
  F(GetFunctionScopeCount, 1, 1) \
  F(GetFunctionScopeDetails, 2, 1) \
421
  F(SetScopeVariableValue, 6, 1) \
422 423 424
  F(DebugPrintScopes, 0, 1) \
  F(GetThreadCount, 1, 1) \
  F(GetThreadDetails, 2, 1) \
425
  F(SetDisableBreak, 1, 1) \
426
  F(GetBreakLocations, 2, 1) \
427
  F(SetFunctionBreakPoint, 3, 1) \
428
  F(SetScriptBreakPoint, 4, 1) \
429 430
  F(ClearBreakPoint, 1, 1) \
  F(ChangeBreakOnException, 2, 1) \
431
  F(IsBreakOnException, 1, 1) \
432
  F(PrepareStep, 4, 1) \
433
  F(ClearStepping, 0, 1) \
434
  F(DebugEvaluate, 6, 1) \
435
  F(DebugEvaluateGlobal, 4, 1) \
436 437 438 439
  F(DebugGetLoadedScripts, 0, 1) \
  F(DebugReferencedBy, 3, 1) \
  F(DebugConstructedBy, 2, 1) \
  F(DebugGetPrototype, 1, 1) \
440
  F(DebugSetScriptSource, 2, 1) \
441 442 443
  F(SystemBreak, 0, 1) \
  F(DebugDisassembleFunction, 1, 1) \
  F(DebugDisassembleConstructor, 1, 1) \
444 445 446 447 448
  F(FunctionGetInferredName, 1, 1) \
  F(LiveEditFindSharedFunctionInfosForScript, 1, 1) \
  F(LiveEditGatherCompileInfo, 2, 1) \
  F(LiveEditReplaceScript, 3, 1) \
  F(LiveEditReplaceFunctionCode, 2, 1) \
449
  F(LiveEditFunctionSourceUpdated, 1, 1) \
450 451
  F(LiveEditFunctionSetScript, 2, 1) \
  F(LiveEditReplaceRefToNestedFunction, 3, 1) \
452
  F(LiveEditPatchFunctionPositions, 2, 1) \
453
  F(LiveEditCheckAndDropActivations, 2, 1) \
454
  F(LiveEditCompareStrings, 2, 1) \
455
  F(LiveEditRestartFrame, 2, 1) \
456
  F(GetFunctionCodePositionFromSource, 2, 1) \
457 458 459 460
  F(ExecuteInDebugContext, 2, 1) \
  \
  F(SetFlags, 1, 1) \
  F(CollectGarbage, 1, 1) \
461
  F(GetHeapUsage, 0, 1) \
462

463 464 465 466 467 468 469 470 471

#ifdef V8_I18N_SUPPORT
#define RUNTIME_FUNCTION_LIST_I18N_SUPPORT(F) \
  /* i18n support */ \
  /* Standalone, helper methods. */ \
  F(CanonicalizeLanguageTag, 1, 1) \
  F(AvailableLocalesOf, 1, 1) \
  F(GetDefaultICULocale, 0, 1) \
  F(GetLanguageTagVariants, 1, 1) \
472 473 474 475
  F(IsInitializedIntlObject, 1, 1) \
  F(IsInitializedIntlObjectOfType, 2, 1) \
  F(MarkAsInitializedIntlObjectOfType, 3, 1) \
  F(GetImplFromInitializedIntlObject, 1, 1) \
476 477 478 479 480
  \
  /* Date format and parse. */ \
  F(CreateDateTimeFormat, 3, 1) \
  F(InternalDateFormat, 2, 1) \
  F(InternalDateParse, 2, 1) \
481 482 483 484 485
  \
  /* Number format and parse. */ \
  F(CreateNumberFormat, 3, 1) \
  F(InternalNumberFormat, 2, 1) \
  F(InternalNumberParse, 2, 1) \
486 487 488 489
  \
  /* Collator. */ \
  F(CreateCollator, 3, 1) \
  F(InternalCompare, 3, 1) \
490
  \
491 492 493
  /* String.prototype.normalize. */ \
  F(StringNormalize, 2, 1) \
  \
494 495 496 497 498 499 500
  /* 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) \
501 502 503 504 505 506

#else
#define RUNTIME_FUNCTION_LIST_I18N_SUPPORT(F)
#endif


507 508 509
#ifdef DEBUG
#define RUNTIME_FUNCTION_LIST_DEBUG(F) \
  /* Testing */ \
510
  F(ListNatives, 0, 1)
511 512 513 514 515 516 517 518
#else
#define RUNTIME_FUNCTION_LIST_DEBUG(F)
#endif

// ----------------------------------------------------------------------------
// 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).
519
// Entries have the form F(name, number of arguments, number of return values).
520 521

#define RUNTIME_FUNCTION_LIST(F) \
522 523
  RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
  RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
524
  RUNTIME_FUNCTION_LIST_DEBUG(F) \
525
  RUNTIME_FUNCTION_LIST_DEBUGGER(F) \
526 527 528 529 530 531
  RUNTIME_FUNCTION_LIST_I18N_SUPPORT(F)

// RUNTIME_HIDDEN_FUNCTION_LIST defines all runtime functions accessed
// by id from code generator, but not via native call by name.
// Entries have the form F(name, number of arguments, number of return values).
#define RUNTIME_HIDDEN_FUNCTION_LIST(F) \
532
  /* String and Regexp */ \
533 534 535 536 537 538 539
  F(NumberToString, 1, 1) \
  F(RegExpConstructResult, 3, 1) \
  F(RegExpExec, 4, 1) \
  F(StringAdd, 2, 1)  \
  F(SubString, 3, 1) \
  F(StringCompare, 2, 1) \
  F(StringCharCodeAt, 2, 1) \
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 565 566 567 568 569 570 571 572 573 574 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
  F(GetFromCache, 2, 1) \
  \
  /* Compilation */ \
  F(CompileUnoptimized, 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(NewArgumentsFast, 3, 1) \
  F(NewStrictArgumentsFast, 3, 1) \
  \
  /* Harmony generators */ \
  F(CreateJSGeneratorObject, 0, 1) \
  F(SuspendJSGeneratorObject, 1, 1) \
  F(ResumeJSGeneratorObject, 3, 1) \
  F(ThrowGeneratorStateError, 1, 1) \
  \
  /* 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) \
  F(NewObject, 1, 1) \
  F(NewObjectWithAllocationSite, 2, 1) \
  F(FinalizeInstanceSize, 1, 1) \
  F(Throw, 1, 1) \
  F(ReThrow, 1, 1) \
  F(ThrowReferenceError, 1, 1) \
  F(ThrowNotDateError, 0, 1) \
  F(StackGuard, 0, 1) \
  F(Interrupt, 0, 1) \
  F(PromoteScheduledException, 0, 1) \
  \
  /* Contexts */ \
  F(NewGlobalContext, 2, 1) \
  F(NewFunctionContext, 1, 1) \
  F(PushWithContext, 2, 1) \
  F(PushCatchContext, 3, 1) \
  F(PushBlockContext, 2, 1) \
  F(PushModuleContext, 2, 1) \
  F(DeleteContextSlot, 2, 1) \
  F(LoadContextSlot, 2, 2) \
  F(LoadContextSlotNoReferenceError, 2, 2) \
  F(StoreContextSlot, 4, 1) \
  \
  /* Declarations and initialization */ \
  F(DeclareGlobals, 3, 1) \
  F(DeclareModules, 1, 1) \
  F(DeclareContextSlot, 4, 1) \
  F(InitializeConstGlobal, 2, 1) \
  F(InitializeConstContextSlot, 3, 1) \
  \
  /* Eval */ \
609 610 611 612 613
  F(ResolvePossiblyDirectEval, 5, 2) \
  \
  /* Maths */ \
  F(MathPowSlow, 2, 1) \
  F(MathPow, 2, 1)
614

615
// ----------------------------------------------------------------------------
616 617 618 619 620 621 622 623
// 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).
#define INLINE_FUNCTION_LIST(F) \
  F(IsSmi, 1, 1)                                                             \
  F(IsNonNegativeSmi, 1, 1)                                                  \
  F(IsArray, 1, 1)                                                           \
  F(IsRegExp, 1, 1)                                                          \
624
  F(IsConstructCall, 0, 1)                                                   \
625 626 627 628 629
  F(CallFunction, -1 /* receiver + n args + function */, 1)                  \
  F(ArgumentsLength, 0, 1)                                                   \
  F(Arguments, 1, 1)                                                         \
  F(ValueOf, 1, 1)                                                           \
  F(SetValueOf, 2, 1)                                                        \
630
  F(DateField, 2 /* date object, field index */, 1)                          \
631 632
  F(StringCharFromCode, 1, 1)                                                \
  F(StringCharAt, 2, 1)                                                      \
633 634
  F(OneByteSeqStringSetChar, 3, 1)                                           \
  F(TwoByteSeqStringSetChar, 3, 1)                                           \
635 636 637 638 639 640 641
  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)                                                           \
642
  F(IsMinusZero, 1, 1)                                                       \
643
  F(HasCachedArrayIndex, 1, 1)                                               \
644
  F(GetCachedArrayIndex, 1, 1)                                               \
645
  F(FastAsciiArrayJoin, 2, 1)                                                \
646
  F(GeneratorNext, 2, 1)                                                     \
647
  F(GeneratorThrow, 2, 1)                                                    \
648
  F(DebugBreakInOptimizedCode, 0, 1)                                         \
649 650 651 652 653 654 655 656
  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)                                                      \
657 658 659 660 661 662 663
  F(NumberToString, 1, 1)


// ----------------------------------------------------------------------------
// 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.
664 665
// For the benefit of (fuzz) tests, the runtime version can also be called
// directly as %name (i.e. without the leading underscore).
666 667
// Entries have the form F(name, number of arguments, number of return values).
#define INLINE_OPTIMIZED_FUNCTION_LIST(F) \
668
  /* Typed Arrays */                                                         \
669 670
  F(TypedArrayInitialize, 5, 1)                                              \
  F(DataViewInitialize, 4, 1)                                                \
671
  F(MaxSmi, 0, 1)                                                            \
672
  F(TypedArrayMaxSizeInHeap, 0, 1)                                           \
673 674 675 676 677
  F(ArrayBufferViewGetByteLength, 1, 1)                                      \
  F(ArrayBufferViewGetByteOffset, 1, 1)                                      \
  F(TypedArrayGetLength, 1, 1)                                               \
  /* ArrayBuffer */                                                          \
  F(ArrayBufferGetByteLength, 1, 1)                                          \
678
  /* Maths */                                                                \
679
  F(ConstructDouble, 2, 1)                                                   \
680 681
  F(DoubleHi, 1, 1)                                                          \
  F(DoubleLo, 1, 1)                                                          \
682
  F(MathSqrtRT, 1, 1)                                                        \
683
  F(MathLogRT, 1, 1)                                                         \
684 685
  /* Debugger */                                                             \
  F(DebugCallbackSupportsStepping, 1, 1)
686 687 688


//---------------------------------------------------------------------------
689 690
// Runtime provides access to all C++ runtime functions.

691 692
class RuntimeState {
 public:
693 694
  StaticResource<ConsStringIteratorOp>* string_iterator() {
    return &string_iterator_;
695 696 697 698 699 700 701
  }
  unibrow::Mapping<unibrow::ToUppercase, 128>* to_upper_mapping() {
    return &to_upper_mapping_;
  }
  unibrow::Mapping<unibrow::ToLowercase, 128>* to_lower_mapping() {
    return &to_lower_mapping_;
  }
702 703
  ConsStringIteratorOp* string_iterator_compare_x() {
    return &string_iterator_compare_x_;
704
  }
705 706
  ConsStringIteratorOp* string_iterator_compare_y() {
    return &string_iterator_compare_y_;
707
  }
708 709
  ConsStringIteratorOp* string_locale_compare_it1() {
    return &string_locale_compare_it1_;
710
  }
711 712
  ConsStringIteratorOp* string_locale_compare_it2() {
    return &string_locale_compare_it2_;
713 714 715 716 717
  }

 private:
  RuntimeState() {}
  // Non-reentrant string buffer for efficient general use in the runtime.
718
  StaticResource<ConsStringIteratorOp> string_iterator_;
719 720
  unibrow::Mapping<unibrow::ToUppercase, 128> to_upper_mapping_;
  unibrow::Mapping<unibrow::ToLowercase, 128> to_lower_mapping_;
721 722 723 724
  ConsStringIteratorOp string_iterator_compare_x_;
  ConsStringIteratorOp string_iterator_compare_y_;
  ConsStringIteratorOp string_locale_compare_it1_;
  ConsStringIteratorOp string_locale_compare_it2_;
725 726 727 728 729 730 731 732

  friend class Isolate;
  friend class Runtime;

  DISALLOW_COPY_AND_ASSIGN(RuntimeState);
};


733 734 735
class Runtime : public AllStatic {
 public:
  enum FunctionId {
736
#define F(name, nargs, ressize) k##name,
737
    RUNTIME_FUNCTION_LIST(F)
738
    INLINE_OPTIMIZED_FUNCTION_LIST(F)
739
#undef F
740 741 742
#define F(name, nargs, ressize) kHidden##name,
    RUNTIME_HIDDEN_FUNCTION_LIST(F)
#undef F
743 744
#define F(name, nargs, ressize) kInline##name,
    INLINE_FUNCTION_LIST(F)
745 746 747
#undef F
#define F(name, nargs, ressize) kInlineOptimized##name,
    INLINE_OPTIMIZED_FUNCTION_LIST(F)
748 749 750 751 752 753 754
#undef F
    kNumFunctions,
    kFirstInlineFunction = kInlineIsSmi
  };

  enum IntrinsicType {
    RUNTIME,
755 756 757
    RUNTIME_HIDDEN,
    INLINE,
    INLINE_OPTIMIZED
758 759
  };

760
  // Intrinsic function descriptor.
761
  struct Function {
762 763
    FunctionId function_id;
    IntrinsicType intrinsic_type;
764 765 766
    // The JS name of the function.
    const char* name;

767
    // The C++ (native) entry point.  NULL if the function is inlined.
768 769
    byte* entry;

770 771
    // The number of arguments expected. nargs is -1 if the function takes
    // a variable number of arguments.
772
    int nargs;
773
    // Size of result.  Most functions return a single pointer, size 1.
774
    int result_size;
775 776
  };

777 778
  static const int kNotFound = -1;

779 780
  // Add internalized strings for all the intrinsic function names to a
  // StringDictionary.
781 782
  static void InitializeIntrinsicFunctionNames(Isolate* isolate,
                                               Handle<NameDictionary> dict);
783

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

787
  // Get the intrinsic function with the given FunctionId.
788
  static const Function* FunctionForId(FunctionId id);
789

790
  // General-purpose helper functions for runtime system.
791 792 793 794
  static int StringMatch(Isolate* isolate,
                         Handle<String> sub,
                         Handle<String> pat,
                         int index);
795

796
  static bool IsUpperCaseChar(RuntimeState* runtime_state, uint16_t ch);
797

798 799
  // TODO(1240886): Some of the following methods are *not* handle safe, but
  // accept handle arguments. This seems fragile.
800 801 802

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

808
  MUST_USE_RESULT static MaybeHandle<Object> SetObjectProperty(
809 810 811 812 813
      Isolate* isolate,
      Handle<Object> object,
      Handle<Object> key,
      Handle<Object> value,
      PropertyAttributes attr,
814
      StrictMode strict_mode);
815

816
  MUST_USE_RESULT static MaybeHandle<Object> ForceSetObjectProperty(
817 818 819
      Handle<JSObject> object,
      Handle<Object> key,
      Handle<Object> value,
820 821 822
      PropertyAttributes attr,
      JSReceiver::StoreFromKeyed store_from_keyed
        = JSReceiver::MAY_BE_STORE_FROM_KEYED);
823

824
  MUST_USE_RESULT static MaybeHandle<Object> DeleteObjectProperty(
825 826 827 828 829
      Isolate* isolate,
      Handle<JSReceiver> object,
      Handle<Object> key,
      JSReceiver::DeleteMode mode);

830
  MUST_USE_RESULT static MaybeHandle<Object> HasObjectProperty(
831
      Isolate* isolate,
832
      Handle<JSReceiver> object,
833 834
      Handle<Object> key);

835 836 837 838
  MUST_USE_RESULT static MaybeHandle<Object> GetObjectProperty(
      Isolate* isolate,
      Handle<Object> object,
      Handle<Object> key);
839

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

  static bool SetupArrayBufferAllocatingData(
      Isolate* isolate,
      Handle<JSArrayBuffer> array_buffer,
849 850
      size_t allocated_length,
      bool initialize = true);
851

852 853
  static void NeuterArrayBuffer(Handle<JSArrayBuffer> array_buffer);

854 855 856 857
  static void FreeArrayBuffer(
      Isolate* isolate,
      JSArrayBuffer* phantom_array_buffer);

858 859 860 861 862 863 864 865 866 867
  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,
868 869 870 871
    ARRAY_ID_UINT8_CLAMPED = 9,

    ARRAY_ID_FIRST = ARRAY_ID_UINT8,
    ARRAY_ID_LAST = ARRAY_ID_UINT8_CLAMPED
872 873 874
  };

  static void ArrayIdToTypeAndSize(int array_id,
875 876 877 878
      ExternalArrayType *type,
      ElementsKind* external_elements_kind,
      ElementsKind* fixed_elements_kind,
      size_t *element_size);
879

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

887 888 889 890

//---------------------------------------------------------------------------
// Constants used by interface to runtime functions.

891 892
class AllocateDoubleAlignFlag:  public BitField<bool,            0, 1> {};
class AllocateTargetSpace:      public BitField<AllocationSpace, 1, 3> {};
893

894 895 896
class DeclareGlobalsEvalFlag:   public BitField<bool,       0, 1> {};
class DeclareGlobalsNativeFlag: public BitField<bool,       1, 1> {};
class DeclareGlobalsStrictMode: public BitField<StrictMode, 2, 1> {};
897

898 899 900
} }  // namespace v8::internal

#endif  // V8_RUNTIME_H_