From a5f74b4da7ad3f4946cb5e0db7c94ee6bf8e5718 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Sat, 7 Jan 2012 00:24:41 +0600 Subject: [PATCH] added isolates support --- src/node_script.cc | 51 ++++++++++++++++++++++----------------------------- src/node_vars.h | 4 ++++ 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/src/node_script.cc b/src/node_script.cc index 1f51113..a6fdba6 100644 --- a/src/node_script.cc +++ b/src/node_script.cc @@ -21,6 +21,7 @@ #include #include +#include #include namespace node { @@ -43,6 +44,8 @@ using v8::Integer; using v8::Function; using v8::FunctionTemplate; +#define wrapped_context_constructor NODE_VAR(wrapped_context_constructor) +#define wrapped_script_constructor NODE_VAR(wrapped_script_constructor) class WrappedContext : ObjectWrap { public: @@ -55,8 +58,6 @@ class WrappedContext : ObjectWrap { protected: - static Persistent constructor_template; - WrappedContext(); ~WrappedContext(); @@ -64,9 +65,6 @@ class WrappedContext : ObjectWrap { }; -Persistent WrappedContext::constructor_template; - - class WrappedScript : ObjectWrap { public: static void Initialize(Handle target); @@ -81,8 +79,6 @@ class WrappedScript : ObjectWrap { static Handle EvalMachine(const Arguments& args); protected: - static Persistent constructor_template; - WrappedScript() : ObjectWrap() {} ~WrappedScript(); @@ -135,17 +131,17 @@ void WrappedContext::Initialize(Handle target) { HandleScope scope; Local t = FunctionTemplate::New(WrappedContext::New); - constructor_template = Persistent::New(t); - constructor_template->InstanceTemplate()->SetInternalFieldCount(1); - constructor_template->SetClassName(String::NewSymbol("Context")); + wrapped_context_constructor = Persistent::New(t); + wrapped_context_constructor->InstanceTemplate()->SetInternalFieldCount(1); + wrapped_context_constructor->SetClassName(String::NewSymbol("Context")); target->Set(String::NewSymbol("Context"), - constructor_template->GetFunction()); + wrapped_context_constructor->GetFunction()); } bool WrappedContext::InstanceOf(Handle value) { - return !value.IsEmpty() && constructor_template->HasInstance(value); + return !value.IsEmpty() && wrapped_context_constructor->HasInstance(value); } @@ -170,7 +166,7 @@ WrappedContext::~WrappedContext() { Local WrappedContext::NewInstance() { - Local context = constructor_template->GetFunction()->NewInstance(); + Local context = wrapped_context_constructor->GetFunction()->NewInstance(); return context; } @@ -180,60 +176,57 @@ Persistent WrappedContext::GetV8Context() { } -Persistent WrappedScript::constructor_template; - - void WrappedScript::Initialize(Handle target) { HandleScope scope; Local t = FunctionTemplate::New(WrappedScript::New); - constructor_template = Persistent::New(t); - constructor_template->InstanceTemplate()->SetInternalFieldCount(1); + wrapped_script_constructor = Persistent::New(t); + wrapped_script_constructor->InstanceTemplate()->SetInternalFieldCount(1); // Note: We use 'NodeScript' instead of 'Script' so that we do not // conflict with V8's Script class defined in v8/src/messages.js // See GH-203 https://github.com/joyent/node/issues/203 - constructor_template->SetClassName(String::NewSymbol("NodeScript")); + wrapped_script_constructor->SetClassName(String::NewSymbol("NodeScript")); - NODE_SET_PROTOTYPE_METHOD(constructor_template, + NODE_SET_PROTOTYPE_METHOD(wrapped_script_constructor, "createContext", WrappedScript::CreateContext); - NODE_SET_PROTOTYPE_METHOD(constructor_template, + NODE_SET_PROTOTYPE_METHOD(wrapped_script_constructor, "runInContext", WrappedScript::RunInContext); - NODE_SET_PROTOTYPE_METHOD(constructor_template, + NODE_SET_PROTOTYPE_METHOD(wrapped_script_constructor, "runInThisContext", WrappedScript::RunInThisContext); - NODE_SET_PROTOTYPE_METHOD(constructor_template, + NODE_SET_PROTOTYPE_METHOD(wrapped_script_constructor, "runInNewContext", WrappedScript::RunInNewContext); - NODE_SET_METHOD(constructor_template, + NODE_SET_METHOD(wrapped_script_constructor, "createContext", WrappedScript::CreateContext); - NODE_SET_METHOD(constructor_template, + NODE_SET_METHOD(wrapped_script_constructor, "runInContext", WrappedScript::CompileRunInContext); - NODE_SET_METHOD(constructor_template, + NODE_SET_METHOD(wrapped_script_constructor, "runInThisContext", WrappedScript::CompileRunInThisContext); - NODE_SET_METHOD(constructor_template, + NODE_SET_METHOD(wrapped_script_constructor, "runInNewContext", WrappedScript::CompileRunInNewContext); target->Set(String::NewSymbol("NodeScript"), - constructor_template->GetFunction()); + wrapped_script_constructor->GetFunction()); } Handle WrappedScript::New(const Arguments& args) { if (!args.IsConstructCall()) { - return FromConstructorTemplate(constructor_template, args); + return FromConstructorTemplate(wrapped_script_constructor, args); } HandleScope scope; diff --git a/src/node_vars.h b/src/node_vars.h index dbd362b..acf581e 100644 --- a/src/node_vars.h +++ b/src/node_vars.h @@ -168,6 +168,10 @@ struct globals { v8::Persistent write_sym; v8::Persistent buffer_constructor_template; + // node_script.cc + v8::Persistent wrapped_context_constructor; + v8::Persistent wrapped_script_constructor; + // node_signal_watcher.cc v8::Persistent callback_symbol; v8::Persistent signal_watcher_constructor_template; -- 2.7.4