Reviewers: yurys, vsevik,

Message:
Yury, please take a look.

Description:
[V8] Send AfterCompile and CompileError messages in debug scope

[email protected],[email protected]
BUG=396013

Please review this at https://codereview.chromium.org/642863007/

Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+54, -5 lines):
  M src/debug.cc
  M test/cctest/test-debug.cc
  M test/mjsunit/debug-clearbreakpointgroup.js
  M test/mjsunit/debug-compile-event.js
  M test/mjsunit/debug-evaluate-with-context.js


Index: src/debug.cc
diff --git a/src/debug.cc b/src/debug.cc
index c1c2aad68279b549005857c631e8d3999e6b610d..804aa6c562f6bd038f623768dab19615fc9503f6 100644
--- a/src/debug.cc
+++ b/src/debug.cc
@@ -2424,7 +2424,19 @@ void Debug::RecordEvalCaller(Handle<Script> script) {
 MaybeHandle<Object> Debug::MakeJSObject(const char* constructor_name,
                                         int argc,
                                         Handle<Object> argv[]) {
-  AssertDebugContext();
+  if (in_debug_scope()) {
+    Handle<GlobalObject> debug_global(debug_context()->global_object());
+    Factory* factory = isolate_->factory();
+    Handle<JSFunction> constructor =
+      Handle<JSFunction>::cast(Object::GetProperty(
+ debug_global, factory->InternalizeUtf8String(constructor_name)).ToHandleChecked());
+    PostponeInterruptsScope no_interrupts(isolate_);
+    return Execution::TryCall(constructor,
+                              handle(debug_context()->global_proxy()),
+                              argc,
+                              argv);
+  }
+
   // Create the execution state object.
   Handle<GlobalObject> global(isolate_->global_object());
   Handle<Object> constructor = Object::GetProperty(
@@ -2574,7 +2586,7 @@ void Debug::OnException(Handle<Object> exception, bool uncaught,

 void Debug::OnCompileError(Handle<Script> script) {
   // No more to do if not debugging.
-  if (in_debug_scope() || ignore_events()) return;
+  if (ignore_events()) return;

   HandleScope scope(isolate_);
   DebugScope debug_scope(this);
@@ -2636,7 +2648,17 @@ void Debug::OnAfterCompile(Handle<Script> script) {
   if (script_cache_ != NULL) script_cache_->Add(script);

   // No more to do if not debugging.
-  if (in_debug_scope() || ignore_events()) return;
+  if (ignore_events()) return;
+  if (in_debug_scope()) {
+    // Create the compile state object.
+    Handle<Object> event_data;
+    // Bail out and don't call debugger if exception.
+ if (!MakeCompileEvent(script, v8::AfterCompile).ToHandle(&event_data)) return;
+
+    // Process debug event.
+ ProcessDebugEvent(v8::AfterCompile, Handle<JSObject>::cast(event_data), true);
+    return;
+  }

   HandleScope scope(isolate_);
   DebugScope debug_scope(this);
@@ -2829,7 +2851,8 @@ void Debug::NotifyMessageHandler(v8::DebugEvent event,
// added. It should be enough to clear the flag only once while we are in the
   // debugger.
   DCHECK(in_debug_scope());
-  isolate_->stack_guard()->ClearDebugCommand();
+ if (!(in_debug_scope() && (event == v8::AfterCompile || event == v8::CompileError)))
+    isolate_->stack_guard()->ClearDebugCommand();

// Notify the debugger that a debug event has occurred unless auto continue is
   // active in which case no event is send.
@@ -2847,6 +2870,7 @@ void Debug::NotifyMessageHandler(v8::DebugEvent event,
// messages in the queue as the execution state might not be what is expected
   // by the client.
   if (auto_continue && !has_commands()) return;
+ if (in_debug_scope() && (event == v8::AfterCompile || event == v8::CompileError)) return;

   // DebugCommandProcessor goes here.
   bool running = auto_continue;
Index: test/cctest/test-debug.cc
diff --git a/test/cctest/test-debug.cc b/test/cctest/test-debug.cc
index 575f938594cbe6f9011d89c11838af29cefc9c9d..ae5f49aa40041da453dd1a354ece464f9d796f11 100644
--- a/test/cctest/test-debug.cc
+++ b/test/cctest/test-debug.cc
@@ -4863,6 +4863,19 @@ bool IsEvaluateResponseMessage(char* message) {
 }


+// We match parts of the message to decide if it is a after compile message.
+bool IsCompileEventMessage(char* message) {
+  const char* type_event = "\"type\":\"event\"";
+  const char* event_after_compile = "\"event\":\"afterCompile\"";
+  const char* event_compile_error = "\"event\":\"compileError\"";
+  // Does the message contain both type:event and event:afterCompile or
+  // event:compileError ?
+  return strstr(message, type_event) != NULL &&
+      (strstr(message, event_after_compile) != NULL ||
+       strstr(message, event_compile_error) != NULL);
+}
+
+
 static int StringToInt(const char* s) {
   return atoi(s);  // NOLINT
 }
@@ -4946,6 +4959,8 @@ static void MessageHandler(const v8::Debug::Message& message) {
     message_queue_barriers.semaphore_2.Signal();
   }

+  if (IsCompileEventMessage(*utf8)) return;
+
   // Allow message handler to block on a semaphore, to test queueing of
   // messages while blocked.
   message_queue_barriers.semaphore_1.Wait();
Index: test/mjsunit/debug-clearbreakpointgroup.js
diff --git a/test/mjsunit/debug-clearbreakpointgroup.js b/test/mjsunit/debug-clearbreakpointgroup.js index 137dfecbecbedd20c0db312f5abb224806061b9f..2ad447e4b7ebb020e979fb06243150ba76d35418 100644
--- a/test/mjsunit/debug-clearbreakpointgroup.js
+++ b/test/mjsunit/debug-clearbreakpointgroup.js
@@ -33,6 +33,7 @@ var Debug = debug.Debug
 // Simple function which stores the last debug event.
 var listenerComplete = false;
 var exception = false;
+var ignore_events = false;

var base_request = '"seq":0,"type":"request","command":"clearbreakpointgroup"';
 var scriptId = null;
@@ -49,7 +50,9 @@ function safeEval(code) {
 function testArguments(dcp, arguments, success) {
   var request = '{' + base_request + ',"arguments":' + arguments + '}'
   var json_response = dcp.processDebugJSONRequest(request);
+  ignore_events = true;
   var response = safeEval(json_response);
+  ignore_events = false;
   if (success) {
     assertTrue(response.success, json_response);
   } else {
@@ -58,6 +61,7 @@ function testArguments(dcp, arguments, success) {
 }

 function listener(event, exec_state, event_data, data) {
+  if (ignore_events) return;
   try {
     if (event == Debug.DebugEvent.Break) {
       // Get the debug command processor.
Index: test/mjsunit/debug-compile-event.js
diff --git a/test/mjsunit/debug-compile-event.js b/test/mjsunit/debug-compile-event.js index c38cd8477a9fe4d53b110f419d7b099292a111ff..5b745be5893cde59af4ee5aa3e6ffe1a9c62795f 100644
--- a/test/mjsunit/debug-compile-event.js
+++ b/test/mjsunit/debug-compile-event.js
@@ -37,6 +37,7 @@ var current_source = ''; // Current source being compiled.
 var source_count = 0;  // Total number of scources compiled.
 var host_compilations = 0;  // Number of scources compiled through the API.
 var eval_compilations = 0;  // Number of scources compiled through eval.
+var ignore_events = false;


 function compileSource(source) {
@@ -47,6 +48,7 @@ function compileSource(source) {


 function listener(event, exec_state, event_data, data) {
+  if (ignore_events) return;
   try {
     if (event == Debug.DebugEvent.BeforeCompile ||
         event == Debug.DebugEvent.AfterCompile ||
@@ -81,7 +83,9 @@ function listener(event, exec_state, event_data, data) {
       }
       // Check that script context is included into the event message.
       var json = event_data.toJSONProtocol();
+      ignore_events = true;
       var msg = eval('(' + json + ')');
+      ignore_events = false;
       assertTrue('context' in msg.body.script);

       // Check that we pick script name from //# sourceURL, iff present
@@ -117,7 +121,7 @@ try {
 }

 // Make sure that the debug event listener was invoked.
-assertFalse(exception, "exception in listener")
+assertFalse(exception, "exception in listener");

 // Number of before and after + error events should be the same.
assertEquals(before_compile_count, after_compile_count + compile_error_count);
Index: test/mjsunit/debug-evaluate-with-context.js
diff --git a/test/mjsunit/debug-evaluate-with-context.js b/test/mjsunit/debug-evaluate-with-context.js index 5e1c83cf52cf401f615fc06ec45f0feaac125079..e2e14370d3ef3a324d1aadfd42e91aae8e6a59cf 100644
--- a/test/mjsunit/debug-evaluate-with-context.js
+++ b/test/mjsunit/debug-evaluate-with-context.js
@@ -32,6 +32,8 @@ Debug = debug.Debug
 var evaluate_callback;

 function listener(event, exec_state, event_data, data) {
+  if (event == Debug.DebugEvent.AfterCompile ||
+      event == Debug.DebugEvent.CompileError) return;
   try {
     var context = { what_is_capybara: "a fish" };
var context2 = { what_is_capybara: "a fish", what_is_parrot: "a beard" };


--
--
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.

Reply via email to