runtime.h revision 589d6979ff2ef66fca2d8fa51404c369ca5e9250
1// Copyright 2011 the V8 project authors. All rights reserved. 2// Redistribution and use in source and binary forms, with or without 3// modification, are permitted provided that the following conditions are 4// met: 5// 6// * Redistributions of source code must retain the above copyright 7// notice, this list of conditions and the following disclaimer. 8// * Redistributions in binary form must reproduce the above 9// copyright notice, this list of conditions and the following 10// disclaimer in the documentation and/or other materials provided 11// with the distribution. 12// * Neither the name of Google Inc. nor the names of its 13// contributors may be used to endorse or promote products derived 14// from this software without specific prior written permission. 15// 16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 28#ifndef V8_RUNTIME_H_ 29#define V8_RUNTIME_H_ 30 31#include "allocation.h" 32#include "zone.h" 33 34namespace v8 { 35namespace internal { 36 37// The interface to C++ runtime functions. 38 39// ---------------------------------------------------------------------------- 40// RUNTIME_FUNCTION_LIST_ALWAYS defines runtime calls available in both 41// release and debug mode. 42// This macro should only be used by the macro RUNTIME_FUNCTION_LIST. 43 44// WARNING: RUNTIME_FUNCTION_LIST_ALWAYS_* is a very large macro that caused 45// MSVC Intellisense to crash. It was broken into two macros to work around 46// this problem. Please avoid large recursive macros whenever possible. 47#define RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \ 48 /* Property access */ \ 49 F(GetProperty, 2, 1) \ 50 F(KeyedGetProperty, 2, 1) \ 51 F(DeleteProperty, 3, 1) \ 52 F(HasLocalProperty, 2, 1) \ 53 F(HasProperty, 2, 1) \ 54 F(HasElement, 2, 1) \ 55 F(IsPropertyEnumerable, 2, 1) \ 56 F(GetPropertyNames, 1, 1) \ 57 F(GetPropertyNamesFast, 1, 1) \ 58 F(GetLocalPropertyNames, 1, 1) \ 59 F(GetLocalElementNames, 1, 1) \ 60 F(GetInterceptorInfo, 1, 1) \ 61 F(GetNamedInterceptorPropertyNames, 1, 1) \ 62 F(GetIndexedInterceptorElementNames, 1, 1) \ 63 F(GetArgumentsProperty, 1, 1) \ 64 F(ToFastProperties, 1, 1) \ 65 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 F(IsInPrototypeChain, 2, 1) \ 72 F(SetHiddenPrototype, 2, 1) \ 73 \ 74 F(IsConstructCall, 0, 1) \ 75 \ 76 F(GetOwnProperty, 2, 1) \ 77 \ 78 F(IsExtensible, 1, 1) \ 79 F(PreventExtensions, 1, 1)\ 80 \ 81 /* Utilities */ \ 82 F(CheckIsBootstrapping, 0, 1) \ 83 F(Apply, 5, 1) \ 84 F(GetFunctionDelegate, 1, 1) \ 85 F(GetConstructorDelegate, 1, 1) \ 86 F(NewArgumentsFast, 3, 1) \ 87 F(NewStrictArgumentsFast, 3, 1) \ 88 F(LazyCompile, 1, 1) \ 89 F(LazyRecompile, 1, 1) \ 90 F(NotifyDeoptimized, 1, 1) \ 91 F(NotifyOSR, 0, 1) \ 92 F(DeoptimizeFunction, 1, 1) \ 93 F(RunningInSimulator, 0, 1) \ 94 F(OptimizeFunctionOnNextCall, 1, 1) \ 95 F(GetOptimizationStatus, 1, 1) \ 96 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 \ 102 /* Array join support */ \ 103 F(PushIfAbsent, 2, 1) \ 104 F(ArrayConcat, 1, 1) \ 105 \ 106 /* Conversions */ \ 107 F(ToBool, 1, 1) \ 108 F(Typeof, 1, 1) \ 109 \ 110 F(StringToNumber, 1, 1) \ 111 F(StringFromCharCodeArray, 1, 1) \ 112 F(StringParseInt, 2, 1) \ 113 F(StringParseFloat, 1, 1) \ 114 F(StringToLowerCase, 1, 1) \ 115 F(StringToUpperCase, 1, 1) \ 116 F(StringSplit, 3, 1) \ 117 F(CharFromCode, 1, 1) \ 118 F(URIEscape, 1, 1) \ 119 F(URIUnescape, 1, 1) \ 120 F(QuoteJSONString, 1, 1) \ 121 F(QuoteJSONStringComma, 1, 1) \ 122 F(QuoteJSONStringArray, 1, 1) \ 123 \ 124 F(NumberToString, 1, 1) \ 125 F(NumberToStringSkipCache, 1, 1) \ 126 F(NumberToInteger, 1, 1) \ 127 F(NumberToIntegerMapMinusZero, 1, 1) \ 128 F(NumberToJSUint32, 1, 1) \ 129 F(NumberToJSInt32, 1, 1) \ 130 F(NumberToSmi, 1, 1) \ 131 F(AllocateHeapNumber, 0, 1) \ 132 \ 133 /* Arithmetic operations */ \ 134 F(NumberAdd, 2, 1) \ 135 F(NumberSub, 2, 1) \ 136 F(NumberMul, 2, 1) \ 137 F(NumberDiv, 2, 1) \ 138 F(NumberMod, 2, 1) \ 139 F(NumberUnaryMinus, 1, 1) \ 140 F(NumberAlloc, 0, 1) \ 141 \ 142 F(StringAdd, 2, 1) \ 143 F(StringBuilderConcat, 3, 1) \ 144 F(StringBuilderJoin, 3, 1) \ 145 F(SparseJoinWithSeparator, 3, 1) \ 146 \ 147 /* Bit operations */ \ 148 F(NumberOr, 2, 1) \ 149 F(NumberAnd, 2, 1) \ 150 F(NumberXor, 2, 1) \ 151 F(NumberNot, 1, 1) \ 152 \ 153 F(NumberShl, 2, 1) \ 154 F(NumberShr, 2, 1) \ 155 F(NumberSar, 2, 1) \ 156 \ 157 /* Comparisons */ \ 158 F(NumberEquals, 2, 1) \ 159 F(StringEquals, 2, 1) \ 160 \ 161 F(NumberCompare, 3, 1) \ 162 F(SmiLexicographicCompare, 2, 1) \ 163 F(StringCompare, 2, 1) \ 164 \ 165 /* Math */ \ 166 F(Math_acos, 1, 1) \ 167 F(Math_asin, 1, 1) \ 168 F(Math_atan, 1, 1) \ 169 F(Math_atan2, 2, 1) \ 170 F(Math_ceil, 1, 1) \ 171 F(Math_cos, 1, 1) \ 172 F(Math_exp, 1, 1) \ 173 F(Math_floor, 1, 1) \ 174 F(Math_log, 1, 1) \ 175 F(Math_pow, 2, 1) \ 176 F(Math_pow_cfunction, 2, 1) \ 177 F(RoundNumber, 1, 1) \ 178 F(Math_sin, 1, 1) \ 179 F(Math_sqrt, 1, 1) \ 180 F(Math_tan, 1, 1) \ 181 \ 182 /* Regular expressions */ \ 183 F(RegExpCompile, 3, 1) \ 184 F(RegExpExec, 4, 1) \ 185 F(RegExpExecMultiple, 4, 1) \ 186 F(RegExpInitializeObject, 5, 1) \ 187 F(RegExpConstructResult, 3, 1) \ 188 \ 189 /* JSON */ \ 190 F(ParseJson, 1, 1) \ 191 \ 192 /* Strings */ \ 193 F(StringCharCodeAt, 2, 1) \ 194 F(StringIndexOf, 3, 1) \ 195 F(StringLastIndexOf, 3, 1) \ 196 F(StringLocaleCompare, 2, 1) \ 197 F(SubString, 3, 1) \ 198 F(StringReplaceRegExpWithString, 4, 1) \ 199 F(StringMatch, 3, 1) \ 200 F(StringTrim, 3, 1) \ 201 F(StringToArray, 2, 1) \ 202 F(NewStringWrapper, 1, 1) \ 203 \ 204 /* Numbers */ \ 205 F(NumberToRadixString, 2, 1) \ 206 F(NumberToFixed, 2, 1) \ 207 F(NumberToExponential, 2, 1) \ 208 F(NumberToPrecision, 2, 1) 209 210#define RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \ 211 /* Reflection */ \ 212 F(FunctionSetInstanceClassName, 2, 1) \ 213 F(FunctionSetLength, 2, 1) \ 214 F(BoundFunctionSetLength, 2, 1) \ 215 F(FunctionSetPrototype, 2, 1) \ 216 F(FunctionSetReadOnlyPrototype, 1, 1) \ 217 F(FunctionGetName, 1, 1) \ 218 F(FunctionSetName, 2, 1) \ 219 F(FunctionNameShouldPrintAsAnonymous, 1, 1) \ 220 F(FunctionMarkNameShouldPrintAsAnonymous, 1, 1) \ 221 F(FunctionSetBound, 1, 1) \ 222 F(FunctionRemovePrototype, 1, 1) \ 223 F(FunctionGetSourceCode, 1, 1) \ 224 F(FunctionGetScript, 1, 1) \ 225 F(FunctionGetScriptSourcePosition, 1, 1) \ 226 F(FunctionGetPositionForOffset, 2, 1) \ 227 F(FunctionIsAPIFunction, 1, 1) \ 228 F(FunctionIsBuiltin, 1, 1) \ 229 F(GetScript, 1, 1) \ 230 F(CollectStackTrace, 2, 1) \ 231 F(GetV8Version, 0, 1) \ 232 \ 233 F(ClassOf, 1, 1) \ 234 F(SetCode, 2, 1) \ 235 F(SetExpectedNumberOfProperties, 2, 1) \ 236 \ 237 F(CreateApiFunction, 1, 1) \ 238 F(IsTemplate, 1, 1) \ 239 F(GetTemplateField, 2, 1) \ 240 F(DisableAccessChecks, 1, 1) \ 241 F(EnableAccessChecks, 1, 1) \ 242 \ 243 /* Dates */ \ 244 F(DateCurrentTime, 0, 1) \ 245 F(DateParseString, 2, 1) \ 246 F(DateLocalTimezone, 1, 1) \ 247 F(DateLocalTimeOffset, 0, 1) \ 248 F(DateDaylightSavingsOffset, 1, 1) \ 249 F(DateMakeDay, 3, 1) \ 250 F(DateYMDFromTime, 2, 1) \ 251 \ 252 /* Numbers */ \ 253 \ 254 /* Globals */ \ 255 F(CompileString, 1, 1) \ 256 F(GlobalPrint, 1, 1) \ 257 \ 258 /* Eval */ \ 259 F(GlobalReceiver, 1, 1) \ 260 F(ResolvePossiblyDirectEval, 4, 2) \ 261 F(ResolvePossiblyDirectEvalNoLookup, 4, 2) \ 262 \ 263 F(SetProperty, -1 /* 4 or 5 */, 1) \ 264 F(DefineOrRedefineDataProperty, 4, 1) \ 265 F(DefineOrRedefineAccessorProperty, 5, 1) \ 266 F(IgnoreAttributesAndSetProperty, -1 /* 3 or 4 */, 1) \ 267 \ 268 /* Arrays */ \ 269 F(RemoveArrayHoles, 2, 1) \ 270 F(GetArrayKeys, 2, 1) \ 271 F(MoveArrayContents, 2, 1) \ 272 F(EstimateNumberOfElements, 1, 1) \ 273 F(SwapElements, 3, 1) \ 274 \ 275 /* Getters and Setters */ \ 276 F(DefineAccessor, -1 /* 4 or 5 */, 1) \ 277 F(LookupAccessor, 3, 1) \ 278 \ 279 /* Literals */ \ 280 F(MaterializeRegExpLiteral, 4, 1)\ 281 F(CreateArrayLiteralBoilerplate, 3, 1) \ 282 F(CloneLiteralBoilerplate, 1, 1) \ 283 F(CloneShallowLiteralBoilerplate, 1, 1) \ 284 F(CreateObjectLiteral, 4, 1) \ 285 F(CreateObjectLiteralShallow, 4, 1) \ 286 F(CreateArrayLiteral, 3, 1) \ 287 F(CreateArrayLiteralShallow, 3, 1) \ 288 \ 289 /* Harmony proxies */ \ 290 F(CreateJSProxy, 2, 1) \ 291 F(CreateJSFunctionProxy, 4, 1) \ 292 F(IsJSProxy, 1, 1) \ 293 F(IsJSFunctionProxy, 1, 1) \ 294 F(GetHandler, 1, 1) \ 295 F(GetCallTrap, 1, 1) \ 296 F(GetConstructTrap, 1, 1) \ 297 F(Fix, 1, 1) \ 298 \ 299 /* Harmony weakmaps */ \ 300 F(WeakMapInitialize, 1, 1) \ 301 F(WeakMapGet, 2, 1) \ 302 F(WeakMapSet, 3, 1) \ 303 \ 304 /* Statements */ \ 305 F(NewClosure, 3, 1) \ 306 F(NewObject, 1, 1) \ 307 F(NewObjectFromBound, 2, 1) \ 308 F(FinalizeInstanceSize, 1, 1) \ 309 F(Throw, 1, 1) \ 310 F(ReThrow, 1, 1) \ 311 F(ThrowReferenceError, 1, 1) \ 312 F(StackGuard, 0, 1) \ 313 F(PromoteScheduledException, 0, 1) \ 314 \ 315 /* Contexts */ \ 316 F(NewFunctionContext, 1, 1) \ 317 F(PushWithContext, 2, 1) \ 318 F(PushCatchContext, 3, 1) \ 319 F(PushBlockContext, 2, 1) \ 320 F(DeleteContextSlot, 2, 1) \ 321 F(LoadContextSlot, 2, 2) \ 322 F(LoadContextSlotNoReferenceError, 2, 2) \ 323 F(StoreContextSlot, 4, 1) \ 324 \ 325 /* Declarations and initialization */ \ 326 F(DeclareGlobals, 3, 1) \ 327 F(DeclareContextSlot, 4, 1) \ 328 F(InitializeVarGlobal, -1 /* 2 or 3 */, 1) \ 329 F(InitializeConstGlobal, 2, 1) \ 330 F(InitializeConstContextSlot, 3, 1) \ 331 F(OptimizeObjectForAddingMultipleProperties, 2, 1) \ 332 \ 333 /* Debugging */ \ 334 F(DebugPrint, 1, 1) \ 335 F(DebugTrace, 0, 1) \ 336 F(TraceEnter, 0, 1) \ 337 F(TraceExit, 1, 1) \ 338 F(Abort, 2, 1) \ 339 /* Logging */ \ 340 F(Log, 2, 1) \ 341 /* ES5 */ \ 342 F(LocalKeys, 1, 1) \ 343 /* Cache suport */ \ 344 F(GetFromCache, 2, 1) \ 345 \ 346 /* Message objects */ \ 347 F(NewMessageObject, 2, 1) \ 348 F(MessageGetType, 1, 1) \ 349 F(MessageGetArguments, 1, 1) \ 350 F(MessageGetStartPosition, 1, 1) \ 351 F(MessageGetScript, 1, 1) \ 352 \ 353 /* Pseudo functions - handled as macros by parser */ \ 354 F(IS_VAR, 1, 1) \ 355 \ 356 /* expose boolean functions from objects-inl.h */ \ 357 F(HasFastElements, 1, 1) \ 358 F(HasFastDoubleElements, 1, 1) \ 359 F(HasDictionaryElements, 1, 1) \ 360 F(HasExternalPixelElements, 1, 1) \ 361 F(HasExternalArrayElements, 1, 1) \ 362 F(HasExternalByteElements, 1, 1) \ 363 F(HasExternalUnsignedByteElements, 1, 1) \ 364 F(HasExternalShortElements, 1, 1) \ 365 F(HasExternalUnsignedShortElements, 1, 1) \ 366 F(HasExternalIntElements, 1, 1) \ 367 F(HasExternalUnsignedIntElements, 1, 1) \ 368 F(HasExternalFloatElements, 1, 1) \ 369 F(HasExternalDoubleElements, 1, 1) \ 370 /* profiler */ \ 371 F(ProfilerResume, 0, 1) \ 372 F(ProfilerPause, 0, 1) 373 374 375#ifdef ENABLE_DEBUGGER_SUPPORT 376#define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \ 377 /* Debugger support*/ \ 378 F(DebugBreak, 0, 1) \ 379 F(SetDebugEventListener, 2, 1) \ 380 F(Break, 0, 1) \ 381 F(DebugGetPropertyDetails, 2, 1) \ 382 F(DebugGetProperty, 2, 1) \ 383 F(DebugPropertyTypeFromDetails, 1, 1) \ 384 F(DebugPropertyAttributesFromDetails, 1, 1) \ 385 F(DebugPropertyIndexFromDetails, 1, 1) \ 386 F(DebugNamedInterceptorPropertyValue, 2, 1) \ 387 F(DebugIndexedInterceptorElementValue, 2, 1) \ 388 F(CheckExecutionState, 1, 1) \ 389 F(GetFrameCount, 1, 1) \ 390 F(GetFrameDetails, 2, 1) \ 391 F(GetScopeCount, 2, 1) \ 392 F(GetScopeDetails, 4, 1) \ 393 F(DebugPrintScopes, 0, 1) \ 394 F(GetThreadCount, 1, 1) \ 395 F(GetThreadDetails, 2, 1) \ 396 F(SetDisableBreak, 1, 1) \ 397 F(GetBreakLocations, 1, 1) \ 398 F(SetFunctionBreakPoint, 3, 1) \ 399 F(SetScriptBreakPoint, 3, 1) \ 400 F(ClearBreakPoint, 1, 1) \ 401 F(ChangeBreakOnException, 2, 1) \ 402 F(IsBreakOnException, 1, 1) \ 403 F(PrepareStep, 3, 1) \ 404 F(ClearStepping, 0, 1) \ 405 F(DebugEvaluate, 6, 1) \ 406 F(DebugEvaluateGlobal, 4, 1) \ 407 F(DebugGetLoadedScripts, 0, 1) \ 408 F(DebugReferencedBy, 3, 1) \ 409 F(DebugConstructedBy, 2, 1) \ 410 F(DebugGetPrototype, 1, 1) \ 411 F(SystemBreak, 0, 1) \ 412 F(DebugDisassembleFunction, 1, 1) \ 413 F(DebugDisassembleConstructor, 1, 1) \ 414 F(FunctionGetInferredName, 1, 1) \ 415 F(LiveEditFindSharedFunctionInfosForScript, 1, 1) \ 416 F(LiveEditGatherCompileInfo, 2, 1) \ 417 F(LiveEditReplaceScript, 3, 1) \ 418 F(LiveEditReplaceFunctionCode, 2, 1) \ 419 F(LiveEditFunctionSourceUpdated, 1, 1) \ 420 F(LiveEditFunctionSetScript, 2, 1) \ 421 F(LiveEditReplaceRefToNestedFunction, 3, 1) \ 422 F(LiveEditPatchFunctionPositions, 2, 1) \ 423 F(LiveEditCheckAndDropActivations, 2, 1) \ 424 F(LiveEditCompareStrings, 2, 1) \ 425 F(GetFunctionCodePositionFromSource, 2, 1) \ 426 F(ExecuteInDebugContext, 2, 1) \ 427 \ 428 F(SetFlags, 1, 1) \ 429 F(CollectGarbage, 1, 1) \ 430 F(GetHeapUsage, 0, 1) \ 431 \ 432 /* LiveObjectList support*/ \ 433 F(HasLOLEnabled, 0, 1) \ 434 F(CaptureLOL, 0, 1) \ 435 F(DeleteLOL, 1, 1) \ 436 F(DumpLOL, 5, 1) \ 437 F(GetLOLObj, 1, 1) \ 438 F(GetLOLObjId, 1, 1) \ 439 F(GetLOLObjRetainers, 6, 1) \ 440 F(GetLOLPath, 3, 1) \ 441 F(InfoLOL, 2, 1) \ 442 F(PrintLOLObj, 1, 1) \ 443 F(ResetLOL, 0, 1) \ 444 F(SummarizeLOL, 3, 1) 445 446#else 447#define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) 448#endif 449 450#ifdef DEBUG 451#define RUNTIME_FUNCTION_LIST_DEBUG(F) \ 452 /* Testing */ \ 453 F(ListNatives, 0, 1) 454#else 455#define RUNTIME_FUNCTION_LIST_DEBUG(F) 456#endif 457 458// ---------------------------------------------------------------------------- 459// RUNTIME_FUNCTION_LIST defines all runtime functions accessed 460// either directly by id (via the code generator), or indirectly 461// via a native call by name (from within JS code). 462 463#define RUNTIME_FUNCTION_LIST(F) \ 464 RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \ 465 RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \ 466 RUNTIME_FUNCTION_LIST_DEBUG(F) \ 467 RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) 468 469// ---------------------------------------------------------------------------- 470// INLINE_FUNCTION_LIST defines all inlined functions accessed 471// with a native call of the form %_name from within JS code. 472// Entries have the form F(name, number of arguments, number of return values). 473#define INLINE_FUNCTION_LIST(F) \ 474 F(IsSmi, 1, 1) \ 475 F(IsNonNegativeSmi, 1, 1) \ 476 F(IsArray, 1, 1) \ 477 F(IsRegExp, 1, 1) \ 478 F(CallFunction, -1 /* receiver + n args + function */, 1) \ 479 F(ArgumentsLength, 0, 1) \ 480 F(Arguments, 1, 1) \ 481 F(ValueOf, 1, 1) \ 482 F(SetValueOf, 2, 1) \ 483 F(StringCharFromCode, 1, 1) \ 484 F(StringCharAt, 2, 1) \ 485 F(ObjectEquals, 2, 1) \ 486 F(RandomHeapNumber, 0, 1) \ 487 F(IsObject, 1, 1) \ 488 F(IsFunction, 1, 1) \ 489 F(IsUndetectableObject, 1, 1) \ 490 F(IsSpecObject, 1, 1) \ 491 F(IsStringWrapperSafeForDefaultValueOf, 1, 1) \ 492 F(MathPow, 2, 1) \ 493 F(MathSin, 1, 1) \ 494 F(MathCos, 1, 1) \ 495 F(MathSqrt, 1, 1) \ 496 F(MathLog, 1, 1) \ 497 F(IsRegExpEquivalent, 2, 1) \ 498 F(HasCachedArrayIndex, 1, 1) \ 499 F(GetCachedArrayIndex, 1, 1) \ 500 F(FastAsciiArrayJoin, 2, 1) 501 502 503// ---------------------------------------------------------------------------- 504// INLINE_AND_RUNTIME_FUNCTION_LIST defines all inlined functions accessed 505// with a native call of the form %_name from within JS code that also have 506// a corresponding runtime function, that is called for slow cases. 507// Entries have the form F(name, number of arguments, number of return values). 508#define INLINE_RUNTIME_FUNCTION_LIST(F) \ 509 F(IsConstructCall, 0, 1) \ 510 F(ClassOf, 1, 1) \ 511 F(StringCharCodeAt, 2, 1) \ 512 F(Log, 3, 1) \ 513 F(StringAdd, 2, 1) \ 514 F(SubString, 3, 1) \ 515 F(StringCompare, 2, 1) \ 516 F(RegExpExec, 4, 1) \ 517 F(RegExpConstructResult, 3, 1) \ 518 F(GetFromCache, 2, 1) \ 519 F(NumberToString, 1, 1) \ 520 F(SwapElements, 3, 1) 521 522 523//--------------------------------------------------------------------------- 524// Runtime provides access to all C++ runtime functions. 525 526class RuntimeState { 527 public: 528 StaticResource<StringInputBuffer>* string_input_buffer() { 529 return &string_input_buffer_; 530 } 531 unibrow::Mapping<unibrow::ToUppercase, 128>* to_upper_mapping() { 532 return &to_upper_mapping_; 533 } 534 unibrow::Mapping<unibrow::ToLowercase, 128>* to_lower_mapping() { 535 return &to_lower_mapping_; 536 } 537 StringInputBuffer* string_input_buffer_compare_bufx() { 538 return &string_input_buffer_compare_bufx_; 539 } 540 StringInputBuffer* string_input_buffer_compare_bufy() { 541 return &string_input_buffer_compare_bufy_; 542 } 543 StringInputBuffer* string_locale_compare_buf1() { 544 return &string_locale_compare_buf1_; 545 } 546 StringInputBuffer* string_locale_compare_buf2() { 547 return &string_locale_compare_buf2_; 548 } 549 550 private: 551 RuntimeState() {} 552 // Non-reentrant string buffer for efficient general use in the runtime. 553 StaticResource<StringInputBuffer> string_input_buffer_; 554 unibrow::Mapping<unibrow::ToUppercase, 128> to_upper_mapping_; 555 unibrow::Mapping<unibrow::ToLowercase, 128> to_lower_mapping_; 556 StringInputBuffer string_input_buffer_compare_bufx_; 557 StringInputBuffer string_input_buffer_compare_bufy_; 558 StringInputBuffer string_locale_compare_buf1_; 559 StringInputBuffer string_locale_compare_buf2_; 560 561 friend class Isolate; 562 friend class Runtime; 563 564 DISALLOW_COPY_AND_ASSIGN(RuntimeState); 565}; 566 567 568class Runtime : public AllStatic { 569 public: 570 enum FunctionId { 571#define F(name, nargs, ressize) k##name, 572 RUNTIME_FUNCTION_LIST(F) 573#undef F 574#define F(name, nargs, ressize) kInline##name, 575 INLINE_FUNCTION_LIST(F) 576 INLINE_RUNTIME_FUNCTION_LIST(F) 577#undef F 578 kNumFunctions, 579 kFirstInlineFunction = kInlineIsSmi 580 }; 581 582 enum IntrinsicType { 583 RUNTIME, 584 INLINE 585 }; 586 587 // Intrinsic function descriptor. 588 struct Function { 589 FunctionId function_id; 590 IntrinsicType intrinsic_type; 591 // The JS name of the function. 592 const char* name; 593 594 // The C++ (native) entry point. NULL if the function is inlined. 595 byte* entry; 596 597 // The number of arguments expected. nargs is -1 if the function takes 598 // a variable number of arguments. 599 int nargs; 600 // Size of result. Most functions return a single pointer, size 1. 601 int result_size; 602 }; 603 604 static const int kNotFound = -1; 605 606 // Add symbols for all the intrinsic function names to a StringDictionary. 607 // Returns failure if an allocation fails. In this case, it must be 608 // retried with a new, empty StringDictionary, not with the same one. 609 // Alternatively, heap initialization can be completely restarted. 610 MUST_USE_RESULT static MaybeObject* InitializeIntrinsicFunctionNames( 611 Heap* heap, Object* dictionary); 612 613 // Get the intrinsic function with the given name, which must be a symbol. 614 static const Function* FunctionForSymbol(Handle<String> name); 615 616 // Get the intrinsic function with the given FunctionId. 617 static const Function* FunctionForId(FunctionId id); 618 619 // General-purpose helper functions for runtime system. 620 static int StringMatch(Isolate* isolate, 621 Handle<String> sub, 622 Handle<String> pat, 623 int index); 624 625 static bool IsUpperCaseChar(RuntimeState* runtime_state, uint16_t ch); 626 627 // TODO(1240886): The following three methods are *not* handle safe, 628 // but accept handle arguments. This seems fragile. 629 630 // Support getting the characters in a string using [] notation as 631 // in Firefox/SpiderMonkey, Safari and Opera. 632 MUST_USE_RESULT static MaybeObject* GetElementOrCharAt(Isolate* isolate, 633 Handle<Object> object, 634 uint32_t index); 635 MUST_USE_RESULT static MaybeObject* GetElement(Handle<Object> object, 636 uint32_t index); 637 638 MUST_USE_RESULT static MaybeObject* SetObjectProperty( 639 Isolate* isolate, 640 Handle<Object> object, 641 Handle<Object> key, 642 Handle<Object> value, 643 PropertyAttributes attr, 644 StrictModeFlag strict_mode); 645 646 MUST_USE_RESULT static MaybeObject* ForceSetObjectProperty( 647 Isolate* isolate, 648 Handle<JSObject> object, 649 Handle<Object> key, 650 Handle<Object> value, 651 PropertyAttributes attr); 652 653 MUST_USE_RESULT static MaybeObject* ForceDeleteObjectProperty( 654 Isolate* isolate, 655 Handle<JSReceiver> object, 656 Handle<Object> key); 657 658 MUST_USE_RESULT static MaybeObject* GetObjectProperty( 659 Isolate* isolate, 660 Handle<Object> object, 661 Handle<Object> key); 662 663 // This function is used in FunctionNameUsing* tests. 664 static Object* FindSharedFunctionInfoInScript(Isolate* isolate, 665 Handle<Script> script, 666 int position); 667 668 // Helper functions used stubs. 669 static void PerformGC(Object* result); 670}; 671 672 673//--------------------------------------------------------------------------- 674// Constants used by interface to runtime functions. 675 676enum kDeclareGlobalsFlags { 677 kDeclareGlobalsEvalFlag = 1 << 0, 678 kDeclareGlobalsStrictModeFlag = 1 << 1, 679 kDeclareGlobalsNativeFlag = 1 << 2 680}; 681 682} } // namespace v8::internal 683 684#endif // V8_RUNTIME_H_ 685