runtime.h 23.3 KB
Newer Older
1
// Copyright 2011 the V8 project authors. All rights reserved.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
//       copyright notice, this list of conditions and the following
//       disclaimer in the documentation and/or other materials provided
//       with the distribution.
//     * Neither the name of Google Inc. nor the names of its
//       contributors may be used to endorse or promote products derived
//       from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#ifndef V8_RUNTIME_H_
#define V8_RUNTIME_H_

31
#include "allocation.h"
32 33
#include "zone.h"

34 35
namespace v8 {
namespace internal {
36 37 38 39

// The interface to C++ runtime functions.

// ----------------------------------------------------------------------------
40 41 42
// 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.
43

44 45 46 47
// 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) \
48
  /* Property access */ \
49 50
  F(GetProperty, 2, 1) \
  F(KeyedGetProperty, 2, 1) \
51
  F(DeleteProperty, 3, 1) \
52 53 54 55 56 57
  F(HasLocalProperty, 2, 1) \
  F(HasProperty, 2, 1) \
  F(HasElement, 2, 1) \
  F(IsPropertyEnumerable, 2, 1) \
  F(GetPropertyNames, 1, 1) \
  F(GetPropertyNamesFast, 1, 1) \
58 59 60 61 62
  F(GetLocalPropertyNames, 1, 1) \
  F(GetLocalElementNames, 1, 1) \
  F(GetInterceptorInfo, 1, 1) \
  F(GetNamedInterceptorPropertyNames, 1, 1) \
  F(GetIndexedInterceptorElementNames, 1, 1) \
63 64 65
  F(GetArgumentsProperty, 1, 1) \
  F(ToFastProperties, 1, 1) \
  F(ToSlowProperties, 1, 1) \
66
  F(FinishArrayPrototypeSetup, 1, 1) \
67
  F(SpecialArrayFunctions, 1, 1) \
68
  F(GetDefaultReceiver, 1, 1) \
69
  \
70
  F(GetPrototype, 1, 1) \
71 72 73
  F(IsInPrototypeChain, 2, 1) \
  \
  F(IsConstructCall, 0, 1) \
74
  \
75 76
  F(GetOwnProperty, 2, 1) \
  \
77
  F(IsExtensible, 1, 1) \
78
  F(PreventExtensions, 1, 1)\
79
  \
80
  /* Utilities */ \
81
  F(CheckIsBootstrapping, 0, 1) \
82
  F(Call, -1 /* >= 2 */, 1) \
83
  F(Apply, 5, 1) \
84 85 86
  F(GetFunctionDelegate, 1, 1) \
  F(GetConstructorDelegate, 1, 1) \
  F(NewArgumentsFast, 3, 1) \
87
  F(NewStrictArgumentsFast, 3, 1) \
88
  F(LazyCompile, 1, 1) \
89 90 91
  F(LazyRecompile, 1, 1) \
  F(NotifyDeoptimized, 1, 1) \
  F(NotifyOSR, 0, 1) \
92
  F(DeoptimizeFunction, 1, 1) \
93
  F(RunningInSimulator, 0, 1) \
94
  F(OptimizeFunctionOnNextCall, 1, 1) \
95 96
  F(GetOptimizationStatus, 1, 1) \
  F(GetOptimizationCount, 1, 1) \
97
  F(CompileForOnStackReplacement, 1, 1) \
98
  F(SetNewFunctionAttributes, 1, 1) \
99
  F(AllocateInNewSpace, 1, 1) \
100
  F(SetNativeFlag, 1, 1) \
101
  F(StoreArrayLiteralElement, 5, 1) \
102
  \
103
  /* Array join support */ \
104 105
  F(PushIfAbsent, 2, 1) \
  F(ArrayConcat, 1, 1) \
106
  \
107
  /* Conversions */ \
108 109 110 111 112 113 114 115 116
  F(ToBool, 1, 1) \
  F(Typeof, 1, 1) \
  \
  F(StringToNumber, 1, 1) \
  F(StringFromCharCodeArray, 1, 1) \
  F(StringParseInt, 2, 1) \
  F(StringParseFloat, 1, 1) \
  F(StringToLowerCase, 1, 1) \
  F(StringToUpperCase, 1, 1) \
117
  F(StringSplit, 3, 1) \
118 119 120
  F(CharFromCode, 1, 1) \
  F(URIEscape, 1, 1) \
  F(URIUnescape, 1, 1) \
121
  F(QuoteJSONString, 1, 1) \
122
  F(QuoteJSONStringComma, 1, 1) \
123
  F(QuoteJSONStringArray, 1, 1) \
124 125
  \
  F(NumberToString, 1, 1) \
126
  F(NumberToStringSkipCache, 1, 1) \
127
  F(NumberToInteger, 1, 1) \
128
  F(NumberToIntegerMapMinusZero, 1, 1) \
129 130 131
  F(NumberToJSUint32, 1, 1) \
  F(NumberToJSInt32, 1, 1) \
  F(NumberToSmi, 1, 1) \
132
  F(AllocateHeapNumber, 0, 1) \
133 134
  \
  /* Arithmetic operations */ \
135 136 137 138 139 140
  F(NumberAdd, 2, 1) \
  F(NumberSub, 2, 1) \
  F(NumberMul, 2, 1) \
  F(NumberDiv, 2, 1) \
  F(NumberMod, 2, 1) \
  F(NumberUnaryMinus, 1, 1) \
141
  F(NumberAlloc, 0, 1) \
142
  \
143
  F(StringAdd, 2, 1) \
144
  F(StringBuilderConcat, 3, 1) \
145
  F(StringBuilderJoin, 3, 1) \
146
  F(SparseJoinWithSeparator, 3, 1) \
147 148
  \
  /* Bit operations */ \
149 150 151 152
  F(NumberOr, 2, 1) \
  F(NumberAnd, 2, 1) \
  F(NumberXor, 2, 1) \
  F(NumberNot, 1, 1) \
153
  \
154 155 156
  F(NumberShl, 2, 1) \
  F(NumberShr, 2, 1) \
  F(NumberSar, 2, 1) \
157 158
  \
  /* Comparisons */ \
159 160
  F(NumberEquals, 2, 1) \
  F(StringEquals, 2, 1) \
161
  \
162 163 164
  F(NumberCompare, 3, 1) \
  F(SmiLexicographicCompare, 2, 1) \
  F(StringCompare, 2, 1) \
165 166
  \
  /* Math */ \
167 168 169 170 171 172 173 174 175 176
  F(Math_acos, 1, 1) \
  F(Math_asin, 1, 1) \
  F(Math_atan, 1, 1) \
  F(Math_atan2, 2, 1) \
  F(Math_ceil, 1, 1) \
  F(Math_cos, 1, 1) \
  F(Math_exp, 1, 1) \
  F(Math_floor, 1, 1) \
  F(Math_log, 1, 1) \
  F(Math_pow, 2, 1) \
177
  F(Math_pow_cfunction, 2, 1) \
178
  F(RoundNumber, 1, 1) \
179 180 181
  F(Math_sin, 1, 1) \
  F(Math_sqrt, 1, 1) \
  F(Math_tan, 1, 1) \
182 183
  \
  /* Regular expressions */ \
184 185
  F(RegExpCompile, 3, 1) \
  F(RegExpExec, 4, 1) \
186
  F(RegExpExecMultiple, 4, 1) \
187
  F(RegExpInitializeObject, 5, 1) \
188
  F(RegExpConstructResult, 3, 1) \
189
  \
190 191 192
  /* JSON */ \
  F(ParseJson, 1, 1) \
  \
193
  /* Strings */ \
194 195 196 197
  F(StringCharCodeAt, 2, 1) \
  F(StringIndexOf, 3, 1) \
  F(StringLastIndexOf, 3, 1) \
  F(StringLocaleCompare, 2, 1) \
198
  F(SubString, 3, 1) \
199
  F(StringReplaceRegExpWithString, 4, 1) \
200
  F(StringReplaceOneCharWithString, 3, 1) \
201
  F(StringMatch, 3, 1) \
202
  F(StringTrim, 3, 1) \
203
  F(StringToArray, 2, 1) \
204
  F(NewStringWrapper, 1, 1) \
205 206
  \
  /* Numbers */ \
207 208 209 210
  F(NumberToRadixString, 2, 1) \
  F(NumberToFixed, 2, 1) \
  F(NumberToExponential, 2, 1) \
  F(NumberToPrecision, 2, 1)
211 212

#define RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
213
  /* Reflection */ \
214 215 216
  F(FunctionSetInstanceClassName, 2, 1) \
  F(FunctionSetLength, 2, 1) \
  F(FunctionSetPrototype, 2, 1) \
217
  F(FunctionSetReadOnlyPrototype, 1, 1) \
218 219
  F(FunctionGetName, 1, 1) \
  F(FunctionSetName, 2, 1) \
220 221
  F(FunctionNameShouldPrintAsAnonymous, 1, 1) \
  F(FunctionMarkNameShouldPrintAsAnonymous, 1, 1) \
222 223
  F(FunctionBindArguments, 4, 1) \
  F(BoundFunctionGetBindings, 1, 1) \
224
  F(FunctionRemovePrototype, 1, 1) \
225 226 227 228 229
  F(FunctionGetSourceCode, 1, 1) \
  F(FunctionGetScript, 1, 1) \
  F(FunctionGetScriptSourcePosition, 1, 1) \
  F(FunctionGetPositionForOffset, 2, 1) \
  F(FunctionIsAPIFunction, 1, 1) \
230
  F(FunctionIsBuiltin, 1, 1) \
231 232
  F(GetScript, 1, 1) \
  F(CollectStackTrace, 2, 1) \
233
  F(GetV8Version, 0, 1) \
234 235 236
  \
  F(ClassOf, 1, 1) \
  F(SetCode, 2, 1) \
237
  F(SetExpectedNumberOfProperties, 2, 1) \
238 239 240 241 242 243
  \
  F(CreateApiFunction, 1, 1) \
  F(IsTemplate, 1, 1) \
  F(GetTemplateField, 2, 1) \
  F(DisableAccessChecks, 1, 1) \
  F(EnableAccessChecks, 1, 1) \
244 245
  \
  /* Dates */ \
246 247 248 249 250
  F(DateCurrentTime, 0, 1) \
  F(DateParseString, 2, 1) \
  F(DateLocalTimezone, 1, 1) \
  F(DateLocalTimeOffset, 0, 1) \
  F(DateDaylightSavingsOffset, 1, 1) \
251
  F(DateMakeDay, 2, 1) \
252
  F(DateYMDFromTime, 2, 1) \
253 254 255 256
  \
  /* Numbers */ \
  \
  /* Globals */ \
257
  F(CompileString, 1, 1) \
258
  F(GlobalPrint, 1, 1) \
259 260
  \
  /* Eval */ \
261
  F(GlobalReceiver, 1, 1) \
262
  F(ResolvePossiblyDirectEval, 5, 2) \
263
  \
264
  F(SetProperty, -1 /* 4 or 5 */, 1) \
265 266
  F(DefineOrRedefineDataProperty, 4, 1) \
  F(DefineOrRedefineAccessorProperty, 5, 1) \
267
  F(IgnoreAttributesAndSetProperty, -1 /* 3 or 4 */, 1) \
268 269
  \
  /* Arrays */ \
270 271 272 273
  F(RemoveArrayHoles, 2, 1) \
  F(GetArrayKeys, 2, 1) \
  F(MoveArrayContents, 2, 1) \
  F(EstimateNumberOfElements, 1, 1) \
274
  F(SwapElements, 3, 1) \
275 276
  \
  /* Getters and Setters */ \
277 278
  F(DefineAccessor, -1 /* 4 or 5 */, 1) \
  F(LookupAccessor, 3, 1) \
279 280
  \
  /* Literals */ \
281
  F(MaterializeRegExpLiteral, 4, 1)\
282 283
  F(CreateObjectLiteral, 4, 1) \
  F(CreateObjectLiteralShallow, 4, 1) \
284 285
  F(CreateArrayLiteral, 3, 1) \
  F(CreateArrayLiteralShallow, 3, 1) \
286
  \
287 288
  /* Harmony proxies */ \
  F(CreateJSProxy, 2, 1) \
289
  F(CreateJSFunctionProxy, 4, 1) \
290
  F(IsJSProxy, 1, 1) \
291
  F(IsJSFunctionProxy, 1, 1) \
292
  F(GetHandler, 1, 1) \
293 294
  F(GetCallTrap, 1, 1) \
  F(GetConstructTrap, 1, 1) \
295
  F(Fix, 1, 1) \
296
  \
297 298 299 300 301 302 303 304 305 306 307
  /* Harmony sets */ \
  F(SetInitialize, 1, 1) \
  F(SetAdd, 2, 1) \
  F(SetHas, 2, 1) \
  F(SetDelete, 2, 1) \
  \
  /* Harmony maps */ \
  F(MapInitialize, 1, 1) \
  F(MapGet, 2, 1) \
  F(MapSet, 3, 1) \
  \
308 309 310 311 312
  /* Harmony weakmaps */ \
  F(WeakMapInitialize, 1, 1) \
  F(WeakMapGet, 2, 1) \
  F(WeakMapSet, 3, 1) \
  \
313
  /* Statements */ \
314
  F(NewClosure, 3, 1) \
315
  F(NewObject, 1, 1) \
316
  F(NewObjectFromBound, 1, 1) \
317
  F(FinalizeInstanceSize, 1, 1) \
318 319 320
  F(Throw, 1, 1) \
  F(ReThrow, 1, 1) \
  F(ThrowReferenceError, 1, 1) \
321
  F(StackGuard, 0, 1) \
322
  F(PromoteScheduledException, 0, 1) \
323 324
  \
  /* Contexts */ \
325
  F(NewFunctionContext, 1, 1) \
326 327
  F(PushWithContext, 2, 1) \
  F(PushCatchContext, 3, 1) \
328
  F(PushBlockContext, 2, 1) \
329
  F(DeleteContextSlot, 2, 1) \
330 331
  F(LoadContextSlot, 2, 2) \
  F(LoadContextSlotNoReferenceError, 2, 2) \
332
  F(StoreContextSlot, 4, 1) \
333 334
  \
  /* Declarations and initialization */ \
335
  F(DeclareGlobals, 3, 1) \
336
  F(DeclareContextSlot, 4, 1) \
337
  F(InitializeVarGlobal, -1 /* 2 or 3 */, 1) \
338 339 340
  F(InitializeConstGlobal, 2, 1) \
  F(InitializeConstContextSlot, 3, 1) \
  F(OptimizeObjectForAddingMultipleProperties, 2, 1) \
341 342
  \
  /* Debugging */ \
343 344 345 346 347
  F(DebugPrint, 1, 1) \
  F(DebugTrace, 0, 1) \
  F(TraceEnter, 0, 1) \
  F(TraceExit, 1, 1) \
  F(Abort, 2, 1) \
348
  /* Logging */ \
349
  F(Log, 2, 1) \
350 351
  /* ES5 */ \
  F(LocalKeys, 1, 1) \
352 353
  /* Cache suport */ \
  F(GetFromCache, 2, 1) \
354
  \
355 356 357 358 359 360 361
  /* Message objects */ \
  F(NewMessageObject, 2, 1) \
  F(MessageGetType, 1, 1) \
  F(MessageGetArguments, 1, 1) \
  F(MessageGetStartPosition, 1, 1) \
  F(MessageGetScript, 1, 1) \
  \
362
  /* Pseudo functions - handled as macros by parser */ \
363 364 365
  F(IS_VAR, 1, 1) \
  \
  /* expose boolean functions from objects-inl.h */ \
366
  F(HasFastSmiOnlyElements, 1, 1) \
367 368 369 370 371 372 373 374 375 376 377 378
  F(HasFastElements, 1, 1) \
  F(HasFastDoubleElements, 1, 1) \
  F(HasDictionaryElements, 1, 1) \
  F(HasExternalPixelElements, 1, 1) \
  F(HasExternalArrayElements, 1, 1) \
  F(HasExternalByteElements, 1, 1) \
  F(HasExternalUnsignedByteElements, 1, 1) \
  F(HasExternalShortElements, 1, 1) \
  F(HasExternalUnsignedShortElements, 1, 1) \
  F(HasExternalIntElements, 1, 1) \
  F(HasExternalUnsignedIntElements, 1, 1) \
  F(HasExternalFloatElements, 1, 1) \
379
  F(HasExternalDoubleElements, 1, 1) \
380 381
  F(TransitionElementsSmiToDouble, 1, 1) \
  F(TransitionElementsDoubleToObject, 1, 1) \
382
  F(HaveSameMap, 2, 1) \
383 384 385
  /* profiler */ \
  F(ProfilerResume, 0, 1) \
  F(ProfilerPause, 0, 1)
386

387

388 389 390
#ifdef ENABLE_DEBUGGER_SUPPORT
#define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \
  /* Debugger support*/ \
391 392 393 394 395 396 397 398 399 400 401 402 403 404
  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) \
405
  F(GetScopeDetails, 4, 1) \
406 407 408
  F(DebugPrintScopes, 0, 1) \
  F(GetThreadCount, 1, 1) \
  F(GetThreadDetails, 2, 1) \
409
  F(SetDisableBreak, 1, 1) \
410 411 412 413 414
  F(GetBreakLocations, 1, 1) \
  F(SetFunctionBreakPoint, 3, 1) \
  F(SetScriptBreakPoint, 3, 1) \
  F(ClearBreakPoint, 1, 1) \
  F(ChangeBreakOnException, 2, 1) \
415
  F(IsBreakOnException, 1, 1) \
416 417
  F(PrepareStep, 3, 1) \
  F(ClearStepping, 0, 1) \
418
  F(DebugEvaluate, 6, 1) \
419
  F(DebugEvaluateGlobal, 4, 1) \
420 421 422 423 424 425 426
  F(DebugGetLoadedScripts, 0, 1) \
  F(DebugReferencedBy, 3, 1) \
  F(DebugConstructedBy, 2, 1) \
  F(DebugGetPrototype, 1, 1) \
  F(SystemBreak, 0, 1) \
  F(DebugDisassembleFunction, 1, 1) \
  F(DebugDisassembleConstructor, 1, 1) \
427 428 429 430 431
  F(FunctionGetInferredName, 1, 1) \
  F(LiveEditFindSharedFunctionInfosForScript, 1, 1) \
  F(LiveEditGatherCompileInfo, 2, 1) \
  F(LiveEditReplaceScript, 3, 1) \
  F(LiveEditReplaceFunctionCode, 2, 1) \
432
  F(LiveEditFunctionSourceUpdated, 1, 1) \
433 434
  F(LiveEditFunctionSetScript, 2, 1) \
  F(LiveEditReplaceRefToNestedFunction, 3, 1) \
435
  F(LiveEditPatchFunctionPositions, 2, 1) \
436
  F(LiveEditCheckAndDropActivations, 2, 1) \
437
  F(LiveEditCompareStrings, 2, 1) \
438
  F(GetFunctionCodePositionFromSource, 2, 1) \
439 440 441 442
  F(ExecuteInDebugContext, 2, 1) \
  \
  F(SetFlags, 1, 1) \
  F(CollectGarbage, 1, 1) \
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
  F(GetHeapUsage, 0, 1) \
  \
  /* LiveObjectList support*/ \
  F(HasLOLEnabled, 0, 1) \
  F(CaptureLOL, 0, 1) \
  F(DeleteLOL, 1, 1) \
  F(DumpLOL, 5, 1) \
  F(GetLOLObj, 1, 1) \
  F(GetLOLObjId, 1, 1) \
  F(GetLOLObjRetainers, 6, 1) \
  F(GetLOLPath, 3, 1) \
  F(InfoLOL, 2, 1) \
  F(PrintLOLObj, 1, 1) \
  F(ResetLOL, 0, 1) \
  F(SummarizeLOL, 3, 1)
458

459 460 461
#else
#define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F)
#endif
462

463 464 465
#ifdef DEBUG
#define RUNTIME_FUNCTION_LIST_DEBUG(F) \
  /* Testing */ \
466
  F(ListNatives, 0, 1)
467 468 469 470 471 472 473 474 475 476
#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).

#define RUNTIME_FUNCTION_LIST(F) \
477 478
  RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
  RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
479
  RUNTIME_FUNCTION_LIST_DEBUG(F) \
480
  RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F)
