Skip to content

Commit

Permalink
Not Close-ing over handles returned from module loading leads to trouble
Browse files Browse the repository at this point in the history
  • Loading branch information
jpike committed Jan 20, 2012
1 parent 678ed53 commit 3deafd6
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
14 changes: 8 additions & 6 deletions README.markdown
Expand Up @@ -19,9 +19,10 @@ vu8 is a project that allows one to give JavaScript access to C++ classes and me
static inline v8::Handle<v8::Value> Open() {
v8::HandleScope scope;
Module mod;
return mod("println", &Println)
return scope.Close(
mod("println", &Println)
.Set<void(), &Flush>("flush")
.NewInstance();
.NewInstance());
}

} }
Expand Down Expand Up @@ -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<bool(char const *, char const *), &Rename>("rename")
.NewInstance();
return scope.Close(
mod("Writer", fileWriter)
("Reader", fileReader)
.Set<bool(char const *, char const *), &Rename>("rename")
.NewInstance());
}

## Creating a v8 Context capable of using "vu8.load"
Expand Down
6 changes: 5 additions & 1 deletion src/vu8/Context.cpp
Expand Up @@ -63,8 +63,12 @@ v8::Handle<v8::Value> LoadModule(const v8::Arguments& args) {
context.modules_.insert(modules_t::value_type(
modName, boost::make_tuple(
dl, v8::Persistent<v8::Value>::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 {
Expand Down
3 changes: 1 addition & 2 deletions src/vu8/lib/console.cpp
Expand Up @@ -20,8 +20,7 @@ v8::Handle<v8::Value> Log(const v8::Arguments& args) {
static inline v8::Handle<v8::Value> Open() {
v8::HandleScope scope;
Module mod;
mod("log", &Log);
return mod.NewInstance();
return scope.Close(mod("log", &Log).NewInstance());
}

} }
Expand Down
4 changes: 2 additions & 2 deletions src/vu8/lib/file.cpp
Expand Up @@ -112,12 +112,12 @@ static inline v8::Handle<v8::Value> Open() {
;

Module mod;
return mod
return scope.Close(mod
("Writer", fileWriter)
("Reader", fileReader)
.Set<bool(char const *, char const *), &Rename>("rename")
.Set<bool(char const *), &Mkdir>("mkdir")
.NewInstance();
.NewInstance());
}

} }
Expand Down
4 changes: 2 additions & 2 deletions src/vu8/lib/os.cpp
Expand Up @@ -24,10 +24,10 @@ bool Signal(int const pid, int const signal) {
static inline v8::Handle<v8::Value> Open() {
v8::HandleScope scope;
Module mod;
return mod
return scope.Close(mod
.Set<char const *(char const *), &Getenv>("getenv")
.Set<bool(int const, int const), &Signal>("signal")
.NewInstance();
.NewInstance());
}

} }
Expand Down
1 change: 1 addition & 0 deletions 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')
Expand Down

0 comments on commit 3deafd6

Please sign in to comment.