Permalink
Browse files

[#37] WindowContext with evaluate method.

  • Loading branch information...
1 parent c9f7c1d commit 8c81853619eeaa16afc154fc80dcc42628cdf29a @assaf committed Feb 15, 2011
Showing with 68 additions and 2 deletions.
  1. +66 −0 src/zombie/windowcontext.cc
  2. +2 −2 wscript
View
66 src/zombie/windowcontext.cc
@@ -0,0 +1,66 @@
+#include <v8.h>
+#include <node.h>
+
+using namespace node;
+using namespace v8;
+
+class WindowContext: ObjectWrap {
+private:
+ int m_count;
+ Handle<ObjectTemplate> global;
+ Persistent<Context> context;
+
+public:
+
+ static Persistent<FunctionTemplate> s_ct;
+ static void Init(Handle<Object> target) {
+ HandleScope scope;
+
+ Local<FunctionTemplate> t = FunctionTemplate::New(New);
+
+ s_ct = Persistent<FunctionTemplate>::New(t);
+ s_ct->InstanceTemplate()->SetInternalFieldCount(1);
+ s_ct->SetClassName(String::NewSymbol("WindowContext"));
+
+ //NODE_SET_PROTOTYPE_METHOD(s_ct, "global", GetGlobal);
+ NODE_SET_PROTOTYPE_METHOD(s_ct, "evaluate", Evaluate);
+
+ target->Set(String::NewSymbol("WindowContext"), s_ct->GetFunction());
+ }
+
+ WindowContext() : m_count(0) {
+ global = ObjectTemplate::New();
+ context = Context::New(NULL, global);
+ }
+
+ ~WindowContext() {
+ }
+
+ static Handle<Value> New(const Arguments& args) {
+ HandleScope scope;
+ WindowContext* hw = new WindowContext();
+ hw->Wrap(args.This());
+ return args.This();
+ }
+
+ static Handle<Value> Evaluate(const Arguments& args) {
+ HandleScope scope;
+ WindowContext* wc = ObjectWrap::Unwrap<WindowContext>(args.This());
+ Context::Scope context_scope(wc->context);
+ Local<String> source = args[0]->ToString();
+ Handle<Script> script = Script::Compile(source);
+ Handle<Value> result = script->Run();
+ return scope.Close(result);
+ }
+
+};
+
+Persistent<FunctionTemplate> WindowContext::s_ct;
+
+extern "C" {
+ static void init(Handle<Object> target) {
+ WindowContext::Init(target);
+ }
+ NODE_MODULE(windowcontext, init);
+}
+
View
4 wscript
@@ -8,5 +8,5 @@ def configure(conf):
def build(bld):
obj = bld.new_task_gen("cxx", "shlib", "node_addon")
obj.cxxflags = ["-g", "-D_FILE_OFFSET_BITS=64", "-D_LARGEFILE_SOURCE", "-Wall"]
- obj.target = "hellow"
- obj.source = "src/hellow.cc"
+ obj.target = "windowcontext"
+ obj.source = "src/zombie/windowcontext.cc"

0 comments on commit 8c81853

Please sign in to comment.