481

482
// ----------------------------------------------------------------------------
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
// 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)                                                          \
  F(CallFunction, -1 /* receiver + n args + function */, 1)                  \
  F(ArgumentsLength, 0, 1)                                                   \
  F(Arguments, 1, 1)                                                         \
  F(ValueOf, 1, 1)                                                           \
  F(SetValueOf, 2, 1)                                                        \
  F(StringCharFromCode, 1, 1)                                                \
  F(StringCharAt, 2, 1)                                                      \
  F(ObjectEquals, 2, 1)                                                      \
  F(RandomHeapNumber, 0, 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(MathSin, 1, 1)                                                           \
  F(MathCos, 1, 1)                                                           \
508
  F(MathTan, 1, 1)                                                           \
509
  F(MathSqrt, 1, 1)                                                          \
510
  F(MathLog, 1, 1)                                                           \
511 512
  F(IsRegExpEquivalent, 2, 1)                                                \
  F(HasCachedArrayIndex, 1, 1)                                               \
513
  F(GetCachedArrayIndex, 1, 1)                                               \
514
  F(FastAsciiArrayJoin, 2, 1)
515 516 517 518 519


// ----------------------------------------------------------------------------
// INLINE_AND_RUNTIME_FUNCTION_LIST defines all inlined functions accessed
// with a native call of the form %_name from within JS code that also have
520
// a corresponding runtime function, that is called for slow cases.
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537
// Entries have the form F(name, number of arguments, number of return values).
#define INLINE_RUNTIME_FUNCTION_LIST(F) \
  F(IsConstructCall, 0, 1)                                                   \
  F(ClassOf, 1, 1)                                                           \
  F(StringCharCodeAt, 2, 1)                                                  \
  F(Log, 3, 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)                                                    \
  F(SwapElements, 3, 1)


//---------------------------------------------------------------------------
538 539
// Runtime provides access to all C++ runtime functions.

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
class RuntimeState {
 public:
  StaticResource<StringInputBuffer>* string_input_buffer() {
    return &string_input_buffer_;
  }
  unibrow::Mapping<unibrow::ToUppercase, 128>* to_upper_mapping() {
    return &to_upper_mapping_;
  }
  unibrow::Mapping<unibrow::ToLowercase, 128>* to_lower_mapping() {
    return &to_lower_mapping_;
  }
  StringInputBuffer* string_input_buffer_compare_bufx() {
    return &string_input_buffer_compare_bufx_;
  }
  StringInputBuffer* string_input_buffer_compare_bufy() {
    return &string_input_buffer_compare_bufy_;
  }
  StringInputBuffer* string_locale_compare_buf1() {
    return &string_locale_compare_buf1_;
  }
  StringInputBuffer* string_locale_compare_buf2() {
    return &string_locale_compare_buf2_;
  }

 private:
  RuntimeState() {}
  // Non-reentrant string buffer for efficient general use in the runtime.
  StaticResource<StringInputBuffer> string_input_buffer_;
  unibrow::Mapping<unibrow::ToUppercase, 128> to_upper_mapping_;
  unibrow::Mapping<unibrow::ToLowercase, 128> to_lower_mapping_;
  StringInputBuffer string_input_buffer_compare_bufx_;
  StringInputBuffer string_input_buffer_compare_bufy_;
  StringInputBuffer string_locale_compare_buf1_;
  StringInputBuffer string_locale_compare_buf2_;

  friend class Isolate;
  friend class Runtime;

  DISALLOW_COPY_AND_ASSIGN(RuntimeState);
};


582 583 584
class Runtime : public AllStatic {
 public:
  enum FunctionId {
585
#define F(name, nargs, ressize) k##name,
586 587
    RUNTIME_FUNCTION_LIST(F)
#undef F
588 589 590 591 592 593 594 595 596 597 598
#define F(name, nargs, ressize) kInline##name,
    INLINE_FUNCTION_LIST(F)
    INLINE_RUNTIME_FUNCTION_LIST(F)
#undef F
    kNumFunctions,
    kFirstInlineFunction = kInlineIsSmi
  };

  enum IntrinsicType {
    RUNTIME,
    INLINE
599 600
  };

601
  // Intrinsic function descriptor.
602
  struct Function {
603 604
    FunctionId function_id;
    IntrinsicType intrinsic_type;
605 606 607
    // The JS name of the function.
    const char* name;

608
    // The C++ (native) entry point.  NULL if the function is inlined.
609 610
    byte* entry;

611 612
    // The number of arguments expected. nargs is -1 if the function takes
    // a variable number of arguments.
613
    int nargs;
614
    // Size of result.  Most functions return a single pointer, size 1.
615
    int result_size;
616 617
  };

618 619 620 621 622 623
  static const int kNotFound = -1;

  // Add symbols for all the intrinsic function names to a StringDictionary.
  // Returns failure if an allocation fails.  In this case, it must be
  // retried with a new, empty StringDictionary, not with the same one.
  // Alternatively, heap initialization can be completely restarted.
624
  MUST_USE_RESULT static MaybeObject* InitializeIntrinsicFunctionNames(
625
      Heap* heap, Object* dictionary);
626 627

  // Get the intrinsic function with the given name, which must be a symbol.
628
  static const Function* FunctionForSymbol(Handle<String> name);
629

630
  // Get the intrinsic function with the given FunctionId.
631
  static const Function* FunctionForId(FunctionId id);
632

633 634 635 636 637 638
  static Handle<String> StringReplaceOneCharWithString(Isolate* isolate,
                                                       Handle<String> subject,
                                                       Handle<String> search,
                                                       Handle<String> replace,
                                                       bool* found);

639
  // General-purpose helper functions for runtime system.
640 641 642 643
  static int StringMatch(Isolate* isolate,
                         Handle<String> sub,
                         Handle<String> pat,
                         int index);
644

645
  static bool IsUpperCaseChar(RuntimeState* runtime_state, uint16_t ch);
646

647 648
  // TODO(1240886): Some of the following methods are *not* handle safe, but
  // accept handle arguments. This seems fragile.
649 650 651

  // Support getting the characters in a string using [] notation as
  // in Firefox/SpiderMonkey, Safari and Opera.
652 653
  MUST_USE_RESULT static MaybeObject* GetElementOrCharAt(Isolate* isolate,
                                                         Handle<Object> object,
654 655 656
                                                         uint32_t index);

  MUST_USE_RESULT static MaybeObject* SetObjectProperty(
657
      Isolate* isolate,
658 659 660
      Handle<Object> object,
      Handle<Object> key,
      Handle<Object> value,
661
      PropertyAttributes attr,
662
      StrictModeFlag strict_mode);
663 664

  MUST_USE_RESULT static MaybeObject* ForceSetObjectProperty(
665
      Isolate* isolate,
666 667 668 669 670 671
      Handle<JSObject> object,
      Handle<Object> key,
      Handle<Object> value,
      PropertyAttributes attr);

  MUST_USE_RESULT static MaybeObject* ForceDeleteObjectProperty(
672
      Isolate* isolate,
673
      Handle<JSReceiver> object,
674 675
      Handle<Object> key);

676 677 678 679
  MUST_USE_RESULT static MaybeObject* GetObjectProperty(
      Isolate* isolate,
      Handle<Object> object,
      Handle<Object> key);
680

681
  // This function is used in FunctionNameUsing* tests.
682 683
  static Object* FindSharedFunctionInfoInScript(Isolate* isolate,
                                                Handle<Script> script,
684 685
                                                int position);

686 687
  // Helper functions used stubs.
  static void PerformGC(Object* result);
688 689 690 691 692 693

  // Used in runtime.cc and hydrogen's VisitArrayLiteral.
  static Handle<Object> CreateArrayLiteralBoilerplate(
      Isolate* isolate,
      Handle<FixedArray> literals,
      Handle<FixedArray> elements);
694 695
};

696 697 698 699

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

700 701 702
class DeclareGlobalsEvalFlag:     public BitField<bool,         0, 1> {};
class DeclareGlobalsNativeFlag:   public BitField<bool,         1, 1> {};
class DeclareGlobalsLanguageMode: public BitField<LanguageMode, 2, 2> {};
703

704 705 706
} }  // namespace v8::internal

#endif  // V8_RUNTIME_H_