1 // Copyright 2011 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_BUILTINS_BUILTINS_H_ 6 #define V8_BUILTINS_BUILTINS_H_ 7 8 #include "src/base/flags.h" 9 #include "src/handles.h" 10 11 namespace v8 { 12 namespace internal { 13 14 #define CODE_AGE_LIST_WITH_ARG(V, A) \ 15 V(Quadragenarian, A) \ 16 V(Quinquagenarian, A) \ 17 V(Sexagenarian, A) \ 18 V(Septuagenarian, A) \ 19 V(Octogenarian, A) 20 21 #define CODE_AGE_LIST_IGNORE_ARG(X, V) V(X) 22 23 #define CODE_AGE_LIST(V) CODE_AGE_LIST_WITH_ARG(CODE_AGE_LIST_IGNORE_ARG, V) 24 25 #define CODE_AGE_LIST_COMPLETE(V) \ 26 V(ToBeExecutedOnce) \ 27 V(NotExecuted) \ 28 V(ExecutedOnce) \ 29 V(NoAge) \ 30 CODE_AGE_LIST_WITH_ARG(CODE_AGE_LIST_IGNORE_ARG, V) 31 32 #define DECLARE_CODE_AGE_BUILTIN(C, V) \ 33 V(Make##C##CodeYoungAgainOddMarking) \ 34 V(Make##C##CodeYoungAgainEvenMarking) 35 36 // CPP: Builtin in C++. Entered via BUILTIN_EXIT frame. 37 // Args: name 38 // API: Builtin in C++ for API callbacks. Entered via EXIT frame. 39 // Args: name 40 // TFJ: Builtin in Turbofan, with JS linkage (callable as Javascript function). 41 // Args: name, arguments count 42 // TFS: Builtin in Turbofan, with CodeStub linkage. 43 // Args: name, code kind, extra IC state, interface descriptor 44 // ASM: Builtin in platform-dependent assembly. 45 // Args: name 46 // ASH: Handlers implemented in platform-dependent assembly. 47 // Args: name, code kind, extra IC state 48 // DBG: Builtin in platform-dependent assembly, used by the debugger. 49 // Args: name 50 #define BUILTIN_LIST(CPP, API, TFJ, TFS, ASM, ASH, DBG) \ 51 ASM(Abort) \ 52 /* Code aging */ \ 53 CODE_AGE_LIST_WITH_ARG(DECLARE_CODE_AGE_BUILTIN, ASM) \ 54 \ 55 TFS(ToObject, BUILTIN, kNoExtraICState, TypeConversion) \ 56 \ 57 /* Calls */ \ 58 ASM(ArgumentsAdaptorTrampoline) \ 59 /* ES6 section 9.2.1 [[Call]] ( thisArgument, argumentsList) */ \ 60 ASM(CallFunction_ReceiverIsNullOrUndefined) \ 61 ASM(CallFunction_ReceiverIsNotNullOrUndefined) \ 62 ASM(CallFunction_ReceiverIsAny) \ 63 ASM(TailCallFunction_ReceiverIsNullOrUndefined) \ 64 ASM(TailCallFunction_ReceiverIsNotNullOrUndefined) \ 65 ASM(TailCallFunction_ReceiverIsAny) \ 66 /* ES6 section 9.4.1.1 [[Call]] ( thisArgument, argumentsList) */ \ 67 ASM(CallBoundFunction) \ 68 ASM(TailCallBoundFunction) \ 69 /* ES6 section 7.3.12 Call(F, V, [argumentsList]) */ \ 70 ASM(Call_ReceiverIsNullOrUndefined) \ 71 ASM(Call_ReceiverIsNotNullOrUndefined) \ 72 ASM(Call_ReceiverIsAny) \ 73 ASM(TailCall_ReceiverIsNullOrUndefined) \ 74 ASM(TailCall_ReceiverIsNotNullOrUndefined) \ 75 ASM(TailCall_ReceiverIsAny) \ 76 \ 77 /* Construct */ \ 78 /* ES6 section 9.2.2 [[Construct]] ( argumentsList, newTarget) */ \ 79 ASM(ConstructFunction) \ 80 /* ES6 section 9.4.1.2 [[Construct]] (argumentsList, newTarget) */ \ 81 ASM(ConstructBoundFunction) \ 82 ASM(ConstructedNonConstructable) \ 83 /* ES6 section 9.5.14 [[Construct]] ( argumentsList, newTarget) */ \ 84 ASM(ConstructProxy) \ 85 /* ES6 section 7.3.13 Construct (F, [argumentsList], [newTarget]) */ \ 86 ASM(Construct) \ 87 ASM(JSConstructStubApi) \ 88 ASM(JSConstructStubGeneric) \ 89 ASM(JSBuiltinsConstructStub) \ 90 ASM(JSBuiltinsConstructStubForDerived) \ 91 \ 92 /* Apply and entries */ \ 93 ASM(Apply) \ 94 ASM(JSEntryTrampoline) \ 95 ASM(JSConstructEntryTrampoline) \ 96 ASM(ResumeGeneratorTrampoline) \ 97 \ 98 /* Stack and interrupt check */ \ 99 ASM(InterruptCheck) \ 100 ASM(StackCheck) \ 101 \ 102 /* String helpers */ \ 103 TFS(StringEqual, BUILTIN, kNoExtraICState, Compare) \ 104 TFS(StringNotEqual, BUILTIN, kNoExtraICState, Compare) \ 105 TFS(StringLessThan, BUILTIN, kNoExtraICState, Compare) \ 106 TFS(StringLessThanOrEqual, BUILTIN, kNoExtraICState, Compare) \ 107 TFS(StringGreaterThan, BUILTIN, kNoExtraICState, Compare) \ 108 TFS(StringGreaterThanOrEqual, BUILTIN, kNoExtraICState, Compare) \ 109 \ 110 /* Interpreter */ \ 111 ASM(InterpreterEntryTrampoline) \ 112 ASM(InterpreterPushArgsAndCall) \ 113 ASM(InterpreterPushArgsAndCallFunction) \ 114 ASM(InterpreterPushArgsAndTailCall) \ 115 ASM(InterpreterPushArgsAndTailCallFunction) \ 116 ASM(InterpreterPushArgsAndConstruct) \ 117 ASM(InterpreterPushArgsAndConstructFunction) \ 118 ASM(InterpreterPushArgsAndConstructArray) \ 119 ASM(InterpreterEnterBytecodeAdvance) \ 120 ASM(InterpreterEnterBytecodeDispatch) \ 121 ASM(InterpreterOnStackReplacement) \ 122 \ 123 /* Code life-cycle */ \ 124 ASM(CompileLazy) \ 125 ASM(CompileBaseline) \ 126 ASM(CompileOptimized) \ 127 ASM(CompileOptimizedConcurrent) \ 128 ASM(InOptimizationQueue) \ 129 ASM(InstantiateAsmJs) \ 130 ASM(MarkCodeAsToBeExecutedOnce) \ 131 ASM(MarkCodeAsExecutedOnce) \ 132 ASM(MarkCodeAsExecutedTwice) \ 133 ASM(NotifyDeoptimized) \ 134 ASM(NotifySoftDeoptimized) \ 135 ASM(NotifyLazyDeoptimized) \ 136 ASM(NotifyStubFailure) \ 137 ASM(NotifyStubFailureSaveDoubles) \ 138 ASM(OnStackReplacement) \ 139 \ 140 /* API callback handling */ \ 141 API(HandleApiCall) \ 142 API(HandleApiCallAsFunction) \ 143 API(HandleApiCallAsConstructor) \ 144 ASM(HandleFastApiCall) \ 145 \ 146 /* Adapters for Turbofan into runtime */ \ 147 ASM(AllocateInNewSpace) \ 148 ASM(AllocateInOldSpace) \ 149 \ 150 /* TurboFan support builtins */ \ 151 TFS(CopyFastSmiOrObjectElements, BUILTIN, kNoExtraICState, \ 152 CopyFastSmiOrObjectElements) \ 153 TFS(GrowFastDoubleElements, BUILTIN, kNoExtraICState, GrowArrayElements) \ 154 TFS(GrowFastSmiOrObjectElements, BUILTIN, kNoExtraICState, \ 155 GrowArrayElements) \ 156 \ 157 /* Debugger */ \ 158 DBG(FrameDropper_LiveEdit) \ 159 DBG(Return_DebugBreak) \ 160 DBG(Slot_DebugBreak) \ 161 \ 162 /* Type conversions */ \ 163 TFS(ToBoolean, BUILTIN, kNoExtraICState, TypeConversion) \ 164 TFS(OrdinaryToPrimitive_Number, BUILTIN, kNoExtraICState, TypeConversion) \ 165 TFS(OrdinaryToPrimitive_String, BUILTIN, kNoExtraICState, TypeConversion) \ 166 TFS(NonPrimitiveToPrimitive_Default, BUILTIN, kNoExtraICState, \ 167 TypeConversion) \ 168 TFS(NonPrimitiveToPrimitive_Number, BUILTIN, kNoExtraICState, \ 169 TypeConversion) \ 170 TFS(NonPrimitiveToPrimitive_String, BUILTIN, kNoExtraICState, \ 171 TypeConversion) \ 172 TFS(StringToNumber, BUILTIN, kNoExtraICState, TypeConversion) \ 173 TFS(ToName, BUILTIN, kNoExtraICState, TypeConversion) \ 174 TFS(NonNumberToNumber, BUILTIN, kNoExtraICState, TypeConversion) \ 175 TFS(ToNumber, BUILTIN, kNoExtraICState, TypeConversion) \ 176 TFS(ToString, BUILTIN, kNoExtraICState, TypeConversion) \ 177 TFS(ToInteger, BUILTIN, kNoExtraICState, TypeConversion) \ 178 TFS(ToLength, BUILTIN, kNoExtraICState, TypeConversion) \ 179 TFS(Typeof, BUILTIN, kNoExtraICState, Typeof) \ 180 \ 181 /* Handlers */ \ 182 TFS(KeyedLoadIC_Megamorphic_TF, KEYED_LOAD_IC, kNoExtraICState, \ 183 LoadWithVector) \ 184 ASM(KeyedLoadIC_Miss) \ 185 ASH(KeyedLoadIC_Slow, HANDLER, Code::KEYED_LOAD_IC) \ 186 ASH(KeyedStoreIC_Megamorphic, KEYED_STORE_IC, kNoExtraICState) \ 187 ASH(KeyedStoreIC_Megamorphic_Strict, KEYED_STORE_IC, \ 188 StoreICState::kStrictModeState) \ 189 TFS(KeyedStoreIC_Megamorphic_TF, KEYED_STORE_IC, kNoExtraICState, \ 190 StoreWithVector) \ 191 TFS(KeyedStoreIC_Megamorphic_Strict_TF, KEYED_STORE_IC, \ 192 StoreICState::kStrictModeState, StoreWithVector) \ 193 ASM(KeyedStoreIC_Miss) \ 194 ASH(KeyedStoreIC_Slow, HANDLER, Code::KEYED_STORE_IC) \ 195 TFS(LoadGlobalIC_Miss, BUILTIN, kNoExtraICState, LoadGlobalWithVector) \ 196 TFS(LoadGlobalIC_Slow, HANDLER, Code::LOAD_GLOBAL_IC, LoadGlobalWithVector) \ 197 ASH(LoadIC_Getter_ForDeopt, LOAD_IC, kNoExtraICState) \ 198 TFS(LoadIC_Miss, BUILTIN, kNoExtraICState, LoadWithVector) \ 199 ASH(LoadIC_Normal, HANDLER, Code::LOAD_IC) \ 200 TFS(LoadIC_Slow, HANDLER, Code::LOAD_IC, LoadWithVector) \ 201 TFS(StoreIC_Miss, BUILTIN, kNoExtraICState, StoreWithVector) \ 202 ASH(StoreIC_Normal, HANDLER, Code::STORE_IC) \ 203 ASH(StoreIC_Setter_ForDeopt, STORE_IC, StoreICState::kStrictModeState) \ 204 TFS(StoreIC_SlowSloppy, HANDLER, Code::STORE_IC, StoreWithVector) \ 205 TFS(StoreIC_SlowStrict, HANDLER, Code::STORE_IC, StoreWithVector) \ 206 \ 207 /* Built-in functions for Javascript */ \ 208 /* Special internal builtins */ \ 209 CPP(EmptyFunction) \ 210 CPP(Illegal) \ 211 CPP(RestrictedFunctionPropertiesThrower) \ 212 CPP(RestrictedStrictArgumentsPropertiesThrower) \ 213 CPP(UnsupportedThrower) \ 214 \ 215 /* Array */ \ 216 ASM(ArrayCode) \ 217 ASM(InternalArrayCode) \ 218 CPP(ArrayConcat) \ 219 /* ES6 section 22.1.2.2 Array.isArray */ \ 220 TFJ(ArrayIsArray, 1) \ 221 /* ES7 #sec-array.prototype.includes */ \ 222 TFJ(ArrayIncludes, 2) \ 223 TFJ(ArrayIndexOf, 2) \ 224 CPP(ArrayPop) \ 225 CPP(ArrayPush) \ 226 CPP(ArrayShift) \ 227 CPP(ArraySlice) \ 228 CPP(ArraySplice) \ 229 CPP(ArrayUnshift) \ 230 /* ES6 #sec-array.prototype.entries */ \ 231 TFJ(ArrayPrototypeEntries, 0) \ 232 /* ES6 #sec-array.prototype.keys */ \ 233 TFJ(ArrayPrototypeKeys, 0) \ 234 /* ES6 #sec-array.prototype.values */ \ 235 TFJ(ArrayPrototypeValues, 0) \ 236 /* ES6 #sec-%arrayiteratorprototype%.next */ \ 237 TFJ(ArrayIteratorPrototypeNext, 0) \ 238 \ 239 /* ArrayBuffer */ \ 240 CPP(ArrayBufferConstructor) \ 241 CPP(ArrayBufferConstructor_ConstructStub) \ 242 CPP(ArrayBufferPrototypeGetByteLength) \ 243 CPP(ArrayBufferIsView) \ 244 \ 245 /* Boolean */ \ 246 CPP(BooleanConstructor) \ 247 CPP(BooleanConstructor_ConstructStub) \ 248 /* ES6 section 19.3.3.2 Boolean.prototype.toString ( ) */ \ 249 TFJ(BooleanPrototypeToString, 0) \ 250 /* ES6 section 19.3.3.3 Boolean.prototype.valueOf ( ) */ \ 251 TFJ(BooleanPrototypeValueOf, 0) \ 252 \ 253 /* CallSite */ \ 254 CPP(CallSitePrototypeGetColumnNumber) \ 255 CPP(CallSitePrototypeGetEvalOrigin) \ 256 CPP(CallSitePrototypeGetFileName) \ 257 CPP(CallSitePrototypeGetFunction) \ 258 CPP(CallSitePrototypeGetFunctionName) \ 259 CPP(CallSitePrototypeGetLineNumber) \ 260 CPP(CallSitePrototypeGetMethodName) \ 261 CPP(CallSitePrototypeGetPosition) \ 262 CPP(CallSitePrototypeGetScriptNameOrSourceURL) \ 263 CPP(CallSitePrototypeGetThis) \ 264 CPP(CallSitePrototypeGetTypeName) \ 265 CPP(CallSitePrototypeIsConstructor) \ 266 CPP(CallSitePrototypeIsEval) \ 267 CPP(CallSitePrototypeIsNative) \ 268 CPP(CallSitePrototypeIsToplevel) \ 269 CPP(CallSitePrototypeToString) \ 270 \ 271 /* DataView */ \ 272 CPP(DataViewConstructor) \ 273 CPP(DataViewConstructor_ConstructStub) \ 274 CPP(DataViewPrototypeGetBuffer) \ 275 CPP(DataViewPrototypeGetByteLength) \ 276 CPP(DataViewPrototypeGetByteOffset) \ 277 CPP(DataViewPrototypeGetInt8) \ 278 CPP(DataViewPrototypeSetInt8) \ 279 CPP(DataViewPrototypeGetUint8) \ 280 CPP(DataViewPrototypeSetUint8) \ 281 CPP(DataViewPrototypeGetInt16) \ 282 CPP(DataViewPrototypeSetInt16) \ 283 CPP(DataViewPrototypeGetUint16) \ 284 CPP(DataViewPrototypeSetUint16) \ 285 CPP(DataViewPrototypeGetInt32) \ 286 CPP(DataViewPrototypeSetInt32) \ 287 CPP(DataViewPrototypeGetUint32) \ 288 CPP(DataViewPrototypeSetUint32) \ 289 CPP(DataViewPrototypeGetFloat32) \ 290 CPP(DataViewPrototypeSetFloat32) \ 291 CPP(DataViewPrototypeGetFloat64) \ 292 CPP(DataViewPrototypeSetFloat64) \ 293 \ 294 /* Date */ \ 295 CPP(DateConstructor) \ 296 CPP(DateConstructor_ConstructStub) \ 297 /* ES6 section 20.3.4.2 Date.prototype.getDate ( ) */ \ 298 TFJ(DatePrototypeGetDate, 0) \ 299 /* ES6 section 20.3.4.3 Date.prototype.getDay ( ) */ \ 300 TFJ(DatePrototypeGetDay, 0) \ 301 /* ES6 section 20.3.4.4 Date.prototype.getFullYear ( ) */ \ 302 TFJ(DatePrototypeGetFullYear, 0) \ 303 /* ES6 section 20.3.4.5 Date.prototype.getHours ( ) */ \ 304 TFJ(DatePrototypeGetHours, 0) \ 305 /* ES6 section 20.3.4.6 Date.prototype.getMilliseconds ( ) */ \ 306 TFJ(DatePrototypeGetMilliseconds, 0) \ 307 /* ES6 section 20.3.4.7 Date.prototype.getMinutes ( ) */ \ 308 TFJ(DatePrototypeGetMinutes, 0) \ 309 /* ES6 section 20.3.4.8 Date.prototype.getMonth */ \ 310 TFJ(DatePrototypeGetMonth, 0) \ 311 /* ES6 section 20.3.4.9 Date.prototype.getSeconds ( ) */ \ 312 TFJ(DatePrototypeGetSeconds, 0) \ 313 /* ES6 section 20.3.4.10 Date.prototype.getTime ( ) */ \ 314 TFJ(DatePrototypeGetTime, 0) \ 315 /* ES6 section 20.3.4.11 Date.prototype.getTimezoneOffset ( ) */ \ 316 TFJ(DatePrototypeGetTimezoneOffset, 0) \ 317 /* ES6 section 20.3.4.12 Date.prototype.getUTCDate ( ) */ \ 318 TFJ(DatePrototypeGetUTCDate, 0) \ 319 /* ES6 section 20.3.4.13 Date.prototype.getUTCDay ( ) */ \ 320 TFJ(DatePrototypeGetUTCDay, 0) \ 321 /* ES6 section 20.3.4.14 Date.prototype.getUTCFullYear ( ) */ \ 322 TFJ(DatePrototypeGetUTCFullYear, 0) \ 323 /* ES6 section 20.3.4.15 Date.prototype.getUTCHours ( ) */ \ 324 TFJ(DatePrototypeGetUTCHours, 0) \ 325 /* ES6 section 20.3.4.16 Date.prototype.getUTCMilliseconds ( ) */ \ 326 TFJ(DatePrototypeGetUTCMilliseconds, 0) \ 327 /* ES6 section 20.3.4.17 Date.prototype.getUTCMinutes ( ) */ \ 328 TFJ(DatePrototypeGetUTCMinutes, 0) \ 329 /* ES6 section 20.3.4.18 Date.prototype.getUTCMonth ( ) */ \ 330 TFJ(DatePrototypeGetUTCMonth, 0) \ 331 /* ES6 section 20.3.4.19 Date.prototype.getUTCSeconds ( ) */ \ 332 TFJ(DatePrototypeGetUTCSeconds, 0) \ 333 CPP(DatePrototypeGetYear) \ 334 CPP(DatePrototypeSetYear) \ 335 CPP(DateNow) \ 336 CPP(DateParse) \ 337 CPP(DatePrototypeSetDate) \ 338 CPP(DatePrototypeSetFullYear) \ 339 CPP(DatePrototypeSetHours) \ 340 CPP(DatePrototypeSetMilliseconds) \ 341 CPP(DatePrototypeSetMinutes) \ 342 CPP(DatePrototypeSetMonth) \ 343 CPP(DatePrototypeSetSeconds) \ 344 CPP(DatePrototypeSetTime) \ 345 CPP(DatePrototypeSetUTCDate) \ 346 CPP(DatePrototypeSetUTCFullYear) \ 347 CPP(DatePrototypeSetUTCHours) \ 348 CPP(DatePrototypeSetUTCMilliseconds) \ 349 CPP(DatePrototypeSetUTCMinutes) \ 350 CPP(DatePrototypeSetUTCMonth) \ 351 CPP(DatePrototypeSetUTCSeconds) \ 352 CPP(DatePrototypeToDateString) \ 353 CPP(DatePrototypeToISOString) \ 354 CPP(DatePrototypeToPrimitive) \ 355 CPP(DatePrototypeToUTCString) \ 356 CPP(DatePrototypeToString) \ 357 CPP(DatePrototypeToTimeString) \ 358 CPP(DatePrototypeValueOf) \ 359 CPP(DatePrototypeToJson) \ 360 CPP(DateUTC) \ 361 \ 362 /* Error */ \ 363 CPP(ErrorConstructor) \ 364 CPP(ErrorCaptureStackTrace) \ 365 CPP(ErrorPrototypeToString) \ 366 CPP(MakeError) \ 367 CPP(MakeRangeError) \ 368 CPP(MakeSyntaxError) \ 369 CPP(MakeTypeError) \ 370 CPP(MakeURIError) \ 371 \ 372 /* Function */ \ 373 CPP(FunctionConstructor) \ 374 ASM(FunctionPrototypeApply) \ 375 CPP(FunctionPrototypeBind) \ 376 ASM(FunctionPrototypeCall) \ 377 /* ES6 section 19.2.3.6 Function.prototype [ @@hasInstance ] ( V ) */ \ 378 TFJ(FunctionPrototypeHasInstance, 1) \ 379 CPP(FunctionPrototypeToString) \ 380 \ 381 /* Generator and Async */ \ 382 CPP(GeneratorFunctionConstructor) \ 383 /* ES6 section 25.3.1.2 Generator.prototype.next ( value ) */ \ 384 TFJ(GeneratorPrototypeNext, 1) \ 385 /* ES6 section 25.3.1.3 Generator.prototype.return ( value ) */ \ 386 TFJ(GeneratorPrototypeReturn, 1) \ 387 /* ES6 section 25.3.1.4 Generator.prototype.throw ( exception ) */ \ 388 TFJ(GeneratorPrototypeThrow, 1) \ 389 CPP(AsyncFunctionConstructor) \ 390 \ 391 /* Global object */ \ 392 CPP(GlobalDecodeURI) \ 393 CPP(GlobalDecodeURIComponent) \ 394 CPP(GlobalEncodeURI) \ 395 CPP(GlobalEncodeURIComponent) \ 396 CPP(GlobalEscape) \ 397 CPP(GlobalUnescape) \ 398 CPP(GlobalEval) \ 399 /* ES6 section 18.2.2 isFinite ( number ) */ \ 400 TFJ(GlobalIsFinite, 1) \ 401 /* ES6 section 18.2.3 isNaN ( number ) */ \ 402 TFJ(GlobalIsNaN, 1) \ 403 \ 404 /* ES6 #sec-%iteratorprototype%-@@iterator */ \ 405 TFJ(IteratorPrototypeIterator, 0) \ 406 \ 407 /* JSON */ \ 408 CPP(JsonParse) \ 409 CPP(JsonStringify) \ 410 \ 411 /* Math */ \ 412 /* ES6 section 20.2.2.1 Math.abs ( x ) */ \ 413 TFJ(MathAbs, 1) \ 414 /* ES6 section 20.2.2.2 Math.acos ( x ) */ \ 415 TFJ(MathAcos, 1) \ 416 /* ES6 section 20.2.2.3 Math.acosh ( x ) */ \ 417 TFJ(MathAcosh, 1) \ 418 /* ES6 section 20.2.2.4 Math.asin ( x ) */ \ 419 TFJ(MathAsin, 1) \ 420 /* ES6 section 20.2.2.5 Math.asinh ( x ) */ \ 421 TFJ(MathAsinh, 1) \ 422 /* ES6 section 20.2.2.6 Math.atan ( x ) */ \ 423 TFJ(MathAtan, 1) \ 424 /* ES6 section 20.2.2.7 Math.atanh ( x ) */ \ 425 TFJ(MathAtanh, 1) \ 426 /* ES6 section 20.2.2.8 Math.atan2 ( y, x ) */ \ 427 TFJ(MathAtan2, 2) \ 428 /* ES6 section 20.2.2.9 Math.cbrt ( x ) */ \ 429 TFJ(MathCbrt, 1) \ 430 /* ES6 section 20.2.2.10 Math.ceil ( x ) */ \ 431 TFJ(MathCeil, 1) \ 432 /* ES6 section 20.2.2.11 Math.clz32 ( x ) */ \ 433 TFJ(MathClz32, 1) \ 434 /* ES6 section 20.2.2.12 Math.cos ( x ) */ \ 435 TFJ(MathCos, 1) \ 436 /* ES6 section 20.2.2.13 Math.cosh ( x ) */ \ 437 TFJ(MathCosh, 1) \ 438 /* ES6 section 20.2.2.14 Math.exp ( x ) */ \ 439 TFJ(MathExp, 1) \ 440 /* ES6 section 20.2.2.15 Math.expm1 ( x ) */ \ 441 TFJ(MathExpm1, 1) \ 442 /* ES6 section 20.2.2.16 Math.floor ( x ) */ \ 443 TFJ(MathFloor, 1) \ 444 /* ES6 section 20.2.2.17 Math.fround ( x ) */ \ 445 TFJ(MathFround, 1) \ 446 /* ES6 section 20.2.2.18 Math.hypot ( value1, value2, ...values ) */ \ 447 CPP(MathHypot) \ 448 /* ES6 section 20.2.2.19 Math.imul ( x, y ) */ \ 449 TFJ(MathImul, 2) \ 450 /* ES6 section 20.2.2.20 Math.log ( x ) */ \ 451 TFJ(MathLog, 1) \ 452 /* ES6 section 20.2.2.21 Math.log1p ( x ) */ \ 453 TFJ(MathLog1p, 1) \ 454 /* ES6 section 20.2.2.22 Math.log10 ( x ) */ \ 455 TFJ(MathLog10, 1) \ 456 /* ES6 section 20.2.2.23 Math.log2 ( x ) */ \ 457 TFJ(MathLog2, 1) \ 458 /* ES6 section 20.2.2.24 Math.max ( value1, value2 , ...values ) */ \ 459 ASM(MathMax) \ 460 /* ES6 section 20.2.2.25 Math.min ( value1, value2 , ...values ) */ \ 461 ASM(MathMin) \ 462 /* ES6 section 20.2.2.26 Math.pow ( x, y ) */ \ 463 TFJ(MathPow, 2) \ 464 /* ES6 section 20.2.2.27 Math.random */ \ 465 TFJ(MathRandom, 0) \ 466 /* ES6 section 20.2.2.28 Math.round ( x ) */ \ 467 TFJ(MathRound, 1) \ 468 /* ES6 section 20.2.2.29 Math.sign ( x ) */ \ 469 TFJ(MathSign, 1) \ 470 /* ES6 section 20.2.2.30 Math.sin ( x ) */ \ 471 TFJ(MathSin, 1) \ 472 /* ES6 section 20.2.2.31 Math.sinh ( x ) */ \ 473 TFJ(MathSinh, 1) \ 474 /* ES6 section 20.2.2.32 Math.sqrt ( x ) */ \ 475 TFJ(MathTan, 1) \ 476 /* ES6 section 20.2.2.33 Math.tan ( x ) */ \ 477 TFJ(MathTanh, 1) \ 478 /* ES6 section 20.2.2.34 Math.tanh ( x ) */ \ 479 TFJ(MathSqrt, 1) \ 480 /* ES6 section 20.2.2.35 Math.trunc ( x ) */ \ 481 TFJ(MathTrunc, 1) \ 482 \ 483 /* Number */ \ 484 /* ES6 section 20.1.1.1 Number ( [ value ] ) for the [[Call]] case */ \ 485 ASM(NumberConstructor) \ 486 /* ES6 section 20.1.1.1 Number ( [ value ] ) for the [[Construct]] case */ \ 487 ASM(NumberConstructor_ConstructStub) \ 488 /* ES6 section 20.1.2.2 Number.isFinite ( number ) */ \ 489 TFJ(NumberIsFinite, 1) \ 490 /* ES6 section 20.1.2.3 Number.isInteger ( number ) */ \ 491 TFJ(NumberIsInteger, 1) \ 492 /* ES6 section 20.1.2.4 Number.isNaN ( number ) */ \ 493 TFJ(NumberIsNaN, 1) \ 494 /* ES6 section 20.1.2.5 Number.isSafeInteger ( number ) */ \ 495 TFJ(NumberIsSafeInteger, 1) \ 496 /* ES6 section 20.1.2.12 Number.parseFloat ( string ) */ \ 497 TFJ(NumberParseFloat, 1) \ 498 /* ES6 section 20.1.2.13 Number.parseInt ( string, radix ) */ \ 499 TFJ(NumberParseInt, 2) \ 500 CPP(NumberPrototypeToExponential) \ 501 CPP(NumberPrototypeToFixed) \ 502 CPP(NumberPrototypeToLocaleString) \ 503 CPP(NumberPrototypeToPrecision) \ 504 CPP(NumberPrototypeToString) \ 505 /* ES6 section 20.1.3.7 Number.prototype.valueOf ( ) */ \ 506 TFJ(NumberPrototypeValueOf, 0) \ 507 TFS(Add, BUILTIN, kNoExtraICState, BinaryOp) \ 508 TFS(Subtract, BUILTIN, kNoExtraICState, BinaryOp) \ 509 TFS(Multiply, BUILTIN, kNoExtraICState, BinaryOp) \ 510 TFS(Divide, BUILTIN, kNoExtraICState, BinaryOp) \ 511 TFS(Modulus, BUILTIN, kNoExtraICState, BinaryOp) \ 512 TFS(BitwiseAnd, BUILTIN, kNoExtraICState, BinaryOp) \ 513 TFS(BitwiseOr, BUILTIN, kNoExtraICState, BinaryOp) \ 514 TFS(BitwiseXor, BUILTIN, kNoExtraICState, BinaryOp) \ 515 TFS(ShiftLeft, BUILTIN, kNoExtraICState, BinaryOp) \ 516 TFS(ShiftRight, BUILTIN, kNoExtraICState, BinaryOp) \ 517 TFS(ShiftRightLogical, BUILTIN, kNoExtraICState, BinaryOp) \ 518 TFS(LessThan, BUILTIN, kNoExtraICState, Compare) \ 519 TFS(LessThanOrEqual, BUILTIN, kNoExtraICState, Compare) \ 520 TFS(GreaterThan, BUILTIN, kNoExtraICState, Compare) \ 521 TFS(GreaterThanOrEqual, BUILTIN, kNoExtraICState, Compare) \ 522 TFS(Equal, BUILTIN, kNoExtraICState, Compare) \ 523 TFS(NotEqual, BUILTIN, kNoExtraICState, Compare) \ 524 TFS(StrictEqual, BUILTIN, kNoExtraICState, Compare) \ 525 TFS(StrictNotEqual, BUILTIN, kNoExtraICState, Compare) \ 526 \ 527 /* Object */ \ 528 CPP(ObjectAssign) \ 529 TFJ(ObjectCreate, 2) \ 530 CPP(ObjectDefineGetter) \ 531 CPP(ObjectDefineProperties) \ 532 CPP(ObjectDefineProperty) \ 533 CPP(ObjectDefineSetter) \ 534 CPP(ObjectEntries) \ 535 CPP(ObjectFreeze) \ 536 CPP(ObjectGetOwnPropertyDescriptor) \ 537 CPP(ObjectGetOwnPropertyDescriptors) \ 538 CPP(ObjectGetOwnPropertyNames) \ 539 CPP(ObjectGetOwnPropertySymbols) \ 540 CPP(ObjectGetPrototypeOf) \ 541 CPP(ObjectSetPrototypeOf) \ 542 /* ES6 section 19.1.3.2 Object.prototype.hasOwnProperty */ \ 543 TFJ(ObjectHasOwnProperty, 1) \ 544 CPP(ObjectIs) \ 545 CPP(ObjectIsExtensible) \ 546 CPP(ObjectIsFrozen) \ 547 CPP(ObjectIsSealed) \ 548 CPP(ObjectKeys) \ 549 CPP(ObjectLookupGetter) \ 550 CPP(ObjectLookupSetter) \ 551 CPP(ObjectPreventExtensions) \ 552 /* ES6 section 19.1.3.6 Object.prototype.toString () */ \ 553 TFJ(ObjectProtoToString, 0) \ 554 CPP(ObjectPrototypePropertyIsEnumerable) \ 555 CPP(ObjectPrototypeGetProto) \ 556 CPP(ObjectPrototypeSetProto) \ 557 CPP(ObjectSeal) \ 558 CPP(ObjectValues) \ 559 \ 560 TFS(HasProperty, BUILTIN, kNoExtraICState, HasProperty) \ 561 TFS(InstanceOf, BUILTIN, kNoExtraICState, Compare) \ 562 TFS(OrdinaryHasInstance, BUILTIN, kNoExtraICState, Compare) \ 563 TFS(ForInFilter, BUILTIN, kNoExtraICState, ForInFilter) \ 564 \ 565 /* Promise */ \ 566 CPP(CreateResolvingFunctions) \ 567 CPP(PromiseResolveClosure) \ 568 CPP(PromiseRejectClosure) \ 569 \ 570 /* Proxy */ \ 571 CPP(ProxyConstructor) \ 572 CPP(ProxyConstructor_ConstructStub) \ 573 \ 574 /* Reflect */ \ 575 ASM(ReflectApply) \ 576 ASM(ReflectConstruct) \ 577 CPP(ReflectDefineProperty) \ 578 CPP(ReflectDeleteProperty) \ 579 CPP(ReflectGet) \ 580 CPP(ReflectGetOwnPropertyDescriptor) \ 581 CPP(ReflectGetPrototypeOf) \ 582 CPP(ReflectHas) \ 583 CPP(ReflectIsExtensible) \ 584 CPP(ReflectOwnKeys) \ 585 CPP(ReflectPreventExtensions) \ 586 CPP(ReflectSet) \ 587 CPP(ReflectSetPrototypeOf) \ 588 \ 589 /* RegExp */ \ 590 CPP(RegExpCapture1Getter) \ 591 CPP(RegExpCapture2Getter) \ 592 CPP(RegExpCapture3Getter) \ 593 CPP(RegExpCapture4Getter) \ 594 CPP(RegExpCapture5Getter) \ 595 CPP(RegExpCapture6Getter) \ 596 CPP(RegExpCapture7Getter) \ 597 CPP(RegExpCapture8Getter) \ 598 CPP(RegExpCapture9Getter) \ 599 CPP(RegExpConstructor) \ 600 TFJ(RegExpInternalMatch, 2) \ 601 CPP(RegExpInputGetter) \ 602 CPP(RegExpInputSetter) \ 603 CPP(RegExpLastMatchGetter) \ 604 CPP(RegExpLastParenGetter) \ 605 CPP(RegExpLeftContextGetter) \ 606 CPP(RegExpPrototypeCompile) \ 607 TFJ(RegExpPrototypeExec, 1) \ 608 TFJ(RegExpPrototypeFlagsGetter, 0) \ 609 TFJ(RegExpPrototypeGlobalGetter, 0) \ 610 TFJ(RegExpPrototypeIgnoreCaseGetter, 0) \ 611 CPP(RegExpPrototypeMatch) \ 612 TFJ(RegExpPrototypeMultilineGetter, 0) \ 613 TFJ(RegExpPrototypeReplace, 2) \ 614 TFJ(RegExpPrototypeSearch, 1) \ 615 CPP(RegExpPrototypeSourceGetter) \ 616 CPP(RegExpPrototypeSpeciesGetter) \ 617 CPP(RegExpPrototypeSplit) \ 618 TFJ(RegExpPrototypeStickyGetter, 0) \ 619 TFJ(RegExpPrototypeTest, 1) \ 620 CPP(RegExpPrototypeToString) \ 621 TFJ(RegExpPrototypeUnicodeGetter, 0) \ 622 CPP(RegExpRightContextGetter) \ 623 \ 624 /* SharedArrayBuffer */ \ 625 CPP(SharedArrayBufferPrototypeGetByteLength) \ 626 TFJ(AtomicsLoad, 2) \ 627 TFJ(AtomicsStore, 3) \ 628 \ 629 /* String */ \ 630 ASM(StringConstructor) \ 631 ASM(StringConstructor_ConstructStub) \ 632 CPP(StringFromCodePoint) \ 633 /* ES6 section 21.1.2.1 String.fromCharCode ( ...codeUnits ) */ \ 634 TFJ(StringFromCharCode, SharedFunctionInfo::kDontAdaptArgumentsSentinel) \ 635 /* ES6 section 21.1.3.1 String.prototype.charAt ( pos ) */ \ 636 TFJ(StringPrototypeCharAt, 1) \ 637 /* ES6 section 21.1.3.2 String.prototype.charCodeAt ( pos ) */ \ 638 TFJ(StringPrototypeCharCodeAt, 1) \ 639 /* ES6 section 21.1.3.6 */ \ 640 /* String.prototype.endsWith ( searchString [ , endPosition ] ) */ \ 641 CPP(StringPrototypeEndsWith) \ 642 /* ES6 section 21.1.3.7 */ \ 643 /* String.prototype.includes ( searchString [ , position ] ) */ \ 644 CPP(StringPrototypeIncludes) \ 645 /* ES6 section 21.1.3.8 */ \ 646 /* String.prototype.indexOf ( searchString [ , position ] ) */ \ 647 CPP(StringPrototypeIndexOf) \ 648 /* ES6 section 21.1.3.9 */ \ 649 /* String.prototype.lastIndexOf ( searchString [ , position ] ) */ \ 650 CPP(StringPrototypeLastIndexOf) \ 651 /* ES6 section 21.1.3.10 String.prototype.localeCompare ( that ) */ \ 652 CPP(StringPrototypeLocaleCompare) \ 653 /* ES6 section 21.1.3.12 String.prototype.normalize ( [form] ) */ \ 654 CPP(StringPrototypeNormalize) \ 655 /* ES6 section B.2.3.1 String.prototype.substr ( start, length ) */ \ 656 TFJ(StringPrototypeSubstr, 2) \ 657 /* ES6 section 21.1.3.19 String.prototype.substring ( start, end ) */ \ 658 TFJ(StringPrototypeSubstring, 2) \ 659 /* ES6 section 21.1.3.20 */ \ 660 /* String.prototype.startsWith ( searchString [ , position ] ) */ \ 661 CPP(StringPrototypeStartsWith) \ 662 /* ES6 section 21.1.3.25 String.prototype.toString () */ \ 663 TFJ(StringPrototypeToString, 0) \ 664 CPP(StringPrototypeTrim) \ 665 CPP(StringPrototypeTrimLeft) \ 666 CPP(StringPrototypeTrimRight) \ 667 /* ES6 section 21.1.3.28 String.prototype.valueOf () */ \ 668 TFJ(StringPrototypeValueOf, 0) \ 669 /* ES6 #sec-string.prototype-@@iterator */ \ 670 TFJ(StringPrototypeIterator, 0) \ 671 \ 672 /* StringIterator */ \ 673 TFJ(StringIteratorPrototypeNext, 0) \ 674 \ 675 /* Symbol */ \ 676 CPP(SymbolConstructor) \ 677 CPP(SymbolConstructor_ConstructStub) \ 678 /* ES6 section 19.4.3.4 Symbol.prototype [ @@toPrimitive ] ( hint ) */ \ 679 TFJ(SymbolPrototypeToPrimitive, 1) \ 680 /* ES6 section 19.4.3.2 Symbol.prototype.toString ( ) */ \ 681 TFJ(SymbolPrototypeToString, 0) \ 682 /* ES6 section 19.4.3.3 Symbol.prototype.valueOf ( ) */ \ 683 TFJ(SymbolPrototypeValueOf, 0) \ 684 \ 685 /* TypedArray */ \ 686 CPP(TypedArrayPrototypeBuffer) \ 687 /* ES6 section 22.2.3.2 get %TypedArray%.prototype.byteLength */ \ 688 TFJ(TypedArrayPrototypeByteLength, 0) \ 689 /* ES6 section 22.2.3.3 get %TypedArray%.prototype.byteOffset */ \ 690 TFJ(TypedArrayPrototypeByteOffset, 0) \ 691 /* ES6 section 22.2.3.18 get %TypedArray%.prototype.length */ \ 692 TFJ(TypedArrayPrototypeLength, 0) \ 693 /* ES6 #sec-%typedarray%.prototype.entries */ \ 694 TFJ(TypedArrayPrototypeEntries, 0) \ 695 /* ES6 #sec-%typedarray%.prototype.keys */ \ 696 TFJ(TypedArrayPrototypeKeys, 0) \ 697 /* ES6 #sec-%typedarray%.prototype.values */ \ 698 TFJ(TypedArrayPrototypeValues, 0) \ 699 \ 700 CPP(ModuleNamespaceIterator) \ 701 CPP(FixedArrayIteratorNext) 702 703 #define IGNORE_BUILTIN(...) 704 705 #define BUILTIN_LIST_ALL(V) BUILTIN_LIST(V, V, V, V, V, V, V) 706 707 #define BUILTIN_LIST_C(V) \ 708 BUILTIN_LIST(V, V, IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN, \ 709 IGNORE_BUILTIN, IGNORE_BUILTIN) 710 711 #define BUILTIN_LIST_A(V) \ 712 BUILTIN_LIST(IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN, \ 713 V, V, V) 714 715 #define BUILTIN_LIST_DBG(V) \ 716 BUILTIN_LIST(IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN, \ 717 IGNORE_BUILTIN, IGNORE_BUILTIN, V) 718 719 // Forward declarations. 720 class CodeStubAssembler; 721 class ObjectVisitor; 722 723 class Builtins { 724 public: 725 ~Builtins(); 726 727 // Generate all builtin code objects. Should be called once during 728 // isolate initialization. 729 void SetUp(Isolate* isolate, bool create_heap_objects); 730 void TearDown(); 731 732 // Garbage collection support. 733 void IterateBuiltins(ObjectVisitor* v); 734 735 // Disassembler support. 736 const char* Lookup(byte* pc); 737 738 enum Name { 739 #define DEF_ENUM(Name, ...) k##Name, 740 BUILTIN_LIST_ALL(DEF_ENUM) 741 #undef DEF_ENUM 742 builtin_count 743 }; 744 745 #define DECLARE_BUILTIN_ACCESSOR(Name, ...) \ 746 V8_EXPORT_PRIVATE Handle<Code> Name(); 747 BUILTIN_LIST_ALL(DECLARE_BUILTIN_ACCESSOR) 748 #undef DECLARE_BUILTIN_ACCESSOR 749 750 // Convenience wrappers. 751 Handle<Code> CallFunction( 752 ConvertReceiverMode = ConvertReceiverMode::kAny, 753 TailCallMode tail_call_mode = TailCallMode::kDisallow); 754 Handle<Code> Call(ConvertReceiverMode = ConvertReceiverMode::kAny, 755 TailCallMode tail_call_mode = TailCallMode::kDisallow); 756 Handle<Code> CallBoundFunction(TailCallMode tail_call_mode); 757 Handle<Code> NonPrimitiveToPrimitive( 758 ToPrimitiveHint hint = ToPrimitiveHint::kDefault); 759 Handle<Code> OrdinaryToPrimitive(OrdinaryToPrimitiveHint hint); 760 Handle<Code> InterpreterPushArgsAndCall( 761 TailCallMode tail_call_mode, 762 CallableType function_type = CallableType::kAny); 763 Handle<Code> InterpreterPushArgsAndConstruct(CallableType function_type); 764 builtin(Name name)765 Code* builtin(Name name) { 766 // Code::cast cannot be used here since we access builtins 767 // during the marking phase of mark sweep. See IC::Clear. 768 return reinterpret_cast<Code*>(builtins_[name]); 769 } 770 builtin_address(Name name)771 Address builtin_address(Name name) { 772 return reinterpret_cast<Address>(&builtins_[name]); 773 } 774 775 static const char* name(int index); 776 777 // Returns the C++ entry point for builtins implemented in C++, and the null 778 // Address otherwise. 779 static Address CppEntryOf(int index); 780 781 static bool IsCpp(int index); 782 static bool IsApi(int index); 783 static bool HasCppImplementation(int index); 784 is_initialized()785 bool is_initialized() const { return initialized_; } 786 787 MUST_USE_RESULT static MaybeHandle<Object> InvokeApiFunction( 788 Isolate* isolate, bool is_construct, Handle<HeapObject> function, 789 Handle<Object> receiver, int argc, Handle<Object> args[], 790 Handle<HeapObject> new_target); 791 792 enum ExitFrameType { EXIT, BUILTIN_EXIT }; 793 794 static void Generate_Adaptor(MacroAssembler* masm, Address builtin_address, 795 ExitFrameType exit_frame_type); 796 797 static bool AllowDynamicFunction(Isolate* isolate, Handle<JSFunction> target, 798 Handle<JSObject> target_global_proxy); 799 800 private: 801 Builtins(); 802 803 static void Generate_CallFunction(MacroAssembler* masm, 804 ConvertReceiverMode mode, 805 TailCallMode tail_call_mode); 806 807 static void Generate_CallBoundFunctionImpl(MacroAssembler* masm, 808 TailCallMode tail_call_mode); 809 810 static void Generate_Call(MacroAssembler* masm, ConvertReceiverMode mode, 811 TailCallMode tail_call_mode); 812 813 static void Generate_InterpreterPushArgsAndCallImpl( 814 MacroAssembler* masm, TailCallMode tail_call_mode, 815 CallableType function_type); 816 817 static void Generate_InterpreterPushArgsAndConstructImpl( 818 MacroAssembler* masm, CallableType function_type); 819 820 static void Generate_DatePrototype_GetField(CodeStubAssembler* masm, 821 int field_index); 822 823 enum class MathMaxMinKind { kMax, kMin }; 824 static void Generate_MathMaxMin(MacroAssembler* masm, MathMaxMinKind kind); 825 826 #define DECLARE_ASM(Name, ...) \ 827 static void Generate_##Name(MacroAssembler* masm); 828 #define DECLARE_TF(Name, ...) \ 829 static void Generate_##Name(CodeStubAssembler* csasm); 830 831 BUILTIN_LIST(IGNORE_BUILTIN, IGNORE_BUILTIN, DECLARE_TF, DECLARE_TF, 832 DECLARE_ASM, DECLARE_ASM, DECLARE_ASM) 833 834 #undef DECLARE_ASM 835 #undef DECLARE_TF 836 837 // Note: These are always Code objects, but to conform with 838 // IterateBuiltins() above which assumes Object**'s for the callback 839 // function f, we use an Object* array here. 840 Object* builtins_[builtin_count]; 841 bool initialized_; 842 843 friend class Isolate; 844 845 DISALLOW_COPY_AND_ASSIGN(Builtins); 846 }; 847 848 } // namespace internal 849 } // namespace v8 850 851 #endif // V8_BUILTINS_BUILTINS_H_ 852