From 4e9e1eedf1ba399d00b53adf6e5722d442ed9797 Mon Sep 17 00:00:00 2001 From: kozyatinskiy Date: Tue, 3 Feb 2015 00:57:18 -0800 Subject: [PATCH] [V8] Added line, column and script symbols for SyntaxError For exception in promise we generate v8::Message API object from exception object. And in cases of Syntax or Reference Error we don't have enough information in exception object - we can't restore Error location from top stack frame. In this patch three aditional private fields introduced for exception object. In case of Syntax Error we store line, column and script on Exception object and receive this information when restoring message. BUG=443140 LOG=Y R=yurys@chromium.org Review URL: https://codereview.chromium.org/885043002 Cr-Commit-Position: refs/heads/master@{#26393} --- src/heap/heap.h | 5 ++++- src/isolate.cc | 36 ++++++++++++++++++++++++++--- src/isolate.h | 2 ++ src/parser.cc | 21 ++++++++++++++++- test/cctest/test-api.cc | 60 ++++++++++++++++++++++++++++++++++++++++++------- 5 files changed, 111 insertions(+), 13 deletions(-) diff --git a/src/heap/heap.h b/src/heap/heap.h index 9d7341a..2975d09 100644 --- a/src/heap/heap.h +++ b/src/heap/heap.h @@ -302,7 +302,10 @@ namespace internal { V(promise_has_handler_symbol) \ V(class_script_symbol) \ V(class_start_position_symbol) \ - V(class_end_position_symbol) + V(class_end_position_symbol) \ + V(error_start_pos_symbol) \ + V(error_end_pos_symbol) \ + V(error_script_symbol) #define PUBLIC_SYMBOL_LIST(V) \ V(has_instance_symbol, symbolHasInstance, Symbol.hasInstance) \ diff --git a/src/isolate.cc b/src/isolate.cc index 3479ae2..259c2a2 100644 --- a/src/isolate.cc +++ b/src/isolate.cc @@ -1069,6 +1069,33 @@ void Isolate::ComputeLocation(MessageLocation* target) { } +bool Isolate::ComputeLocationFromException(MessageLocation* target, + Handle exception) { + if (!exception->IsJSObject()) return false; + + Handle start_pos_symbol = factory()->error_start_pos_symbol(); + Handle start_pos = JSObject::GetDataProperty( + Handle::cast(exception), start_pos_symbol); + if (!start_pos->IsSmi()) return false; + int start_pos_value = Handle::cast(start_pos)->value(); + + Handle end_pos_symbol = factory()->error_end_pos_symbol(); + Handle end_pos = JSObject::GetDataProperty( + Handle::cast(exception), end_pos_symbol); + if (!end_pos->IsSmi()) return false; + int end_pos_value = Handle::cast(end_pos)->value(); + + Handle script_symbol = factory()->error_script_symbol(); + Handle script = JSObject::GetDataProperty( + Handle::cast(exception), script_symbol); + if (!script->IsScript()) return false; + + Handle