Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
added isolates support
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny authored and bnoordhuis committed Jan 10, 2012
1 parent 97e4b3a commit a5f74b4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 29 deletions.
51 changes: 22 additions & 29 deletions src/node_script.cc
Expand Up @@ -21,6 +21,7 @@

#include <node.h>
#include <node_script.h>
#include <node_vars.h>
#include <assert.h>

namespace node {
Expand All @@ -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:
Expand All @@ -55,18 +58,13 @@ class WrappedContext : ObjectWrap {

protected:

static Persistent<FunctionTemplate> constructor_template;

WrappedContext();
~WrappedContext();

Persistent<Context> context_;
};


Persistent<FunctionTemplate> WrappedContext::constructor_template;


class WrappedScript : ObjectWrap {
public:
static void Initialize(Handle<Object> target);
Expand All @@ -81,8 +79,6 @@ class WrappedScript : ObjectWrap {
static Handle<Value> EvalMachine(const Arguments& args);

protected:
static Persistent<FunctionTemplate> constructor_template;

WrappedScript() : ObjectWrap() {}
~WrappedScript();

Expand Down Expand Up @@ -135,17 +131,17 @@ void WrappedContext::Initialize(Handle<Object> target) {
HandleScope scope;

Local<FunctionTemplate> t = FunctionTemplate::New(WrappedContext::New);
constructor_template = Persistent<FunctionTemplate>::New(t);
constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
constructor_template->SetClassName(String::NewSymbol("Context"));
wrapped_context_constructor = Persistent<FunctionTemplate>::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> value) {
return !value.IsEmpty() && constructor_template->HasInstance(value);
return !value.IsEmpty() && wrapped_context_constructor->HasInstance(value);
}


Expand All @@ -170,7 +166,7 @@ WrappedContext::~WrappedContext() {


Local<Object> WrappedContext::NewInstance() {
Local<Object> context = constructor_template->GetFunction()->NewInstance();
Local<Object> context = wrapped_context_constructor->GetFunction()->NewInstance();
return context;
}

Expand All @@ -180,60 +176,57 @@ Persistent<Context> WrappedContext::GetV8Context() {
}


Persistent<FunctionTemplate> WrappedScript::constructor_template;


void WrappedScript::Initialize(Handle<Object> target) {
HandleScope scope;

Local<FunctionTemplate> t = FunctionTemplate::New(WrappedScript::New);
constructor_template = Persistent<FunctionTemplate>::New(t);
constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
wrapped_script_constructor = Persistent<FunctionTemplate>::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<Value> WrappedScript::New(const Arguments& args) {
if (!args.IsConstructCall()) {
return FromConstructorTemplate(constructor_template, args);
return FromConstructorTemplate(wrapped_script_constructor, args);
}

HandleScope scope;
Expand Down
4 changes: 4 additions & 0 deletions src/node_vars.h
Expand Up @@ -168,6 +168,10 @@ struct globals {
v8::Persistent<v8::String> write_sym;
v8::Persistent<v8::FunctionTemplate> buffer_constructor_template;

// node_script.cc
v8::Persistent<v8::FunctionTemplate> wrapped_context_constructor;
v8::Persistent<v8::FunctionTemplate> wrapped_script_constructor;

// node_signal_watcher.cc
v8::Persistent<v8::String> callback_symbol;
v8::Persistent<v8::FunctionTemplate> signal_watcher_constructor_template;
Expand Down

0 comments on commit a5f74b4

Please sign in to comment.