0
@@ -9,23 +9,10 @@ DEFINE_RUBY_WRAPPER(rb_yield, rb_yield, ARGLIST1(v))
0
static VALUE proxy_class = Qnil;
0
-static
JSBool get_jsval_for_proxy(RubyLandProxy* proxy, jsval* jv)
0
+static
inline JSBool get_jsval_for_proxy(RubyLandProxy* proxy, jsval* jv)
0
- JSContext * context = johnson_get_current_context(proxy->runtime);
0
- PREPARE_JROOTS(context, 0);
0
- // FIXME: this is totally lame
0
- sprintf(global_key, "%x", (int)proxy->runtime->global);
0
- if (0 == strcmp(global_key, proxy->key))
0
- *jv = OBJECT_TO_JSVAL(proxy->runtime->global);
0
- JCHECK(JS_GetProperty(context, proxy->runtime->gcthings, proxy->key, jv));
0
+ *jv = (jsval)(proxy->key);
0
static VALUE call_js_function_value(JohnsonRuntime* runtime, jsval target, jsval function, int argc, VALUE* argv)
0
@@ -454,23 +441,21 @@ static VALUE to_s(VALUE self)
0
static void finalize(RubyLandProxy* proxy)
0
- JSContext * context = johnson_get_current_context(proxy->runtime);
0
- PREPARE_RUBY_JROOTS(context, 0);
0
- JCHECK_RUBY(get_jsval_for_proxy(proxy, &proxy_value));
0
// could get finalized after the context has been freed
0
if (proxy->runtime && proxy->runtime->jsids)
0
// remove this proxy from the OID map
0
+ get_jsval_for_proxy(proxy, &proxy_value);
0
JS_HashTableRemove(proxy->runtime->jsids, (void *)proxy_value);
0
// remove our GC handle on the JS value
0
- JS_DeleteProperty(context, proxy->runtime->gcthings, proxy->key);
0
+ JS_RemoveRootRT(proxy->runtime->js, &(proxy->key));
0
@@ -496,13 +481,11 @@ JSBool unwrap_ruby_land_proxy(JohnsonRuntime* runtime, VALUE wrapped, jsval* ret
0
VALUE make_ruby_land_proxy(JohnsonRuntime* runtime, jsval value)
0
VALUE id = (VALUE)JS_HashTableLookup(runtime->jsids, (void *)value);
0
- JSContext * context = johnson_get_current_context(runtime);
0
// if we already have a proxy, return it
0
- return rb_funcall(rb_const_get(rb_cObject,
0
- rb_intern("ObjectSpace")), rb_intern("_id2ref"), 1, id);
0
@@ -510,18 +493,19 @@ VALUE make_ruby_land_proxy(JohnsonRuntime* runtime, jsval value)
0
RubyLandProxy* our_proxy;
0
VALUE proxy = Data_Make_Struct(proxy_class, RubyLandProxy, 0, finalize, our_proxy);
0
+ JSContext * context = johnson_get_current_context(runtime);
0
PREPARE_RUBY_JROOTS(context, 1);
0
- // root the value for JS GC and lookups
0
- sprintf(our_proxy->key, "%x", (int)value);
0
- JCHECK(JS_SetProperty(context, runtime->gcthings, our_proxy->key, &value));
0
our_proxy->runtime = runtime;
0
+ our_proxy->key = (void *)value;
0
+ // root the value for JS GC and lookups
0
+ JCHECK(JS_AddNamedRootRT(runtime->js, &(our_proxy->key), "RubyLandProxy"));
0
// put the proxy OID in the id map
0
- JCHECK(JS_HashTableAdd(runtime->jsids, (void *)value, (void *)
rb_obj_id(proxy)));
0
+ JCHECK(JS_HashTableAdd(runtime->jsids, (void *)value, (void *)
proxy));
Comments
No one has commented yet.