1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00

Handle#MakeWeak() now has a signature faithful to its v8 counterpart.

This commit is contained in:
Charles Lowell 2011-04-26 11:30:17 -05:00
parent f76a9ca47f
commit 45b53341e2
3 changed files with 18 additions and 21 deletions

View file

@ -56,21 +56,23 @@ namespace {
}
void RubyWeakReferenceCallback(Persistent<Value> value, void* parameter) {
VALUE self = (VALUE)parameter;
v8_handle* handle = rr_v8_handle_raw(self);
VALUE callback = rr_v8_handle_get_internal(self, "weakref_callback");
VALUE parameters = rr_v8_handle_get_internal(self, "weakref_callback_parameters");
if (RTEST(callback)) {
rb_funcall(callback, rb_intern("call"), 2, self, parameters);
}
value.Dispose();
v8_handle* handle = rr_v8_handle_raw((VALUE)parameter);
handle->handle.Dispose();
handle->handle.Clear();
handle->dead = true;
VALUE callback = rr_v8_handle_get_internal((VALUE)parameter, "weakref_callback");
if (RTEST(callback)) {
rb_funcall(callback, rb_intern("call"), 0);
}
}
VALUE MakeWeak(VALUE self) {
VALUE callback = rb_block_given_p() ? rb_block_proc() : Qnil;
VALUE MakeWeak(VALUE self, VALUE parameters, VALUE callback) {
rr_v8_handle_set_internal(self,"weakref_callback", callback);
rr_v8_handle_set_internal(self, "weakref_callback_parameters", parameters);
rr_v8_handle<void>(self).MakeWeak((void*)self, RubyWeakReferenceCallback);
return Qnil;
}
@ -100,7 +102,7 @@ void rr_init_handle() {
rr_define_method(HandleClass, "IsEmpty", IsEmpty, 0);
rr_define_method(HandleClass, "Clear", Clear, 0);
rr_define_method(HandleClass, "Dispose", Dispose, 0);
rr_define_method(HandleClass, "MakeWeak", MakeWeak, 0);
rr_define_method(HandleClass, "MakeWeak", MakeWeak, 2);
rr_define_method(HandleClass, "ClearWeak", ClearWeak, 0);
rr_define_method(HandleClass, "IsNearDeath", IsNearDeath, 0);
rr_define_method(HandleClass, "IsWeak", IsWeak, 0);

View file

@ -39,7 +39,7 @@ module V8
@js_proxies_js2rb[proxy] = target
@js_proxies_rb2js[target] = proxy
proxy.MakeWeak(&clear_js_proxy(proxy))
proxy.MakeWeak(nil, method(:clear_js_proxy))
end
def rb_object_2_js_proxy(object)
@ -68,12 +68,10 @@ module V8
@rb_proxies_rb2js[proxy.object_id]
end
def clear_js_proxy(proxy)
lambda do
rb = @js_proxies_js2rb[proxy]
@js_proxies_js2rb.delete(proxy)
@js_proxies_rb2js.delete(rb)
end
def clear_js_proxy(proxy, parameter)
rb = @js_proxies_js2rb[proxy]
@js_proxies_js2rb.delete(proxy)
@js_proxies_rb2js.delete(rb)
end
def clear_rb_proxy(proxy_id)

View file

@ -11,7 +11,7 @@ describe "Memory:" do
it "has a strong reference from the ruby side, which is not released until the Ruby reference goes away" do
handle = c::Handle::New(object = c::Object::New())
handle.MakeWeak(&@weakref_callback)
handle.MakeWeak(nil, @weakref_callback)
ruby_gc do
v8_gc
@weakref_callback.should_not have_been_invoked
@ -28,11 +28,8 @@ describe "Memory:" do
private
class WeakrefCallback
def to_proc
method(:invoke).to_proc
end
def invoke
def call(value, parameters)
@invoked = true
end