Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: src/js/messages.js

Issue 2158303002: Begin porting CallSite to C++ (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@remove-overflow-boilerplate
Patch Set: Eager CallSite import and rebase Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/builtins/builtins-callsite.cc ('k') | src/messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 = utils.ImportNow("CallSite");
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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 ); 265 );
265 266
266 267
267 function GetStackTraceLine(recv, fun, pos, isGlobal) { 268 function GetStackTraceLine(recv, fun, pos, isGlobal) {
268 return new CallSite(recv, fun, pos, false).toString(); 269 return new CallSite(recv, fun, pos, false).toString();
269 } 270 }
270 271
271 // ---------------------------------------------------------------------------- 272 // ----------------------------------------------------------------------------
272 // Error implementation 273 // Error implementation
273 274
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() { 275 function CallSiteToString() {
390 if (HAS_PRIVATE(this, callSiteWasmObjectSymbol)) { 276 if (HAS_PRIVATE(this, callSiteWasmObjectSymbol)) {
391 var funName = this.getFunctionName(); 277 var funName = this.getFunctionName();
392 var funcIndex = GET_PRIVATE(this, callSiteWasmFunctionIndexSymbol); 278 var funcIndex = GET_PRIVATE(this, callSiteWasmFunctionIndexSymbol);
393 var pos = this.getPosition(); 279 var pos = this.getPosition();
394 if (IS_NULL(funName)) funName = "<WASM UNNAMED>"; 280 if (IS_NULL(funName)) funName = "<WASM UNNAMED>";
395 return funName + " (<WASM>[" + funcIndex + "]+" + pos + ")"; 281 return funName + " (<WASM>[" + funcIndex + "]+" + pos + ")";
396 } 282 }
397 283
398 var fileName; 284 var fileName;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 } else { 338 } else {
453 line += fileLocation; 339 line += fileLocation;
454 addSuffix = false; 340 addSuffix = false;
455 } 341 }
456 if (addSuffix) { 342 if (addSuffix) {
457 line += " (" + fileLocation + ")"; 343 line += " (" + fileLocation + ")";
458 } 344 }
459 return line; 345 return line;
460 } 346 }
461 347
462 utils.SetUpLockedPrototype(CallSite, ["receiver", "fun", "pos"], [ 348 %AddNamedProperty(CallSite.prototype, "toString", CallSiteToString,
463 "getThis", CallSiteGetThis, 349 DONT_ENUM | DONT_DELETE | READ_ONLY);
464 "getTypeName", CallSiteGetTypeName, 350 %SetNativeFlag(CallSiteToString);
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 351
520 352
521 function FormatErrorString(error) { 353 function FormatErrorString(error) {
522 try { 354 try {
523 return %_Call(ErrorToString, error); 355 return %_Call(ErrorToString, error);
524 } catch (e) { 356 } catch (e) {
525 try { 357 try {
526 return "<error: " + e + ">"; 358 return "<error: " + e + ">";
527 } catch (ee) { 359 } catch (ee) {
528 return "<error>"; 360 return "<error>";
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 utils.Export(function(to) { 484 utils.Export(function(to) {
653 to.ErrorToString = ErrorToString; 485 to.ErrorToString = ErrorToString;
654 to.MakeError = MakeError; 486 to.MakeError = MakeError;
655 to.MakeRangeError = MakeRangeError; 487 to.MakeRangeError = MakeRangeError;
656 to.MakeSyntaxError = MakeSyntaxError; 488 to.MakeSyntaxError = MakeSyntaxError;
657 to.MakeTypeError = MakeTypeError; 489 to.MakeTypeError = MakeTypeError;
658 to.MakeURIError = MakeURIError; 490 to.MakeURIError = MakeURIError;
659 }); 491 });
660 492
661 }); 493 });
OLDNEW
« no previous file with comments | « src/builtins/builtins-callsite.cc ('k') | src/messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698