Home | History | Annotate | Download | only in src
      1 // Copyright 2012 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 
     34 namespace v8 {
     35 namespace 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, 2, 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(FinishArrayPrototypeSetup, 1, 1) \
     66   F(SpecialArrayFunctions, 1, 1) \
     67   F(IsCallable, 1, 1) \
     68   F(IsClassicModeFunction, 1, 1) \
     69   F(GetDefaultReceiver, 1, 1) \
     70   \
     71   F(GetPrototype, 1, 1) \
     72   F(SetPrototype, 2, 1) \
     73   F(IsInPrototypeChain, 2, 1) \
     74   \
     75   F(GetOwnProperty, 2, 1) \
     76   \
     77   F(IsExtensible, 1, 1) \
     78   F(PreventExtensions, 1, 1)\
     79   \
     80   /* Utilities */ \
     81   F(CheckIsBootstrapping, 0, 1) \
     82   F(GetRootNaN, 0, 1) \
     83   F(Call, -1 /* >= 2 */, 1) \
     84   F(Apply, 5, 1) \
     85   F(GetFunctionDelegate, 1, 1) \
     86   F(GetConstructorDelegate, 1, 1) \
     87   F(NewArgumentsFast, 3, 1) \
     88   F(NewStrictArgumentsFast, 3, 1) \
     89   F(LazyCompile, 1, 1) \
     90   F(LazyRecompile, 1, 1) \
     91   F(ConcurrentRecompile, 1, 1) \
     92   F(TryInstallRecompiledCode, 1, 1) \
     93   F(NotifyDeoptimized, 1, 1) \
     94   F(NotifyStubFailure, 0, 1) \
     95   F(DeoptimizeFunction, 1, 1) \
     96   F(ClearFunctionTypeFeedback, 1, 1) \
     97   F(RunningInSimulator, 0, 1) \
     98   F(IsConcurrentRecompilationSupported, 0, 1) \
     99   F(OptimizeFunctionOnNextCall, -1, 1) \
    100   F(NeverOptimizeFunction, 1, 1) \
    101   F(GetOptimizationStatus, -1, 1) \
    102   F(GetOptimizationCount, 1, 1) \
    103   F(UnblockConcurrentRecompilation, 0, 1) \
    104   F(CompileForOnStackReplacement, 2, 1) \
    105   F(SetAllocationTimeout, 2, 1) \
    106   F(AllocateInNewSpace, 1, 1) \
    107   F(AllocateInTargetSpace, 2, 1) \
    108   F(SetNativeFlag, 1, 1) \
    109   F(SetInlineBuiltinFlag, 1, 1) \
    110   F(StoreArrayLiteralElement, 5, 1) \
    111   F(DebugCallbackSupportsStepping, 1, 1) \
    112   F(DebugPrepareStepInIfStepping, 1, 1) \
    113   F(FlattenString, 1, 1) \
    114   F(MigrateInstance, 1, 1) \
    115   F(NotifyContextDisposed, 0, 1) \
    116   F(MaxSmi, 0, 1) \
    117   \
    118   /* Array join support */ \
    119   F(PushIfAbsent, 2, 1) \
    120   F(ArrayConcat, 1, 1) \
    121   \
    122   /* Conversions */ \
    123   F(ToBool, 1, 1) \
    124   F(Typeof, 1, 1) \
    125   \
    126   F(StringToNumber, 1, 1) \
    127   F(StringParseInt, 2, 1) \
    128   F(StringParseFloat, 1, 1) \
    129   F(StringToLowerCase, 1, 1) \
    130   F(StringToUpperCase, 1, 1) \
    131   F(StringSplit, 3, 1) \
    132   F(CharFromCode, 1, 1) \
    133   F(URIEscape, 1, 1) \
    134   F(URIUnescape, 1, 1) \
    135   \
    136   F(NumberToString, 1, 1) \
    137   F(NumberToStringSkipCache, 1, 1) \
    138   F(NumberToInteger, 1, 1) \
    139   F(NumberToPositiveInteger, 1, 1) \
    140   F(NumberToIntegerMapMinusZero, 1, 1) \
    141   F(NumberToJSUint32, 1, 1) \
    142   F(NumberToJSInt32, 1, 1) \
    143   F(NumberToSmi, 1, 1) \
    144   F(AllocateHeapNumber, 0, 1) \
    145   \
    146   /* Arithmetic operations */ \
    147   F(NumberAdd, 2, 1) \
    148   F(NumberSub, 2, 1) \
    149   F(NumberMul, 2, 1) \
    150   F(NumberDiv, 2, 1) \
    151   F(NumberMod, 2, 1) \
    152   F(NumberUnaryMinus, 1, 1) \
    153   F(NumberAlloc, 0, 1) \
    154   F(NumberImul, 2, 1) \
    155   \
    156   F(StringAdd, 2, 1) \
    157   F(StringBuilderConcat, 3, 1) \
    158   F(StringBuilderJoin, 3, 1) \
    159   F(SparseJoinWithSeparator, 3, 1) \
    160   \
    161   /* Bit operations */ \
    162   F(NumberOr, 2, 1) \
    163   F(NumberAnd, 2, 1) \
    164   F(NumberXor, 2, 1) \
    165   \
    166   F(NumberShl, 2, 1) \
    167   F(NumberShr, 2, 1) \
    168   F(NumberSar, 2, 1) \
    169   \
    170   /* Comparisons */ \
    171   F(NumberEquals, 2, 1) \
    172   F(StringEquals, 2, 1) \
    173   \
    174   F(NumberCompare, 3, 1) \
    175   F(SmiLexicographicCompare, 2, 1) \
    176   F(StringCompare, 2, 1) \
    177   \
    178   /* Math */ \
    179   F(Math_acos, 1, 1) \
    180   F(Math_asin, 1, 1) \
    181   F(Math_atan, 1, 1) \
    182   F(Math_atan2, 2, 1) \
    183   F(Math_cos, 1, 1) \
    184   F(Math_exp, 1, 1) \
    185   F(Math_floor, 1, 1) \
    186   F(Math_log, 1, 1) \
    187   F(Math_pow, 2, 1) \
    188   F(Math_pow_cfunction, 2, 1) \
    189   F(RoundNumber, 1, 1) \
    190   F(Math_sin, 1, 1) \
    191   F(Math_sqrt, 1, 1) \
    192   F(Math_tan, 1, 1) \
    193   \
    194   /* Regular expressions */ \
    195   F(RegExpCompile, 3, 1) \
    196   F(RegExpExec, 4, 1) \
    197   F(RegExpExecMultiple, 4, 1) \
    198   F(RegExpInitializeObject, 5, 1) \
    199   F(RegExpConstructResult, 3, 1) \
    200   \
    201   /* JSON */ \
    202   F(ParseJson, 1, 1) \
    203   F(BasicJSONStringify, 1, 1) \
    204   F(QuoteJSONString, 1, 1) \
    205   \
    206   /* Strings */ \
    207   F(StringCharCodeAt, 2, 1) \
    208   F(StringIndexOf, 3, 1) \
    209   F(StringLastIndexOf, 3, 1) \
    210   F(StringLocaleCompare, 2, 1) \
    211   F(SubString, 3, 1) \
    212   F(StringReplaceGlobalRegExpWithString, 4, 1) \
    213   F(StringReplaceOneCharWithString, 3, 1) \
    214   F(StringMatch, 3, 1) \
    215   F(StringTrim, 3, 1) \
    216   F(StringToArray, 2, 1) \
    217   F(NewStringWrapper, 1, 1) \
    218   F(NewString, 2, 1) \
    219   F(TruncateString, 2, 1) \
    220   \
    221   /* Numbers */ \
    222   F(NumberToRadixString, 2, 1) \
    223   F(NumberToFixed, 2, 1) \
    224   F(NumberToExponential, 2, 1) \
    225   F(NumberToPrecision, 2, 1) \
    226   F(IsValidSmi, 1, 1)
    227 
    228 
    229 #define RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
    230   /* Reflection */ \
    231   F(FunctionSetInstanceClassName, 2, 1) \
    232   F(FunctionSetLength, 2, 1) \
    233   F(FunctionSetPrototype, 2, 1) \
    234   F(FunctionSetReadOnlyPrototype, 1, 1) \
    235   F(FunctionGetName, 1, 1) \
    236   F(FunctionSetName, 2, 1) \
    237   F(FunctionNameShouldPrintAsAnonymous, 1, 1) \
    238   F(FunctionMarkNameShouldPrintAsAnonymous, 1, 1) \
    239   F(FunctionIsGenerator, 1, 1) \
    240   F(FunctionBindArguments, 4, 1) \
    241   F(BoundFunctionGetBindings, 1, 1) \
    242   F(FunctionRemovePrototype, 1, 1) \
    243   F(FunctionGetSourceCode, 1, 1) \
    244   F(FunctionGetScript, 1, 1) \
    245   F(FunctionGetScriptSourcePosition, 1, 1) \
    246   F(FunctionGetPositionForOffset, 2, 1) \
    247   F(FunctionIsAPIFunction, 1, 1) \
    248   F(FunctionIsBuiltin, 1, 1) \
    249   F(GetScript, 1, 1) \
    250   F(CollectStackTrace, 3, 1) \
    251   F(GetAndClearOverflowedStackTrace, 1, 1) \
    252   F(GetV8Version, 0, 1) \
    253   \
    254   F(ClassOf, 1, 1) \
    255   F(SetCode, 2, 1) \
    256   F(SetExpectedNumberOfProperties, 2, 1) \
    257   \
    258   F(CreateApiFunction, 1, 1) \
    259   F(IsTemplate, 1, 1) \
    260   F(GetTemplateField, 2, 1) \
    261   F(DisableAccessChecks, 1, 1) \
    262   F(EnableAccessChecks, 1, 1) \
    263   F(SetAccessorProperty, 6, 1) \
    264   \
    265   /* Dates */ \
    266   F(DateCurrentTime, 0, 1) \
    267   F(DateParseString, 2, 1) \
    268   F(DateLocalTimezone, 1, 1) \
    269   F(DateToUTC, 1, 1) \
    270   F(DateMakeDay, 2, 1) \
    271   F(DateSetValue, 3, 1) \
    272   \
    273   /* Numbers */ \
    274   \
    275   /* Globals */ \
    276   F(CompileString, 2, 1) \
    277   F(GlobalPrint, 1, 1) \
    278   \
    279   /* Eval */ \
    280   F(GlobalReceiver, 1, 1) \
    281   F(IsAttachedGlobal, 1, 1) \
    282   F(ResolvePossiblyDirectEval, 5, 2) \
    283   \
    284   F(SetProperty, -1 /* 4 or 5 */, 1) \
    285   F(DefineOrRedefineDataProperty, 4, 1) \
    286   F(DefineOrRedefineAccessorProperty, 5, 1) \
    287   F(IgnoreAttributesAndSetProperty, -1 /* 3 or 4 */, 1) \
    288   F(GetDataProperty, 2, 1) \
    289   \
    290   /* Arrays */ \
    291   F(RemoveArrayHoles, 2, 1) \
    292   F(GetArrayKeys, 2, 1) \
    293   F(MoveArrayContents, 2, 1) \
    294   F(EstimateNumberOfElements, 1, 1) \
    295   F(ArrayConstructor, -1, 1) \
    296   F(InternalArrayConstructor, -1, 1) \
    297   \
    298   /* Getters and Setters */ \
    299   F(LookupAccessor, 3, 1) \
    300   \
    301   /* Literals */ \
    302   F(MaterializeRegExpLiteral, 4, 1)\
    303   F(CreateObjectLiteral, 4, 1) \
    304   F(CreateArrayLiteral, 4, 1) \
    305   F(CreateArrayLiteralStubBailout, 3, 1) \
    306   \
    307   /* Harmony generators */ \
    308   F(CreateJSGeneratorObject, 0, 1) \
    309   F(SuspendJSGeneratorObject, 1, 1) \
    310   F(ResumeJSGeneratorObject, 3, 1) \
    311   F(ThrowGeneratorStateError, 1, 1) \
    312   \
    313   /* ES5 */ \
    314   F(ObjectFreeze, 1, 1) \
    315   \
    316   /* Harmony modules */ \
    317   F(IsJSModule, 1, 1) \
    318   \
    319   /* Harmony symbols */ \
    320   F(CreateSymbol, 1, 1) \
    321   F(CreatePrivateSymbol, 1, 1) \
    322   F(SymbolName, 1, 1) \
    323   F(SymbolIsPrivate, 1, 1) \
    324   \
    325   /* Harmony proxies */ \
    326   F(CreateJSProxy, 2, 1) \
    327   F(CreateJSFunctionProxy, 4, 1) \
    328   F(IsJSProxy, 1, 1) \
    329   F(IsJSFunctionProxy, 1, 1) \
    330   F(GetHandler, 1, 1) \
    331   F(GetCallTrap, 1, 1) \
    332   F(GetConstructTrap, 1, 1) \
    333   F(Fix, 1, 1) \
    334   \
    335   /* Harmony sets */ \
    336   F(SetInitialize, 1, 1) \
    337   F(SetAdd, 2, 1) \
    338   F(SetHas, 2, 1) \
    339   F(SetDelete, 2, 1) \
    340   F(SetGetSize, 1, 1) \
    341   \
    342   /* Harmony maps */ \
    343   F(MapInitialize, 1, 1) \
    344   F(MapGet, 2, 1) \
    345   F(MapHas, 2, 1) \
    346   F(MapDelete, 2, 1) \
    347   F(MapSet, 3, 1) \
    348   F(MapGetSize, 1, 1) \
    349   \
    350   /* Harmony weak maps and sets */ \
    351   F(WeakCollectionInitialize, 1, 1) \
    352   F(WeakCollectionGet, 2, 1) \
    353   F(WeakCollectionHas, 2, 1) \
    354   F(WeakCollectionDelete, 2, 1) \
    355   F(WeakCollectionSet, 3, 1) \
    356   \
    357   /* Harmony events */ \
    358   F(SetMicrotaskPending, 1, 1) \
    359   \
    360   /* Harmony observe */ \
    361   F(IsObserved, 1, 1) \
    362   F(SetIsObserved, 1, 1) \
    363   F(GetObservationState, 0, 1) \
    364   F(ObservationWeakMapCreate, 0, 1) \
    365   F(UnwrapGlobalProxy, 1, 1) \
    366   F(IsAccessAllowedForObserver, 3, 1) \
    367   \
    368   /* Harmony typed arrays */ \
    369   F(ArrayBufferInitialize, 2, 1)\
    370   F(ArrayBufferGetByteLength, 1, 1)\
    371   F(ArrayBufferSliceImpl, 3, 1) \
    372   F(ArrayBufferIsView, 1, 1) \
    373   \
    374   F(TypedArrayInitialize, 5, 1) \
    375   F(TypedArrayInitializeFromArrayLike, 4, 1) \
    376   F(TypedArrayGetBuffer, 1, 1) \
    377   F(TypedArrayGetByteLength, 1, 1) \
    378   F(TypedArrayGetByteOffset, 1, 1) \
    379   F(TypedArrayGetLength, 1, 1) \
    380   F(TypedArraySetFastCases, 3, 1) \
    381   \
    382   F(DataViewInitialize, 4, 1) \
    383   F(DataViewGetBuffer, 1, 1) \
    384   F(DataViewGetByteLength, 1, 1) \
    385   F(DataViewGetByteOffset, 1, 1) \
    386   F(DataViewGetInt8, 3, 1) \
    387   F(DataViewGetUint8, 3, 1) \
    388   F(DataViewGetInt16, 3, 1) \
    389   F(DataViewGetUint16, 3, 1) \
    390   F(DataViewGetInt32, 3, 1) \
    391   F(DataViewGetUint32, 3, 1) \
    392   F(DataViewGetFloat32, 3, 1) \
    393   F(DataViewGetFloat64, 3, 1) \
    394   \
    395   F(DataViewSetInt8, 4, 1) \
    396   F(DataViewSetUint8, 4, 1) \
    397   F(DataViewSetInt16, 4, 1) \
    398   F(DataViewSetUint16, 4, 1) \
    399   F(DataViewSetInt32, 4, 1) \
    400   F(DataViewSetUint32, 4, 1) \
    401   F(DataViewSetFloat32, 4, 1) \
    402   F(DataViewSetFloat64, 4, 1) \
    403   \
    404   /* Statements */ \
    405   F(NewClosure, 3, 1) \
    406   F(NewClosureFromStubFailure, 1, 1) \
    407   F(NewObject, 1, 1) \
    408   F(NewObjectFromBound, 1, 1) \
    409   F(FinalizeInstanceSize, 1, 1) \
    410   F(Throw, 1, 1) \
    411   F(ReThrow, 1, 1) \
    412   F(ThrowReferenceError, 1, 1) \
    413   F(ThrowNotDateError, 0, 1) \
    414   F(ThrowMessage, 1, 1) \
    415   F(StackGuard, 0, 1) \
    416   F(Interrupt, 0, 1) \
    417   F(PromoteScheduledException, 0, 1) \
    418   \
    419   /* Contexts */ \
    420   F(NewGlobalContext, 2, 1) \
    421   F(NewFunctionContext, 1, 1) \
    422   F(PushWithContext, 2, 1) \
    423   F(PushCatchContext, 3, 1) \
    424   F(PushBlockContext, 2, 1) \
    425   F(PushModuleContext, 2, 1) \
    426   F(DeleteContextSlot, 2, 1) \
    427   F(LoadContextSlot, 2, 2) \
    428   F(LoadContextSlotNoReferenceError, 2, 2) \
    429   F(StoreContextSlot, 4, 1) \
    430   \
    431   /* Declarations and initialization */ \
    432   F(DeclareGlobals, 3, 1) \
    433   F(DeclareModules, 1, 1) \
    434   F(DeclareContextSlot, 4, 1) \
    435   F(InitializeVarGlobal, -1 /* 2 or 3 */, 1) \
    436   F(InitializeConstGlobal, 2, 1) \
    437   F(InitializeConstContextSlot, 3, 1) \
    438   F(OptimizeObjectForAddingMultipleProperties, 2, 1) \
    439   \
    440   /* Debugging */ \
    441   F(DebugPrint, 1, 1) \
    442   F(DebugTrace, 0, 1) \
    443   F(TraceEnter, 0, 1) \
    444   F(TraceExit, 1, 1) \
    445   F(Abort, 2, 1) \
    446   F(AbortJS, 1, 1) \
    447   /* Logging */ \
    448   F(Log, 2, 1) \
    449   /* ES5 */ \
    450   F(LocalKeys, 1, 1) \
    451   /* Cache suport */ \
    452   F(GetFromCache, 2, 1) \
    453   \
    454   /* Message objects */ \
    455   F(MessageGetStartPosition, 1, 1) \
    456   F(MessageGetScript, 1, 1) \
    457   \
    458   /* Pseudo functions - handled as macros by parser */ \
    459   F(IS_VAR, 1, 1) \
    460   \
    461   /* expose boolean functions from objects-inl.h */ \
    462   F(HasFastSmiElements, 1, 1) \
    463   F(HasFastSmiOrObjectElements, 1, 1) \
    464   F(HasFastObjectElements, 1, 1) \
    465   F(HasFastDoubleElements, 1, 1) \
    466   F(HasFastHoleyElements, 1, 1) \
    467   F(HasDictionaryElements, 1, 1) \
    468   F(HasNonStrictArgumentsElements, 1, 1) \
    469   F(HasExternalPixelElements, 1, 1) \
    470   F(HasExternalArrayElements, 1, 1) \
    471   F(HasExternalByteElements, 1, 1) \
    472   F(HasExternalUnsignedByteElements, 1, 1) \
    473   F(HasExternalShortElements, 1, 1) \
    474   F(HasExternalUnsignedShortElements, 1, 1) \
    475   F(HasExternalIntElements, 1, 1) \
    476   F(HasExternalUnsignedIntElements, 1, 1) \
    477   F(HasExternalFloatElements, 1, 1) \
    478   F(HasExternalDoubleElements, 1, 1) \
    479   F(HasFastProperties, 1, 1) \
    480   F(TransitionElementsKind, 2, 1) \
    481   F(HaveSameMap, 2, 1) \
    482   F(IsAccessCheckNeeded, 1, 1)
    483 
    484 
    485 #ifdef ENABLE_DEBUGGER_SUPPORT
    486 #define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \
    487   /* Debugger support*/ \
    488   F(DebugBreak, 0, 1) \
    489   F(SetDebugEventListener, 2, 1) \
    490   F(Break, 0, 1) \
    491   F(DebugGetPropertyDetails, 2, 1) \
    492   F(DebugGetProperty, 2, 1) \
    493   F(DebugPropertyTypeFromDetails, 1, 1) \
    494   F(DebugPropertyAttributesFromDetails, 1, 1) \
    495   F(DebugPropertyIndexFromDetails, 1, 1) \
    496   F(DebugNamedInterceptorPropertyValue, 2, 1) \
    497   F(DebugIndexedInterceptorElementValue, 2, 1) \
    498   F(CheckExecutionState, 1, 1) \
    499   F(GetFrameCount, 1, 1) \
    500   F(GetFrameDetails, 2, 1) \
    501   F(GetScopeCount, 2, 1) \
    502   F(GetStepInPositions, 2, 1) \
    503   F(GetScopeDetails, 4, 1) \
    504   F(GetFunctionScopeCount, 1, 1) \
    505   F(GetFunctionScopeDetails, 2, 1) \
    506   F(SetScopeVariableValue, 6, 1) \
    507   F(DebugPrintScopes, 0, 1) \
    508   F(GetThreadCount, 1, 1) \
    509   F(GetThreadDetails, 2, 1) \
    510   F(SetDisableBreak, 1, 1) \
    511   F(GetBreakLocations, 2, 1) \
    512   F(SetFunctionBreakPoint, 3, 1) \
    513   F(SetScriptBreakPoint, 4, 1) \
    514   F(ClearBreakPoint, 1, 1) \
    515   F(ChangeBreakOnException, 2, 1) \
    516   F(IsBreakOnException, 1, 1) \
    517   F(PrepareStep, 4, 1) \
    518   F(ClearStepping, 0, 1) \
    519   F(DebugEvaluate, 6, 1) \
    520   F(DebugEvaluateGlobal, 4, 1) \
    521   F(DebugGetLoadedScripts, 0, 1) \
    522   F(DebugReferencedBy, 3, 1) \
    523   F(DebugConstructedBy, 2, 1) \
    524   F(DebugGetPrototype, 1, 1) \
    525   F(DebugSetScriptSource, 2, 1) \
    526   F(SystemBreak, 0, 1) \
    527   F(DebugDisassembleFunction, 1, 1) \
    528   F(DebugDisassembleConstructor, 1, 1) \
    529   F(FunctionGetInferredName, 1, 1) \
    530   F(LiveEditFindSharedFunctionInfosForScript, 1, 1) \
    531   F(LiveEditGatherCompileInfo, 2, 1) \
    532   F(LiveEditReplaceScript, 3, 1) \
    533   F(LiveEditReplaceFunctionCode, 2, 1) \
    534   F(LiveEditFunctionSourceUpdated, 1, 1) \
    535   F(LiveEditFunctionSetScript, 2, 1) \
    536   F(LiveEditReplaceRefToNestedFunction, 3, 1) \
    537   F(LiveEditPatchFunctionPositions, 2, 1) \
    538   F(LiveEditCheckAndDropActivations, 2, 1) \
    539   F(LiveEditCompareStrings, 2, 1) \
    540   F(LiveEditRestartFrame, 2, 1) \
    541   F(GetFunctionCodePositionFromSource, 2, 1) \
    542   F(ExecuteInDebugContext, 2, 1) \
    543   \
    544   F(SetFlags, 1, 1) \
    545   F(CollectGarbage, 1, 1) \
    546   F(GetHeapUsage, 0, 1) \
    547 
    548 #else
    549 #define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F)
    550 #endif
    551 
    552 
    553 #ifdef V8_I18N_SUPPORT
    554 #define RUNTIME_FUNCTION_LIST_I18N_SUPPORT(F) \
    555   /* i18n support */ \
    556   /* Standalone, helper methods. */ \
    557   F(CanonicalizeLanguageTag, 1, 1) \
    558   F(AvailableLocalesOf, 1, 1) \
    559   F(GetDefaultICULocale, 0, 1) \
    560   F(GetLanguageTagVariants, 1, 1) \
    561   \
    562   /* Date format and parse. */ \
    563   F(CreateDateTimeFormat, 3, 1) \
    564   F(InternalDateFormat, 2, 1) \
    565   F(InternalDateParse, 2, 1) \
    566   \
    567   /* Number format and parse. */ \
    568   F(CreateNumberFormat, 3, 1) \
    569   F(InternalNumberFormat, 2, 1) \
    570   F(InternalNumberParse, 2, 1) \
    571   \
    572   /* Collator. */ \
    573   F(CreateCollator, 3, 1) \
    574   F(InternalCompare, 3, 1) \
    575   \
    576   /* Break iterator. */ \
    577   F(CreateBreakIterator, 3, 1) \
    578   F(BreakIteratorAdoptText, 2, 1) \
    579   F(BreakIteratorFirst, 1, 1) \
    580   F(BreakIteratorNext, 1, 1) \
    581   F(BreakIteratorCurrent, 1, 1) \
    582   F(BreakIteratorBreakType, 1, 1) \
    583 
    584 #else
    585 #define RUNTIME_FUNCTION_LIST_I18N_SUPPORT(F)
    586 #endif
    587 
    588 
    589 #ifdef DEBUG
    590 #define RUNTIME_FUNCTION_LIST_DEBUG(F) \
    591   /* Testing */ \
    592   F(ListNatives, 0, 1)
    593 #else
    594 #define RUNTIME_FUNCTION_LIST_DEBUG(F)
    595 #endif
    596 
    597 // ----------------------------------------------------------------------------
    598 // RUNTIME_FUNCTION_LIST defines all runtime functions accessed
    599 // either directly by id (via the code generator), or indirectly
    600 // via a native call by name (from within JS code).
    601 
    602 #define RUNTIME_FUNCTION_LIST(F) \
    603   RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
    604   RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
    605   RUNTIME_FUNCTION_LIST_DEBUG(F) \
    606   RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \
    607   RUNTIME_FUNCTION_LIST_I18N_SUPPORT(F)
    608 
    609 // ----------------------------------------------------------------------------
    610 // INLINE_FUNCTION_LIST defines all inlined functions accessed
    611 // with a native call of the form %_name from within JS code.
    612 // Entries have the form F(name, number of arguments, number of return values).
    613 #define INLINE_FUNCTION_LIST(F) \
    614   F(IsSmi, 1, 1)                                                             \
    615   F(IsNonNegativeSmi, 1, 1)                                                  \
    616   F(IsArray, 1, 1)                                                           \
    617   F(IsRegExp, 1, 1)                                                          \
    618   F(IsConstructCall, 0, 1)                                                   \
    619   F(CallFunction, -1 /* receiver + n args + function */, 1)                  \
    620   F(ArgumentsLength, 0, 1)                                                   \
    621   F(Arguments, 1, 1)                                                         \
    622   F(ValueOf, 1, 1)                                                           \
    623   F(SetValueOf, 2, 1)                                                        \
    624   F(DateField, 2 /* date object, field index */, 1)                          \
    625   F(StringCharFromCode, 1, 1)                                                \
    626   F(StringCharAt, 2, 1)                                                      \
    627   F(OneByteSeqStringSetChar, 3, 1)                                           \
    628   F(TwoByteSeqStringSetChar, 3, 1)                                           \
    629   F(ObjectEquals, 2, 1)                                                      \
    630   F(IsObject, 1, 1)                                                          \
    631   F(IsFunction, 1, 1)                                                        \
    632   F(IsUndetectableObject, 1, 1)                                              \
    633   F(IsSpecObject, 1, 1)                                                      \
    634   F(IsStringWrapperSafeForDefaultValueOf, 1, 1)                              \
    635   F(MathPow, 2, 1)                                                           \
    636   F(MathSqrt, 1, 1)                                                          \
    637   F(MathLog, 1, 1)                                                           \
    638   F(IsMinusZero, 1, 1)                                                       \
    639   F(IsRegExpEquivalent, 2, 1)                                                \
    640   F(HasCachedArrayIndex, 1, 1)                                               \
    641   F(GetCachedArrayIndex, 1, 1)                                               \
    642   F(FastAsciiArrayJoin, 2, 1)                                                \
    643   F(GeneratorNext, 2, 1)                                                     \
    644   F(GeneratorThrow, 2, 1)                                                    \
    645   F(DebugBreakInOptimizedCode, 0, 1)
    646 
    647 
    648 // ----------------------------------------------------------------------------
    649 // INLINE_RUNTIME_FUNCTION_LIST defines all inlined functions accessed
    650 // with a native call of the form %_name from within JS code that also have
    651 // a corresponding runtime function, that is called for slow cases.
    652 // Entries have the form F(name, number of arguments, number of return values).
    653 #define INLINE_RUNTIME_FUNCTION_LIST(F) \
    654   F(ClassOf, 1, 1)                                                           \
    655   F(StringCharCodeAt, 2, 1)                                                  \
    656   F(Log, 3, 1)                                                               \
    657   F(StringAdd, 2, 1)                                                         \
    658   F(SubString, 3, 1)                                                         \
    659   F(StringCompare, 2, 1)                                                     \
    660   F(RegExpExec, 4, 1)                                                        \
    661   F(RegExpConstructResult, 3, 1)                                             \
    662   F(GetFromCache, 2, 1)                                                      \
    663   F(NumberToString, 1, 1)
    664 
    665 
    666 //---------------------------------------------------------------------------
    667 // Runtime provides access to all C++ runtime functions.
    668 
    669 class RuntimeState {
    670  public:
    671   StaticResource<ConsStringIteratorOp>* string_iterator() {
    672     return &string_iterator_;
    673   }
    674   unibrow::Mapping<unibrow::ToUppercase, 128>* to_upper_mapping() {
    675     return &to_upper_mapping_;
    676   }
    677   unibrow::Mapping<unibrow::ToLowercase, 128>* to_lower_mapping() {
    678     return &to_lower_mapping_;
    679   }
    680   ConsStringIteratorOp* string_iterator_compare_x() {
    681     return &string_iterator_compare_x_;
    682   }
    683   ConsStringIteratorOp* string_iterator_compare_y() {
    684     return &string_iterator_compare_y_;
    685   }
    686   ConsStringIteratorOp* string_locale_compare_it1() {
    687     return &string_locale_compare_it1_;
    688   }
    689   ConsStringIteratorOp* string_locale_compare_it2() {
    690     return &string_locale_compare_it2_;
    691   }
    692 
    693  private:
    694   RuntimeState() {}
    695   // Non-reentrant string buffer for efficient general use in the runtime.
    696   StaticResource<ConsStringIteratorOp> string_iterator_;
    697   unibrow::Mapping<unibrow::ToUppercase, 128> to_upper_mapping_;
    698   unibrow::Mapping<unibrow::ToLowercase, 128> to_lower_mapping_;
    699   ConsStringIteratorOp string_iterator_compare_x_;
    700   ConsStringIteratorOp string_iterator_compare_y_;
    701   ConsStringIteratorOp string_locale_compare_it1_;
    702   ConsStringIteratorOp string_locale_compare_it2_;
    703 
    704   friend class Isolate;
    705   friend class Runtime;
    706 
    707   DISALLOW_COPY_AND_ASSIGN(RuntimeState);
    708 };
    709 
    710 
    711 class Runtime : public AllStatic {
    712  public:
    713   enum FunctionId {
    714 #define F(name, nargs, ressize) k##name,
    715     RUNTIME_FUNCTION_LIST(F)
    716 #undef F
    717 #define F(name, nargs, ressize) kInline##name,
    718     INLINE_FUNCTION_LIST(F)
    719     INLINE_RUNTIME_FUNCTION_LIST(F)
    720 #undef F
    721     kNumFunctions,
    722     kFirstInlineFunction = kInlineIsSmi
    723   };
    724 
    725   enum IntrinsicType {
    726     RUNTIME,
    727     INLINE
    728   };
    729 
    730   // Intrinsic function descriptor.
    731   struct Function {
    732     FunctionId function_id;
    733     IntrinsicType intrinsic_type;
    734     // The JS name of the function.
    735     const char* name;
    736 
    737     // The C++ (native) entry point.  NULL if the function is inlined.
    738     byte* entry;
    739 
    740     // The number of arguments expected. nargs is -1 if the function takes
    741     // a variable number of arguments.
    742     int nargs;
    743     // Size of result.  Most functions return a single pointer, size 1.
    744     int result_size;
    745   };
    746 
    747   static const int kNotFound = -1;
    748 
    749   // Add internalized strings for all the intrinsic function names to a
    750   // StringDictionary.
    751   // Returns failure if an allocation fails.  In this case, it must be
    752   // retried with a new, empty StringDictionary, not with the same one.
    753   // Alternatively, heap initialization can be completely restarted.
    754   MUST_USE_RESULT static MaybeObject* InitializeIntrinsicFunctionNames(
    755       Heap* heap, Object* dictionary);
    756 
    757   // Get the intrinsic function with the given name, which must be internalized.
    758   static const Function* FunctionForName(Handle<String> name);
    759 
    760   // Get the intrinsic function with the given FunctionId.
    761   static const Function* FunctionForId(FunctionId id);
    762 
    763   // General-purpose helper functions for runtime system.
    764   static int StringMatch(Isolate* isolate,
    765                          Handle<String> sub,
    766                          Handle<String> pat,
    767                          int index);
    768 
    769   static bool IsUpperCaseChar(RuntimeState* runtime_state, uint16_t ch);
    770 
    771   // TODO(1240886): Some of the following methods are *not* handle safe, but
    772   // accept handle arguments. This seems fragile.
    773 
    774   // Support getting the characters in a string using [] notation as
    775   // in Firefox/SpiderMonkey, Safari and Opera.
    776   MUST_USE_RESULT static MaybeObject* GetElementOrCharAt(Isolate* isolate,
    777                                                          Handle<Object> object,
    778                                                          uint32_t index);
    779 
    780   MUST_USE_RESULT static MaybeObject* GetElementOrCharAtOrFail(
    781       Isolate* isolate,
    782       Handle<Object> object,
    783       uint32_t index);
    784 
    785   static Handle<Object> SetObjectProperty(
    786       Isolate* isolate,
    787       Handle<Object> object,
    788       Handle<Object> key,
    789       Handle<Object> value,
    790       PropertyAttributes attr,
    791       StrictModeFlag strict_mode);
    792 
    793   static Handle<Object> ForceSetObjectProperty(
    794       Isolate* isolate,
    795       Handle<JSObject> object,
    796       Handle<Object> key,
    797       Handle<Object> value,
    798       PropertyAttributes attr);
    799 
    800   MUST_USE_RESULT static MaybeObject* DeleteObjectProperty(
    801       Isolate* isolate,
    802       Handle<JSReceiver> object,
    803       Handle<Object> key,
    804       JSReceiver::DeleteMode mode);
    805 
    806   MUST_USE_RESULT static MaybeObject* HasObjectProperty(
    807       Isolate* isolate,
    808       Handle<JSReceiver> object,
    809       Handle<Object> key);
    810 
    811   MUST_USE_RESULT static MaybeObject* GetObjectProperty(
    812       Isolate* isolate,
    813       Handle<Object> object,
    814       Handle<Object> key);
    815 
    816   MUST_USE_RESULT static MaybeObject* GetObjectPropertyOrFail(
    817       Isolate* isolate,
    818       Handle<Object> object,
    819       Handle<Object> key);
    820 
    821   static void SetupArrayBuffer(Isolate* isolate,
    822                                Handle<JSArrayBuffer> array_buffer,
    823                                bool is_external,
    824                                void* data,
    825                                size_t allocated_length);
    826 
    827   static bool SetupArrayBufferAllocatingData(
    828       Isolate* isolate,
    829       Handle<JSArrayBuffer> array_buffer,
    830       size_t allocated_length,
    831       bool initialize = true);
    832 
    833   static void FreeArrayBuffer(
    834       Isolate* isolate,
    835       JSArrayBuffer* phantom_array_buffer);
    836 
    837   enum TypedArrayId {
    838     // arrayIds below should be synchromized with typedarray.js natives.
    839     ARRAY_ID_UINT8 = 1,
    840     ARRAY_ID_INT8 = 2,
    841     ARRAY_ID_UINT16 = 3,
    842     ARRAY_ID_INT16 = 4,
    843     ARRAY_ID_UINT32 = 5,
    844     ARRAY_ID_INT32 = 6,
    845     ARRAY_ID_FLOAT32 = 7,
    846     ARRAY_ID_FLOAT64 = 8,
    847     ARRAY_ID_UINT8C = 9
    848   };
    849 
    850   static void ArrayIdToTypeAndSize(int array_id,
    851       ExternalArrayType *type, size_t *element_size);
    852 
    853   // Helper functions used stubs.
    854   static void PerformGC(Object* result, Isolate* isolate);
    855 
    856   // Used in runtime.cc and hydrogen's VisitArrayLiteral.
    857   static Handle<Object> CreateArrayLiteralBoilerplate(
    858       Isolate* isolate,
    859       Handle<FixedArray> literals,
    860       Handle<FixedArray> elements);
    861 };
    862 
    863 
    864 //---------------------------------------------------------------------------
    865 // Constants used by interface to runtime functions.
    866 
    867 class AllocateDoubleAlignFlag:    public BitField<bool,            0, 1> {};
    868 class AllocateTargetSpace:        public BitField<AllocationSpace, 1, 3> {};
    869 
    870 class DeclareGlobalsEvalFlag:     public BitField<bool,         0, 1> {};
    871 class DeclareGlobalsNativeFlag:   public BitField<bool,         1, 1> {};
    872 class DeclareGlobalsLanguageMode: public BitField<LanguageMode, 2, 2> {};
    873 
    874 } }  // namespace v8::internal
    875 
    876 #endif  // V8_RUNTIME_H_
    877