Skip to content
This repository has been archived by the owner on Aug 18, 2018. It is now read-only.

Commit

Permalink
Cover a couple more Ruby exception possibilities.
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewd committed Apr 28, 2008
1 parent 15f8763 commit 0c24c6c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 27 deletions.
13 changes: 5 additions & 8 deletions ext/spidermonkey/conversions.c
Expand Up @@ -12,7 +12,7 @@ static JSBool convert_symbol_to_js(OurContext* context, VALUE symbol, jsval* ret
{
PREPARE_JROOTS(context, 2, 0);

VALUE to_s = rb_funcall(symbol, rb_intern("to_s"), 0);
VALUE to_s = JPROTECT(rb_funcall(symbol, rb_intern("to_s"), 0));
jsval name = STRING_TO_JSVAL(JS_NewStringCopyN(context->js, StringValuePtr(to_s), (unsigned) StringValueLen(to_s)));

JROOT(name);
Expand Down Expand Up @@ -116,9 +116,8 @@ VALUE convert_jsstring_to_ruby(OurContext* context, JSString* str)
PREPARE_RUBY_JROOTS(context, 1, 0);
JROOT(str);
char* bytes = JS_GetStringBytes(str);
assert(bytes);
VALUE result = rb_str_new(bytes, (signed)JS_GetStringLength(str));
JRETURN_RUBY(result);
JCHECK(bytes);
JRETURN_RUBY(JPROTECT(rb_str_new(bytes, (signed)JS_GetStringLength(str))));
}

static VALUE convert_regexp_to_ruby(OurContext* context, jsval regexp)
Expand All @@ -127,11 +126,9 @@ static VALUE convert_regexp_to_ruby(OurContext* context, jsval regexp)
JROOT(regexp);
JSRegExp* re = (JSRegExp*)JS_GetPrivate(context->js, JSVAL_TO_OBJECT(regexp));

VALUE result = rb_funcall(rb_cRegexp, rb_intern("new"), 2,
JRETURN_RUBY(JPROTECT(rb_funcall(rb_cRegexp, rb_intern("new"), 2,
convert_jsstring_to_ruby(context, re->source),
INT2NUM(re->flags));

JRETURN_RUBY(result);
INT2NUM(re->flags))));
}

static bool js_value_is_regexp(OurContext* context, jsval maybe_regexp)
Expand Down
26 changes: 7 additions & 19 deletions ext/spidermonkey/ruby_land_proxy.c
Expand Up @@ -26,7 +26,7 @@ static VALUE call_js_function_value(OurContext* context, jsval target, jsval fun
JCHECK(JS_CallFunctionValue(context->js,
JSVAL_TO_OBJECT(target), function, (unsigned) argc, args, &result));

JRETURN_RUBY(convert_to_ruby(context, result));
JRETURN_RUBY(JPROTECT(convert_to_ruby(context, result)));
}

static VALUE /* [] */
Expand All @@ -53,7 +53,7 @@ get(VALUE self, VALUE name)
break;
}

JRETURN_RUBY(convert_to_ruby(proxy->context, js_value));
JRETURN_RUBY(JPROTECT(convert_to_ruby(proxy->context, js_value)));
}

static VALUE /* []= */
Expand Down Expand Up @@ -117,7 +117,7 @@ respond_to_p(VALUE self, VALUE sym)

JCHECK(JS_HasProperty(proxy->context->js, obj, name, &found));

JRETURN_RUBY(found ? Qtrue : rb_call_super(1, &sym));
JRETURN_RUBY(found ? Qtrue : JPROTECT(rb_call_super(1, &sym)));
}

/* private */ static VALUE /* native_call(global, *args) */
Expand Down Expand Up @@ -163,14 +163,8 @@ each(VALUE self)
for (i = 0; i < length; ++i)
{
jsval element;
int state;
JCHECK(JS_GetElement(proxy->context->js, value, (signed) i, &element));
rb_protect(rb_yield, convert_to_ruby(proxy->context, element), &state);
if (state)
{
REMOVE_JROOTS;
rb_jump_tag(state);
}
JPROTECT(rb_yield(convert_to_ruby(proxy->context, element)));
}
}
else
Expand Down Expand Up @@ -203,16 +197,10 @@ each(VALUE self)
}
JROOT(js_value);

VALUE key = convert_to_ruby(proxy->context, js_key);
VALUE value = convert_to_ruby(proxy->context, js_value);
VALUE key = JPROTECT(convert_to_ruby(proxy->context, js_key));
VALUE value = JPROTECT(convert_to_ruby(proxy->context, js_value));

int state;
rb_protect(rb_yield, rb_ary_new3(2, key, value), &state);
if (state)
{
REMOVE_JROOTS;
rb_jump_tag(state);
}
JPROTECT(rb_yield(rb_ary_new3(2, key, value)));

JUNROOT(js_value);
JUNROOT(js_key);
Expand Down

0 comments on commit 0c24c6c

Please sign in to comment.