Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // ------------------------------------------------------------------- | 5 // ------------------------------------------------------------------- |
| 6 | 6 |
| 7 (function(global, utils) { | 7 (function(global, utils) { |
| 8 | 8 |
| 9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
| 10 | 10 |
| 11 // ------------------------------------------------------------------- | 11 // ------------------------------------------------------------------- |
| 12 // Imports | 12 // Imports |
| 13 | 13 |
| 14 var ArrayJoin; | 14 var ArrayJoin; |
| 15 var Bool16x8ToString; | 15 var Bool16x8ToString; |
| 16 var Bool32x4ToString; | 16 var Bool32x4ToString; |
| 17 var Bool8x16ToString; | 17 var Bool8x16ToString; |
| 18 var CallSite; | |
|
Yang
2016/07/22 08:16:17
Let's use utils.ImportNow here, and add the toStri
jgruber
2016/07/22 09:49:10
Done.
| |
| 18 var callSiteConstructorSymbol = | 19 var callSiteConstructorSymbol = |
| 19 utils.ImportNow("call_site_constructor_symbol"); | 20 utils.ImportNow("call_site_constructor_symbol"); |
| 20 var callSiteReceiverSymbol = | 21 var callSiteReceiverSymbol = |
| 21 utils.ImportNow("call_site_receiver_symbol"); | 22 utils.ImportNow("call_site_receiver_symbol"); |
| 22 var callSiteFunctionSymbol = | 23 var callSiteFunctionSymbol = |
| 23 utils.ImportNow("call_site_function_symbol"); | 24 utils.ImportNow("call_site_function_symbol"); |
| 24 var callSitePositionSymbol = | 25 var callSitePositionSymbol = |
| 25 utils.ImportNow("call_site_position_symbol"); | 26 utils.ImportNow("call_site_position_symbol"); |
| 26 var callSiteStrictSymbol = | 27 var callSiteStrictSymbol = |
| 27 utils.ImportNow("call_site_strict_symbol"); | 28 utils.ImportNow("call_site_strict_symbol"); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 51 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); | 52 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); |
| 52 var Uint16x8ToString; | 53 var Uint16x8ToString; |
| 53 var Uint32x4ToString; | 54 var Uint32x4ToString; |
| 54 var Uint8x16ToString; | 55 var Uint8x16ToString; |
| 55 | 56 |
| 56 utils.Import(function(from) { | 57 utils.Import(function(from) { |
| 57 ArrayJoin = from.ArrayJoin; | 58 ArrayJoin = from.ArrayJoin; |
| 58 Bool16x8ToString = from.Bool16x8ToString; | 59 Bool16x8ToString = from.Bool16x8ToString; |
| 59 Bool32x4ToString = from.Bool32x4ToString; | 60 Bool32x4ToString = from.Bool32x4ToString; |
| 60 Bool8x16ToString = from.Bool8x16ToString; | 61 Bool8x16ToString = from.Bool8x16ToString; |
| 62 CallSite = from.CallSite; | |
| 61 Float32x4ToString = from.Float32x4ToString; | 63 Float32x4ToString = from.Float32x4ToString; |
| 62 Int16x8ToString = from.Int16x8ToString; | 64 Int16x8ToString = from.Int16x8ToString; |
| 63 Int32x4ToString = from.Int32x4ToString; | 65 Int32x4ToString = from.Int32x4ToString; |
| 64 Int8x16ToString = from.Int8x16ToString; | 66 Int8x16ToString = from.Int8x16ToString; |
| 65 ObjectHasOwnProperty = from.ObjectHasOwnProperty; | 67 ObjectHasOwnProperty = from.ObjectHasOwnProperty; |
| 66 StringIndexOf = from.StringIndexOf; | 68 StringIndexOf = from.StringIndexOf; |
| 67 Uint16x8ToString = from.Uint16x8ToString; | 69 Uint16x8ToString = from.Uint16x8ToString; |
| 68 Uint32x4ToString = from.Uint32x4ToString; | 70 Uint32x4ToString = from.Uint32x4ToString; |
| 69 Uint8x16ToString = from.Uint8x16ToString; | 71 Uint8x16ToString = from.Uint8x16ToString; |
| 72 | |
| 73 %AddNamedProperty(CallSite.prototype, "toString", CallSiteToString, | |
| 74 DONT_ENUM | DONT_DELETE | READ_ONLY); | |
| 75 %SetNativeFlag(CallSiteToString); | |
| 70 }); | 76 }); |
| 71 | 77 |
| 72 // ------------------------------------------------------------------- | 78 // ------------------------------------------------------------------- |
| 73 | 79 |
| 74 | 80 |
| 75 | 81 |
| 76 function NoSideEffectsObjectToString() { | 82 function NoSideEffectsObjectToString() { |
| 77 if (IS_UNDEFINED(this)) return "[object Undefined]"; | 83 if (IS_UNDEFINED(this)) return "[object Undefined]"; |
| 78 if (IS_NULL(this)) return "[object Null]"; | 84 if (IS_NULL(this)) return "[object Null]"; |
| 79 var O = TO_OBJECT(this); | 85 var O = TO_OBJECT(this); |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 ); | 270 ); |
| 265 | 271 |
| 266 | 272 |
| 267 function GetStackTraceLine(recv, fun, pos, isGlobal) { | 273 function GetStackTraceLine(recv, fun, pos, isGlobal) { |
| 268 return new CallSite(recv, fun, pos, false).toString(); | 274 return new CallSite(recv, fun, pos, false).toString(); |
| 269 } | 275 } |
| 270 | 276 |
| 271 // ---------------------------------------------------------------------------- | 277 // ---------------------------------------------------------------------------- |
| 272 // Error implementation | 278 // Error implementation |
| 273 | 279 |
| 274 function CallSite(receiver, fun, pos, strict_mode) { | |
| 275 // For wasm frames, receiver is the wasm object and fun is the function index | |
| 276 // instead of an actual function. | |
| 277 if (!IS_FUNCTION(fun) && !%IsWasmObject(receiver)) { | |
| 278 throw MakeTypeError(kCallSiteExpectsFunction, typeof receiver, typeof fun); | |
| 279 } | |
| 280 | |
| 281 if (IS_UNDEFINED(new.target)) { | |
| 282 return new CallSite(receiver, fun, pos, strict_mode); | |
| 283 } | |
| 284 | |
| 285 if (IS_FUNCTION(fun)) { | |
| 286 SET_PRIVATE(this, callSiteReceiverSymbol, receiver); | |
| 287 SET_PRIVATE(this, callSiteFunctionSymbol, fun); | |
| 288 } else { | |
| 289 SET_PRIVATE(this, callSiteWasmObjectSymbol, receiver); | |
| 290 SET_PRIVATE(this, callSiteWasmFunctionIndexSymbol, TO_UINT32(fun)); | |
| 291 } | |
| 292 SET_PRIVATE(this, callSitePositionSymbol, TO_INT32(pos)); | |
| 293 SET_PRIVATE(this, callSiteStrictSymbol, TO_BOOLEAN(strict_mode)); | |
| 294 } | |
| 295 | |
| 296 function CheckCallSite(obj, name) { | |
| 297 if (!IS_RECEIVER(obj) || !HAS_PRIVATE(obj, callSitePositionSymbol)) { | |
| 298 throw MakeTypeError(kCallSiteMethod, name); | |
| 299 } | |
| 300 } | |
| 301 | |
| 302 function CallSiteGetThis() { | |
| 303 CheckCallSite(this, "getThis"); | |
| 304 if (GET_PRIVATE(this, callSiteStrictSymbol)) { | |
| 305 return UNDEFINED; | |
| 306 } | |
| 307 var recv = GET_PRIVATE(this, callSiteReceiverSymbol); | |
| 308 return (recv == callSiteConstructorSymbol) ? UNDEFINED : recv; | |
| 309 } | |
| 310 | |
| 311 function CallSiteGetFunction() { | |
| 312 CheckCallSite(this, "getFunction"); | |
| 313 return GET_PRIVATE(this, callSiteStrictSymbol) | |
| 314 ? UNDEFINED : GET_PRIVATE(this, callSiteFunctionSymbol); | |
| 315 } | |
| 316 | |
| 317 function CallSiteGetPosition() { | |
| 318 CheckCallSite(this, "getPosition"); | |
| 319 return GET_PRIVATE(this, callSitePositionSymbol); | |
| 320 } | |
| 321 | |
| 322 function CallSiteGetTypeName() { | |
| 323 CheckCallSite(this, "getTypeName"); | |
| 324 return GetTypeName(GET_PRIVATE(this, callSiteReceiverSymbol), false); | |
| 325 } | |
| 326 | |
| 327 function CallSiteIsToplevel() { | |
| 328 CheckCallSite(this, "isTopLevel"); | |
| 329 return %CallSiteIsToplevelRT(this); | |
| 330 } | |
| 331 | |
| 332 function CallSiteIsEval() { | |
| 333 CheckCallSite(this, "isEval"); | |
| 334 return %CallSiteIsEvalRT(this); | |
| 335 } | |
| 336 | |
| 337 function CallSiteGetEvalOrigin() { | |
| 338 CheckCallSite(this, "getEvalOrigin"); | |
| 339 var script = %FunctionGetScript(GET_PRIVATE(this, callSiteFunctionSymbol)); | |
| 340 return FormatEvalOrigin(script); | |
| 341 } | |
| 342 | |
| 343 function CallSiteGetScriptNameOrSourceURL() { | |
| 344 CheckCallSite(this, "getScriptNameOrSourceURL"); | |
| 345 return %CallSiteGetScriptNameOrSourceUrlRT(this); | |
| 346 } | |
| 347 | |
| 348 function CallSiteGetFunctionName() { | |
| 349 // See if the function knows its own name | |
| 350 CheckCallSite(this, "getFunctionName"); | |
| 351 return %CallSiteGetFunctionNameRT(this); | |
| 352 } | |
| 353 | |
| 354 function CallSiteGetMethodName() { | |
| 355 // See if we can find a unique property on the receiver that holds | |
| 356 // this function. | |
| 357 CheckCallSite(this, "getMethodName"); | |
| 358 return %CallSiteGetMethodNameRT(this); | |
| 359 } | |
| 360 | |
| 361 function CallSiteGetFileName() { | |
| 362 CheckCallSite(this, "getFileName"); | |
| 363 return %CallSiteGetFileNameRT(this); | |
| 364 } | |
| 365 | |
| 366 function CallSiteGetLineNumber() { | |
| 367 if (HAS_PRIVATE(this, callSiteWasmObjectSymbol)) { | |
| 368 return GET_PRIVATE(this, callSiteWasmFunctionIndexSymbol); | |
| 369 } | |
| 370 CheckCallSite(this, "getLineNumber"); | |
| 371 return %CallSiteGetLineNumberRT(this); | |
| 372 } | |
| 373 | |
| 374 function CallSiteGetColumnNumber() { | |
| 375 CheckCallSite(this, "getColumnNumber"); | |
| 376 return %CallSiteGetColumnNumberRT(this); | |
| 377 } | |
| 378 | |
| 379 function CallSiteIsNative() { | |
| 380 CheckCallSite(this, "isNative"); | |
| 381 return %CallSiteIsNativeRT(this); | |
| 382 } | |
| 383 | |
| 384 function CallSiteIsConstructor() { | |
| 385 CheckCallSite(this, "isConstructor"); | |
| 386 return %CallSiteIsConstructorRT(this); | |
| 387 } | |
| 388 | |
| 389 function CallSiteToString() { | 280 function CallSiteToString() { |
| 390 if (HAS_PRIVATE(this, callSiteWasmObjectSymbol)) { | 281 if (HAS_PRIVATE(this, callSiteWasmObjectSymbol)) { |
| 391 var funName = this.getFunctionName(); | 282 var funName = this.getFunctionName(); |
| 392 var funcIndex = GET_PRIVATE(this, callSiteWasmFunctionIndexSymbol); | 283 var funcIndex = GET_PRIVATE(this, callSiteWasmFunctionIndexSymbol); |
| 393 var pos = this.getPosition(); | 284 var pos = this.getPosition(); |
| 394 if (IS_NULL(funName)) funName = "<WASM UNNAMED>"; | 285 if (IS_NULL(funName)) funName = "<WASM UNNAMED>"; |
| 395 return funName + " (<WASM>[" + funcIndex + "]+" + pos + ")"; | 286 return funName + " (<WASM>[" + funcIndex + "]+" + pos + ")"; |
| 396 } | 287 } |
| 397 | 288 |
| 398 var fileName; | 289 var fileName; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 452 } else { | 343 } else { |
| 453 line += fileLocation; | 344 line += fileLocation; |
| 454 addSuffix = false; | 345 addSuffix = false; |
| 455 } | 346 } |
| 456 if (addSuffix) { | 347 if (addSuffix) { |
| 457 line += " (" + fileLocation + ")"; | 348 line += " (" + fileLocation + ")"; |
| 458 } | 349 } |
| 459 return line; | 350 return line; |
| 460 } | 351 } |
| 461 | 352 |
| 462 utils.SetUpLockedPrototype(CallSite, ["receiver", "fun", "pos"], [ | |
| 463 "getThis", CallSiteGetThis, | |
| 464 "getTypeName", CallSiteGetTypeName, | |
| 465 "isToplevel", CallSiteIsToplevel, | |
| 466 "isEval", CallSiteIsEval, | |
| 467 "getEvalOrigin", CallSiteGetEvalOrigin, | |
| 468 "getScriptNameOrSourceURL", CallSiteGetScriptNameOrSourceURL, | |
| 469 "getFunction", CallSiteGetFunction, | |
| 470 "getFunctionName", CallSiteGetFunctionName, | |
| 471 "getMethodName", CallSiteGetMethodName, | |
| 472 "getFileName", CallSiteGetFileName, | |
| 473 "getLineNumber", CallSiteGetLineNumber, | |
| 474 "getColumnNumber", CallSiteGetColumnNumber, | |
| 475 "isNative", CallSiteIsNative, | |
| 476 "getPosition", CallSiteGetPosition, | |
| 477 "isConstructor", CallSiteIsConstructor, | |
| 478 "toString", CallSiteToString | |
| 479 ]); | |
| 480 | |
| 481 | |
| 482 function FormatEvalOrigin(script) { | |
| 483 var sourceURL = script.nameOrSourceURL(); | |
| 484 if (sourceURL) { | |
| 485 return sourceURL; | |
| 486 } | |
| 487 | |
| 488 var eval_origin = "eval at "; | |
| 489 if (script.eval_from_function_name) { | |
| 490 eval_origin += script.eval_from_function_name; | |
| 491 } else { | |
| 492 eval_origin += "<anonymous>"; | |
| 493 } | |
| 494 | |
| 495 var eval_from_script = script.eval_from_script; | |
| 496 if (eval_from_script) { | |
| 497 if (eval_from_script.compilation_type == COMPILATION_TYPE_EVAL) { | |
| 498 // eval script originated from another eval. | |
| 499 eval_origin += " (" + FormatEvalOrigin(eval_from_script) + ")"; | |
| 500 } else { | |
| 501 // eval script originated from "real" source. | |
| 502 if (eval_from_script.name) { | |
| 503 eval_origin += " (" + eval_from_script.name; | |
| 504 var location = eval_from_script.locationFromPosition( | |
| 505 script.eval_from_script_position, true); | |
| 506 if (location) { | |
| 507 eval_origin += ":" + (location.line + 1); | |
| 508 eval_origin += ":" + (location.column + 1); | |
| 509 } | |
| 510 eval_origin += ")"; | |
| 511 } else { | |
| 512 eval_origin += " (unknown source)"; | |
| 513 } | |
| 514 } | |
| 515 } | |
| 516 | |
| 517 return eval_origin; | |
| 518 } | |
| 519 | |
| 520 | 353 |
| 521 function FormatErrorString(error) { | 354 function FormatErrorString(error) { |
| 522 try { | 355 try { |
| 523 return %_Call(ErrorToString, error); | 356 return %_Call(ErrorToString, error); |
| 524 } catch (e) { | 357 } catch (e) { |
| 525 try { | 358 try { |
| 526 return "<error: " + e + ">"; | 359 return "<error: " + e + ">"; |
| 527 } catch (ee) { | 360 } catch (ee) { |
| 528 return "<error>"; | 361 return "<error>"; |
| 529 } | 362 } |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 652 utils.Export(function(to) { | 485 utils.Export(function(to) { |
| 653 to.ErrorToString = ErrorToString; | 486 to.ErrorToString = ErrorToString; |
| 654 to.MakeError = MakeError; | 487 to.MakeError = MakeError; |
| 655 to.MakeRangeError = MakeRangeError; | 488 to.MakeRangeError = MakeRangeError; |
| 656 to.MakeSyntaxError = MakeSyntaxError; | 489 to.MakeSyntaxError = MakeSyntaxError; |
| 657 to.MakeTypeError = MakeTypeError; | 490 to.MakeTypeError = MakeTypeError; |
| 658 to.MakeURIError = MakeURIError; | 491 to.MakeURIError = MakeURIError; |
| 659 }); | 492 }); |
| 660 | 493 |
| 661 }); | 494 }); |
| OLD | NEW |