37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'opal/opal/corelib/object_space.rb', line 37
def define_finalizer(obj, aproc = undefined, &block)
%x{
if ($truthy(block)) aproc = block;
if (!$truthy(aproc)) aproc = #{::Kernel.proc};
if (!$respond_to(aproc, '$call')) {
#{::Kernel.raise ::ArgumentError, "Wrong type argument #{aproc.class} (should be callable)"};
}
var id = #{obj.__id__};
add_caller(id, aproc);
try {
registry.register(obj, id, obj);
}
catch (e) {
delete_callers(id);
#{::Kernel.raise ::ArgumentError, "cannot define finalizer for #{obj.class}"};
}
return [0, aproc];
}
end
|