From 870e80b6ea55af6911e10b10f6a30b5be10f7643 Mon Sep 17 00:00:00 2001 From: Ali Ijaz Sheikh Date: Sun, 23 Aug 2015 06:28:57 -0700 Subject: [PATCH] src: apply debug force load fixups from 41e63fb Apply the src/node_contextify.cc and lib/module.js fixups from @bnoordhuis https://github.com/nodejs/node/commit/41e63fb088a29fa05e16fb0d997255678134c043 PR-URL: https://github.com/nodejs/node/pull/2509 Reviewed-By: Ben Noordhuis --- lib/module.js | 4 ++++ src/node_contextify.cc | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/lib/module.js b/lib/module.js index aaa6220e40a25e..da8a906f951541 100644 --- a/lib/module.js +++ b/lib/module.js @@ -423,6 +423,10 @@ Module.prototype._compile = function(content, filename) { // Set breakpoint on module start if (filename === resolvedArgv) { + // Installing this dummy debug event listener tells V8 to start + // the debugger. Without it, the setBreakPoint() fails with an + // 'illegal access' error. + global.v8debug.Debug.setListener(function() {}); global.v8debug.Debug.setBreakPoint(compiledWrapper, 0, 0); } } diff --git a/src/node_contextify.cc b/src/node_contextify.cc index ae043eb376a115..e1f11c6a401b07 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -261,6 +261,12 @@ class ContextifyContext { if (script_source.IsEmpty()) return; // Exception pending. Local debug_context = Debug::GetDebugContext(); + if (debug_context.IsEmpty()) { + // Force-load the debug context. + Debug::GetMirror(args.GetIsolate()->GetCurrentContext(), args[0]); + debug_context = Debug::GetDebugContext(); + CHECK(!debug_context.IsEmpty()); + } Environment* env = Environment::GetCurrent(args); ScopedEnvironment env_scope(debug_context, env); Context::Scope context_scope(debug_context);