diff options
| author | Ben Noordhuis <info@bnoordhuis.nl> | 2014-08-22 15:09:24 +0200 |
|---|---|---|
| committer | Trevor Norris <trev.norris@gmail.com> | 2014-09-16 12:28:47 -0700 |
| commit | 21e60643b0795fe7b6a46ff29d73df60e6a7c9f5 (patch) | |
| tree | 9eabb3502881497dcb7766179a5d2ee4647a03bd /src | |
| parent | 174f7d2820dcb12f1b4b511840416a03cd65b9cf (diff) | |
| download | node-21e60643b0795fe7b6a46ff29d73df60e6a7c9f5.tar.gz | |
lib, src: add vm.runInDebugContext()
Compiles and executes source code in V8's debugger context. Provides
a programmatic way to get access to the debug object by executing:
var Debug = vm.runInDebugContext('Debug');
Fixes #7886.
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/node_contextify.cc | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/node_contextify.cc b/src/node_contextify.cc index 9525e7db6..bb43536d8 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -28,6 +28,7 @@ #include "env-inl.h" #include "util.h" #include "util-inl.h" +#include "v8-debug.h" namespace node { @@ -35,6 +36,7 @@ using v8::AccessType; using v8::Array; using v8::Boolean; using v8::Context; +using v8::Debug; using v8::EscapableHandleScope; using v8::External; using v8::Function; @@ -244,11 +246,25 @@ class ContextifyContext { function_template->InstanceTemplate()->SetInternalFieldCount(1); env->set_script_data_constructor_function(function_template->GetFunction()); + NODE_SET_METHOD(target, "runInDebugContext", RunInDebugContext); NODE_SET_METHOD(target, "makeContext", MakeContext); NODE_SET_METHOD(target, "isContext", IsContext); } + static void RunInDebugContext(const FunctionCallbackInfo<Value>& args) { + HandleScope scope(args.GetIsolate()); + Local<String> script_source(args[0]->ToString()); + if (script_source.IsEmpty()) + return; // Exception pending. + Context::Scope context_scope(Debug::GetDebugContext()); + Local<Script> script = Script::Compile(script_source); + if (script.IsEmpty()) + return; // Exception pending. + args.GetReturnValue().Set(script->Run()); + } + + static void MakeContext(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args.GetIsolate()); HandleScope scope(env->isolate()); |
