Reviewers: vsevik,
Description:
Add OnSyntaxError handler and v8::ScriptfailedToParse debug event
Work in progress.
BUG=
Please review this at https://codereview.chromium.org/264333007/
SVN Base: git://github.com/v8/v8.git@master
Affected files (+86, -6 lines):
M include/v8-debug.h
M src/debug.h
M src/debug.cc
M src/isolate.h
M src/isolate.cc
Index: include/v8-debug.h
diff --git a/include/v8-debug.h b/include/v8-debug.h
index
8523387a51a487bf9d0937dd1a671e83e2889806..40f2ce26f64e0d65b627a98e923a17fb1c9b0e90
100644
--- a/include/v8-debug.h
+++ b/include/v8-debug.h
@@ -21,7 +21,8 @@ enum DebugEvent {
AfterCompile = 5,
ScriptCollected = 6,
PendingExceptionInPromise = 7,
- BreakForCommand = 8
+ BreakForCommand = 8,
+ ScriptFailedToParse = 9
};
Index: src/debug.cc
diff --git a/src/debug.cc b/src/debug.cc
index
dadaa915d48e0fb17467097156c89047e57edf98..ac4d1217792ced9e12746af1a8c90ecf412973fe
100644
--- a/src/debug.cc
+++ b/src/debug.cc
@@ -2685,6 +2685,67 @@ void Debugger::OnException(Handle<Object> exception,
}
+void Debugger::OnSyntaxError(Handle<Script> script) {
+ HandleScope scope(isolate_);
+ Debug* debug = isolate_->debug();
+
+ // No more to do if not debugging.
+ if (!IsDebuggerActive()) return;
+
+ // No compile events while compiling natives.
+ if (compiling_natives()) return;
+
+ // Store whether in debugger before entering debugger.
+ bool in_debugger = debug->InDebugger();
+
+ // Enter the debugger.
+ EnterDebugger debugger(isolate_);
+ if (debugger.FailedToEnter()) return;
+
+ // Save breakpoints or not, if SyntaxError ocured?
+
+ // If debugging there might be script break points registered for this
+ // script. Make sure that these break points are set.
+
+ // Get the function UpdateScriptBreakPoints (defined in
debug-debugger.js).
+ Handle<String> update_script_break_points_string =
+ isolate_->factory()->InternalizeOneByteString(
+ STATIC_ASCII_VECTOR("UpdateScriptBreakPoints"));
+ Handle<GlobalObject>
debug_global(debug->debug_context()->global_object());
+ Handle<Object> update_script_break_points =
+ Object::GetProperty(
+ debug_global,
update_script_break_points_string).ToHandleChecked();
+ if (!update_script_break_points->IsJSFunction()) {
+ return;
+ }
+ ASSERT(update_script_break_points->IsJSFunction());
+
+ // Wrap the script object in a proper JS object before passing it
+ // to JavaScript.
+ Handle<Object> wrapper = Script::GetWrapper(script);
+
+ // Call UpdateScriptBreakPoints expect no exceptions.
+ Handle<Object> argv[] = { wrapper };
+ if
(Execution::TryCall(Handle<JSFunction>::cast(update_script_break_points),
+ isolate_->js_builtins_object(),
+ ARRAY_SIZE(argv),
+ argv).is_null()) {
+ return;
+ }
+ // Bail out based on state or if there is no listener for this event
+ if (!Debugger::EventActive(v8::AfterCompile)) return;
+
+ // Create the compile state object.
+ Handle<Object> event_data;
+ // Bail out and don't call debugger if exception.
+ if (!MakeCompileEvent(script, false).ToHandle(&event_data)) return;
+
+ // Process debug event.
+ ProcessDebugEvent(v8::ScriptFailedToParse,
+ Handle<JSObject>::cast(event_data), true);
+}
+
+
void Debugger::OnDebugBreak(Handle<Object> break_points_hit,
bool auto_continue) {
HandleScope scope(isolate_);
Index: src/debug.h
diff --git a/src/debug.h b/src/debug.h
index
da59526e6ae02a04c188068dca668e47ddbf4063..29cb55ab1663fc08c5b4dd9647106009ed0a00a6
100644
--- a/src/debug.h
+++ b/src/debug.h
@@ -780,6 +780,7 @@ class Debugger {
void OnException(Handle<Object> exception,
bool uncaught,
Handle<Object> promise = Handle<Object>::null());
+ void OnSyntaxError(Handle<Script> script);
void OnBeforeCompile(Handle<Script> script);
enum AfterCompileFlags {
Index: src/isolate.cc
diff --git a/src/isolate.cc b/src/isolate.cc
index
3542b994ff3338ffd3860b763f49b4730dfe6d54..72aeb614d3cc8399f32e07841dc1ed2657467767
100644
--- a/src/isolate.cc
+++ b/src/isolate.cc
@@ -989,19 +989,29 @@ bool Isolate::ShouldReportException(bool*
can_be_caught_externally,
bool Isolate::IsErrorObject(Handle<Object> obj) {
+ return IsTypeObject(obj,
+ factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("$Error")));
+}
+
+
+bool Isolate::IsSyntaxErrorObject(Handle<Object> obj) {
+ return IsTypeObject(obj,
+
factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("$SyntaxError")));
+}
+
+
+bool Isolate::IsTypeObject(Handle<Object> obj, Handle<String> key) {
if (!obj->IsJSObject()) return false;
- Handle<String> error_key =
- factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("$Error"));
- Handle<Object> error_constructor = Object::GetProperty(
- js_builtins_object(), error_key).ToHandleChecked();
+ Handle<Object> constructor = Object::GetProperty(
+ js_builtins_object(), key).ToHandleChecked();
DisallowHeapAllocation no_gc;
for (Object* prototype = *obj; !prototype->IsNull();
prototype = prototype->GetPrototype(this)) {
if (!prototype->IsJSObject()) return false;
if (JSObject::cast(prototype)->map()->constructor() ==
- *error_constructor) {
+ *constructor) {
return true;
}
}
@@ -1029,6 +1039,11 @@ void Isolate::DoThrow(Object* exception,
MessageLocation* location) {
thread_local_top()->rethrowing_message_ = false;
+ // notify debugger of SyntaxError
+ if (IsSyntaxErrorObject(exception_handle)) {
+ debugger_->OnSyntaxError(location->script());
+ }
+
// Notify debugger of exception.
if (catchable_by_javascript) {
debugger_->OnException(
Index: src/isolate.h
diff --git a/src/isolate.h b/src/isolate.h
index
bc7646bd4834bafc03bf333f53da14ee072ac451..5e1fbb616142a94aef0a6293240a6c1308e493f9
100644
--- a/src/isolate.h
+++ b/src/isolate.h
@@ -1185,6 +1185,8 @@ class Isolate {
// Traverse prototype chain to find out whether the object is derived
from
// the Error object.
bool IsErrorObject(Handle<Object> obj);
+ bool IsSyntaxErrorObject(Handle<Object> obj);
+ bool IsTypeObject(Handle<Object> obj, Handle<String> key);
Atomic32 id_;
EntryStackItem* entry_stack_;
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.