diff options
Diffstat (limited to 'src/node_contextify.cc')
-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 9525e7db64..bb43536d87 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()); |