diff --git a/README.markdown b/README.markdown index c3c1123..efcbc2e 100644 --- a/README.markdown +++ b/README.markdown @@ -19,9 +19,10 @@ vu8 is a project that allows one to give JavaScript access to C++ classes and me static inline v8::Handle Open() { v8::HandleScope scope; Module mod; - return mod("println", &Println) + return scope.Close( + mod("println", &Println) .Set("flush") - .NewInstance(); + .NewInstance()); } } } @@ -116,10 +117,11 @@ vu8 is a project that allows one to give JavaScript access to C++ classes and me // Create a module to add classes and functions to and return a // new instance of the module to be embedded into the v8 context vu8::Module mod; - return mod("Writer", fileWriter) - ("Reader", fileReader) - .Set("rename") - .NewInstance(); + return scope.Close( + mod("Writer", fileWriter) + ("Reader", fileReader) + .Set("rename") + .NewInstance()); } ## Creating a v8 Context capable of using "vu8.load" diff --git a/src/vu8/Context.cpp b/src/vu8/Context.cpp index 69a591a..d9dc7ec 100644 --- a/src/vu8/Context.cpp +++ b/src/vu8/Context.cpp @@ -63,8 +63,12 @@ v8::Handle LoadModule(const v8::Arguments& args) { context.modules_.insert(modules_t::value_type( modName, boost::make_tuple( dl, v8::Persistent::New(value)))); - +#if 0 + // not sure if closing over persistent handle is a problem or necessary + return boost::get<1>(ret.first->second); +#else return scope.Close(boost::get<1>(ret.first->second)); +#endif } namespace { diff --git a/src/vu8/lib/console.cpp b/src/vu8/lib/console.cpp index 4229ed1..51be761 100644 --- a/src/vu8/lib/console.cpp +++ b/src/vu8/lib/console.cpp @@ -20,8 +20,7 @@ v8::Handle Log(const v8::Arguments& args) { static inline v8::Handle Open() { v8::HandleScope scope; Module mod; - mod("log", &Log); - return mod.NewInstance(); + return scope.Close(mod("log", &Log).NewInstance()); } } } diff --git a/src/vu8/lib/file.cpp b/src/vu8/lib/file.cpp index 4a0b402..e0ffb65 100644 --- a/src/vu8/lib/file.cpp +++ b/src/vu8/lib/file.cpp @@ -112,12 +112,12 @@ static inline v8::Handle Open() { ; Module mod; - return mod + return scope.Close(mod ("Writer", fileWriter) ("Reader", fileReader) .Set("rename") .Set("mkdir") - .NewInstance(); + .NewInstance()); } } } diff --git a/src/vu8/lib/os.cpp b/src/vu8/lib/os.cpp index 61ed936..687e950 100644 --- a/src/vu8/lib/os.cpp +++ b/src/vu8/lib/os.cpp @@ -24,10 +24,10 @@ bool Signal(int const pid, int const signal) { static inline v8::Handle Open() { v8::HandleScope scope; Module mod; - return mod + return scope.Close(mod .Set("getenv") .Set("signal") - .NewInstance(); + .NewInstance()); } } } diff --git a/src/vu8/test/loadmodule.js b/src/vu8/test/loadmodule.js index 1a8f99a..17026f5 100644 --- a/src/vu8/test/loadmodule.js +++ b/src/vu8/test/loadmodule.js @@ -1,4 +1,5 @@ var console = vu8.load('console') + console.log('yo', 'baby', 4.2, null) var c2 = vu8.load('console')