Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make convert_to_js() return a JSBool, to allow error reporting.

  • Loading branch information...
commit a5d745efe6756fdabde4f374e3d06c8683dceab9 1 parent 2f84e5e
@matthewd matthewd authored
View
78 ext/spidermonkey/conversions.c
@@ -36,56 +36,70 @@ static jsval convert_regexp_to_js(OurContext* context, VALUE regexp)
options));
}
-jsval convert_to_js(OurContext* context, VALUE ruby)
+JSBool convert_to_js(OurContext* context, VALUE ruby, jsval* retval)
{
switch(TYPE(ruby))
{
case T_NIL:
- return JSVAL_NULL;
+ *retval = JSVAL_NULL;
+ return JS_TRUE;
- case T_TRUE:
- return JSVAL_TRUE;
+ case T_TRUE:
+ *retval = JSVAL_TRUE;
+ return JS_TRUE;
- case T_FALSE:
- return JSVAL_FALSE;
+ case T_FALSE:
+ *retval = JSVAL_FALSE;
+ return JS_TRUE;
- case T_STRING:
- return STRING_TO_JSVAL(JS_NewStringCopyZ(context->js, StringValuePtr(ruby)));
+ case T_STRING:
+ *retval = STRING_TO_JSVAL(JS_NewStringCopyZ(context->js, StringValuePtr(ruby)));
+ return JS_TRUE;
- case T_FIXNUM:
- return INT_TO_JSVAL(NUM2INT(ruby));
+ case T_FIXNUM:
+ *retval = INT_TO_JSVAL(NUM2INT(ruby));
+ return JS_TRUE;
- case T_FLOAT:
- case T_BIGNUM:
- return convert_float_or_bignum_to_js(context, ruby);
+ case T_FLOAT:
+ case T_BIGNUM:
+ *retval = convert_float_or_bignum_to_js(context, ruby);
+ return JS_TRUE;
case T_SYMBOL:
- return convert_symbol_to_js(context, ruby);
-
- case T_CLASS:
- case T_ARRAY:
- case T_HASH:
- case T_MODULE:
- case T_FILE:
- case T_STRUCT:
+ *retval = convert_symbol_to_js(context, ruby);
+ return JS_TRUE;
+
+ case T_CLASS:
+ case T_ARRAY:
+ case T_HASH:
+ case T_MODULE:
+ case T_FILE:
+ case T_STRUCT:
case T_OBJECT:
- return make_js_land_proxy(context, ruby);
+ *retval = make_js_land_proxy(context, ruby);
+ return JS_TRUE;
- case T_REGEXP:
- return convert_regexp_to_js(context, ruby);
-
- case T_DATA: // HEY! keep T_DATA last for fall-through
- if (ruby_value_is_proxy(ruby))
- return unwrap_ruby_land_proxy(context, ruby);
-
- if (rb_cProc == rb_class_of(ruby) || rb_cMethod == rb_class_of(ruby))
- return make_js_land_proxy(context, ruby);
+ case T_REGEXP:
+ *retval = convert_regexp_to_js(context, ruby);
+ return JS_TRUE;
+
+ case T_DATA: // HEY! keep T_DATA last for fall-through
+ if (ruby_value_is_proxy(ruby)) {
+ *retval = unwrap_ruby_land_proxy(context, ruby);
+ return JS_TRUE;
+ }
+
+ if (rb_cProc == rb_class_of(ruby) || rb_cMethod == rb_class_of(ruby)) {
+ *retval = make_js_land_proxy(context, ruby);
+ return JS_TRUE;
+ }
default:
Johnson_Error_raise("unknown ruby type in switch");
}
- return JSVAL_NULL;
+ *retval = JSVAL_NULL;
+ return JS_TRUE;
}
static VALUE convert_regexp_to_ruby(OurContext* context, jsval regexp)
View
2  ext/spidermonkey/conversions.h
@@ -4,7 +4,7 @@
#include "spidermonkey.h"
#include "context.h"
-jsval convert_to_js(OurContext* context, VALUE ruby);
+JSBool convert_to_js(OurContext* context, VALUE ruby, jsval* retval);
VALUE convert_to_ruby(OurContext* context, jsval js);
#endif
View
42 ext/spidermonkey/js_land_proxy.c
@@ -14,7 +14,7 @@ static JSClass JSLandProxyClass = {
get,
set,
JS_EnumerateStub,
- resolve,
+ (JSResolveOp)resolve,
JS_ConvertStub,
finalize
};
@@ -145,8 +145,8 @@ static JSBool get(JSContext* js_context, JSObject* obj, jsval id, jsval* retval)
if (JSVAL_IS_INT(id))
{
if (indexable_p(self))
- *retval = convert_to_js(context,
- rb_funcall(self, rb_intern("[]"), 1, INT2FIX(JSVAL_TO_INT(id))));
+ return convert_to_js(context,
+ rb_funcall(self, rb_intern("[]"), 1, INT2FIX(JSVAL_TO_INT(id))), retval);
return JS_TRUE;
}
@@ -179,9 +179,9 @@ static JSBool get(JSContext* js_context, JSObject* obj, jsval id, jsval* retval)
else if (autovivified_p(ruby_context, self, name))
{
- *retval = convert_to_js(context,
+ return convert_to_js(context,
rb_funcall(Johnson_SpiderMonkey_JSLandProxy(),
- rb_intern("autovivified"), 2, self, rb_str_new2(name)));
+ rb_intern("autovivified"), 2, self, rb_str_new2(name)), retval);
}
// if the Ruby object is a Module or Class and has a matching
@@ -189,14 +189,14 @@ static JSBool get(JSContext* js_context, JSObject* obj, jsval id, jsval* retval)
else if (const_p(self, name))
{
- *retval = convert_to_js(context,
- rb_funcall(self, rb_intern("const_get"), 1, ID2SYM(ruby_id)));
+ return convert_to_js(context,
+ rb_funcall(self, rb_intern("const_get"), 1, ID2SYM(ruby_id)), retval);
}
// otherwise, if it's a global, return the global
else if (global_p(name))
{
- *retval = convert_to_js(context, rb_gv_get(name));
+ return convert_to_js(context, rb_gv_get(name), retval);
}
// otherwise, if the Ruby object has a an attribute method matching
@@ -205,7 +205,7 @@ static JSBool get(JSContext* js_context, JSObject* obj, jsval id, jsval* retval)
else if (attribute_p(self, name))
{
VALUE method = rb_funcall(self, rb_intern("method"), 1, ID2SYM(ruby_id));
- *retval = convert_to_js(context, rb_funcall(self, ruby_id, 0));
+ return convert_to_js(context, rb_funcall(self, ruby_id, 0), retval);
}
// otherwise, if the Ruby object quacks sorta like a hash (it responds to
@@ -213,7 +213,7 @@ static JSBool get(JSContext* js_context, JSObject* obj, jsval id, jsval* retval)
else if (has_key_p(self, name))
{
- *retval = convert_to_js(context, rb_funcall(self, rb_intern("[]"), 1, rb_str_new2(name)));
+ return convert_to_js(context, rb_funcall(self, rb_intern("[]"), 1, rb_str_new2(name)), retval);
}
// otherwise, it's a method being accessed as a property, which means
@@ -224,8 +224,8 @@ static JSBool get(JSContext* js_context, JSObject* obj, jsval id, jsval* retval)
else if (method_p(self, name))
{
- *retval = convert_to_js(context,
- rb_funcall(self, rb_intern("method"), 1, rb_str_new2(name)));
+ convert_to_js(context,
+ rb_funcall(self, rb_intern("method"), 1, rb_str_new2(name)), retval);
}
// else it's undefined (JS_VOID) by default
@@ -315,11 +315,9 @@ static JSBool construct(JSContext* js_context, JSObject* obj, uintN argc, jsval*
for (i = 0; i < argc; ++i)
rb_ary_push(args, convert_to_ruby(context, argv[i]));
- *retval = convert_to_js(context,
+ return convert_to_js(context,
rb_funcall(Johnson_SpiderMonkey_JSLandProxy(), rb_intern("send_with_possible_block"),
- 3, klass, ID2SYM(rb_intern("new")), args));
-
- return JS_TRUE;
+ 3, klass, ID2SYM(rb_intern("new")), args), retval);
}
static JSBool resolve(JSContext *js_context, JSObject *obj, jsval id, uintN flags, JSObject **objp)
@@ -360,11 +358,9 @@ static JSBool method_missing(JSContext* js_context, JSObject* obj, uintN argc, j
// FIXME: this is horrible and lazy, to_a comes from enumerable on proxy (argv[1] is a JSArray)
VALUE args = rb_funcall(convert_to_ruby(context, argv[1]), rb_intern("to_a"), 0);
- *retval = convert_to_js(context,
+ return convert_to_js(context,
rb_funcall(Johnson_SpiderMonkey_JSLandProxy(), rb_intern("send_with_possible_block"),
- 3, self, ID2SYM(ruby_id), args));
-
- return JS_TRUE;
+ 3, self, ID2SYM(ruby_id), args), retval);
}
static JSBool call(JSContext* js_context, JSObject* obj, uintN argc, jsval* argv, jsval* retval)
@@ -384,11 +380,9 @@ static JSBool call(JSContext* js_context, JSObject* obj, uintN argc, jsval* argv
for (i = 0; i < argc; ++i)
rb_ary_push(args, convert_to_ruby(context, argv[i]));
- *retval = convert_to_js(context,
+ return convert_to_js(context,
rb_funcall(Johnson_SpiderMonkey_JSLandProxy(), rb_intern("send_with_possible_block"),
- 3, self, ID2SYM(rb_intern("call")), args));
-
- return JS_TRUE;
+ 3, self, ID2SYM(rb_intern("call")), args), retval);
}
JSBool js_value_is_proxy(OurContext* context, jsval maybe_proxy)
View
10 ext/spidermonkey/ruby_land_proxy.c
@@ -31,7 +31,8 @@ set(VALUE self, VALUE name, VALUE value)
RubyLandProxy* proxy;
Data_Get_Struct(self, RubyLandProxy, proxy);
- jsval js_value = convert_to_js(proxy->context, value);
+ jsval js_value;
+ assert(convert_to_js(proxy->context, value, &js_value));
switch(TYPE(name)) {
case T_FIXNUM:
@@ -86,12 +87,13 @@ native_call(int argc, VALUE* argv, VALUE self)
RubyLandProxy* proxy;
Data_Get_Struct(self, RubyLandProxy, proxy);
- jsval global = convert_to_js(proxy->context, argv[0]);
+ jsval global;
+ assert(convert_to_js(proxy->context, argv[0], &global));
jsval args[argc - 1];
int i;
for(i = 1; i < argc; ++i)
- args[i - 1] = convert_to_js(proxy->context, argv[i]);
+ assert(convert_to_js(proxy->context, argv[i], &(args[i - 1])));
jsval js;
@@ -229,7 +231,7 @@ call_function_property(int argc, VALUE* argv, VALUE self)
int i;
for(i = 1; i < argc; ++i)
- args[i - 1] = convert_to_js(proxy->context, argv[i]);
+ assert(convert_to_js(proxy->context, argv[i], &(args[i - 1])));
jsval js;
Please sign in to comment.
Something went wrong with that request. Please try again.