Permalink
Browse files

add a `persistent` option to writeObject()

This makes it so that `MakeWeak()` is *not* called on the Persistent<Object>
handle, leaving it up to you to make sure to call `Dispose()` on it at some
point (ref doesn't expose a binding to that function... yet... so you'll have
to figure out exactly how to invoke it for now).

This is a somewhat experimental feature...
  • Loading branch information...
1 parent 0eba2ca commit 11067084b043e16e2b172f54943b2a158bd7f3b1 @TooTallNate committed Feb 2, 2013
Showing with 7 additions and 4 deletions.
  1. +3 −3 lib/ref.js
  2. +4 −1 src/binding.cc
View
@@ -699,9 +699,9 @@ exports._writeObject = exports.writeObject
* @param {Object} object The Object to be written into _buffer_.
*/
-exports.writeObject = function writeObject (buf, offset, obj) {
- debug('writing Object to buffer', buf, offset, obj)
- exports._writeObject(buf, offset, obj)
+exports.writeObject = function writeObject (buf, offset, obj, persistent) {
+ debug('writing Object to buffer', buf, offset, obj, persistent)
+ exports._writeObject(buf, offset, obj, persistent)
exports._attach(buf, obj)
}
View
@@ -186,7 +186,10 @@ Handle<Value> WriteObject(const Arguments& args) {
char *ptr = Buffer::Data(buf.As<Object>()) + offset;
Persistent<Value> obj = Persistent<Value>::New(args[2]);
- obj.MakeWeak(NULL, write_object_cb);
+
+ bool persistent = args[3]->BooleanValue();
+ if (!persistent) obj.MakeWeak(NULL, write_object_cb);
+
*reinterpret_cast<Persistent<Value>*>(ptr) = obj;
return Undefined();

0 comments on commit 1106708

Please sign in to comment.