Permalink
Browse files

openRead() without segfaulting

  • Loading branch information...
1 parent 8341a68 commit 5b5eecd08c2263c8fb3605be4cf57f685d88d614 @substack committed Jul 6, 2012
Showing with 6 additions and 7 deletions.
  1. +6 −7 src/format.cc
View
@@ -18,12 +18,12 @@ class Format : public ObjectWrap {
constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
constructor_template->SetClassName(String::NewSymbol("Format"));
+ NODE_SET_PROTOTYPE_METHOD(constructor_template, "openRead", OpenRead);
+
target->Set(
String::NewSymbol("Format"),
constructor_template->GetFunction()
);
-
- NODE_SET_METHOD(target, "openRead", OpenRead);
}
static Handle<Value> New(const Arguments &args) {
@@ -35,13 +35,12 @@ class Format : public ObjectWrap {
static Handle<Value> OpenRead(const Arguments &args) {
HandleScope scope;
- Handle<Object> h = constructor_template->GetFunction()->New();
- Format *obj = ObjectWrap::Unwrap<Format>(h);
-
+ Format *fmt = ObjectWrap::Unwrap<Format>(args.This());
String::Utf8Value path(args[0]);
- obj->format = sox_open_read(*path, NULL, NULL, NULL);
+ fmt->format = sox_open_read(*path, NULL, NULL, NULL);
+ fmt->Ref();
- return h;
+ return Undefined();
}
};

0 comments on commit 5b5eecd

Please sign in to comment.