OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 #include "src/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
6 | 6 |
7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
8 #include "src/ast/prettyprinter.h" | 8 #include "src/ast/prettyprinter.h" |
9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
10 #include "src/conversions.h" | 10 #include "src/conversions.h" |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 | 405 |
406 | 406 |
407 RUNTIME_FUNCTION(Runtime_GetCodeStubExportsObject) { | 407 RUNTIME_FUNCTION(Runtime_GetCodeStubExportsObject) { |
408 HandleScope shs(isolate); | 408 HandleScope shs(isolate); |
409 return isolate->heap()->code_stub_exports_object(); | 409 return isolate->heap()->code_stub_exports_object(); |
410 } | 410 } |
411 | 411 |
412 | 412 |
413 namespace { | 413 namespace { |
414 | 414 |
| 415 bool ComputeLocation(Isolate* isolate, MessageLocation* target) { |
| 416 JavaScriptFrameIterator it(isolate); |
| 417 if (!it.done()) { |
| 418 JavaScriptFrame* frame = it.frame(); |
| 419 JSFunction* fun = frame->function(); |
| 420 Object* script = fun->shared()->script(); |
| 421 if (script->IsScript() && |
| 422 !(Script::cast(script)->source()->IsUndefined())) { |
| 423 Handle<Script> casted_script(Script::cast(script)); |
| 424 // Compute the location from the function and the relocation info of the |
| 425 // baseline code. For optimized code this will use the deoptimization |
| 426 // information to get canonical location information. |
| 427 List<FrameSummary> frames(FLAG_max_inlining_levels + 1); |
| 428 it.frame()->Summarize(&frames); |
| 429 FrameSummary& summary = frames.last(); |
| 430 int pos = summary.code()->SourcePosition(summary.pc()); |
| 431 *target = MessageLocation(casted_script, pos, pos + 1, handle(fun)); |
| 432 return true; |
| 433 } |
| 434 } |
| 435 return false; |
| 436 } |
| 437 |
| 438 |
415 Handle<String> RenderCallSite(Isolate* isolate, Handle<Object> object) { | 439 Handle<String> RenderCallSite(Isolate* isolate, Handle<Object> object) { |
416 MessageLocation location; | 440 MessageLocation location; |
417 if (isolate->ComputeLocation(&location)) { | 441 if (ComputeLocation(isolate, &location)) { |
418 Zone zone; | 442 Zone zone; |
419 base::SmartPointer<ParseInfo> info( | 443 base::SmartPointer<ParseInfo> info( |
420 location.function()->shared()->is_function() | 444 location.function()->shared()->is_function() |
421 ? new ParseInfo(&zone, location.function()) | 445 ? new ParseInfo(&zone, location.function()) |
422 : new ParseInfo(&zone, location.script())); | 446 : new ParseInfo(&zone, location.script())); |
423 if (Parser::ParseStatic(info.get())) { | 447 if (Parser::ParseStatic(info.get())) { |
424 CallPrinter printer(isolate); | 448 CallPrinter printer(isolate, location.function()->shared()->IsBuiltin()); |
425 const char* string = printer.Print(info->literal(), location.start_pos()); | 449 const char* string = printer.Print(info->literal(), location.start_pos()); |
426 return isolate->factory()->NewStringFromAsciiChecked(string); | 450 if (strlen(string) > 0) { |
| 451 return isolate->factory()->NewStringFromAsciiChecked(string); |
| 452 } |
427 } else { | 453 } else { |
428 isolate->clear_pending_exception(); | 454 isolate->clear_pending_exception(); |
429 } | 455 } |
430 } | 456 } |
431 return Object::TypeOf(isolate, object); | 457 return Object::TypeOf(isolate, object); |
432 } | 458 } |
433 | 459 |
434 } // namespace | 460 } // namespace |
435 | 461 |
436 | 462 |
(...skipping 11 matching lines...) Expand all Loading... |
448 HandleScope scope(isolate); | 474 HandleScope scope(isolate); |
449 DCHECK_EQ(1, args.length()); | 475 DCHECK_EQ(1, args.length()); |
450 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); | 476 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); |
451 Handle<String> callsite = RenderCallSite(isolate, object); | 477 Handle<String> callsite = RenderCallSite(isolate, object); |
452 THROW_NEW_ERROR_RETURN_FAILURE( | 478 THROW_NEW_ERROR_RETURN_FAILURE( |
453 isolate, NewTypeError(MessageTemplate::kNotConstructor, callsite)); | 479 isolate, NewTypeError(MessageTemplate::kNotConstructor, callsite)); |
454 } | 480 } |
455 | 481 |
456 } // namespace internal | 482 } // namespace internal |
457 } // namespace v8 | 483 } // namespace v8 |
OLD | NEW |