Permalink
Browse files

Merge commit '3e6f0b5' into unstable

* commit '3e6f0b5':
  Use rb_rescue2() instead of playing with ruby_errinfo.
  • Loading branch information...
2 parents 5f41ab7 + 3e6f0b5 commit 51afedb658d9b6705e255f7bd33f5596a19857b9 @matthewd matthewd committed Jul 12, 2010
Showing with 36 additions and 47 deletions.
  1. +18 −28 ext/tracemonkey/conversions.cc
  2. +3 −1 ext/tracemonkey/conversions.h
  3. +3 −13 ext/tracemonkey/jroot.h
  4. +12 −5 ext/tracemonkey/js_land_proxy.cc
View
46 ext/tracemonkey/conversions.cc
@@ -326,40 +326,30 @@ NORETURN(void) raise_js_error_in_ruby(JohnsonRuntime* runtime)
#define TAG_RAISE 0x6
#define TAG_THROW 0x7
-JSBool report_ruby_error_in_js(JohnsonRuntime* runtime, int state, VALUE old_errinfo)
+JSBool report_ruby_error_in_js(JohnsonRuntime* runtime, VALUE local_error)
{
JSContext * context = johnson_get_current_context(runtime);
- assert(state);
- switch (state)
- {
- case TAG_RAISE:
- {
- VALUE local_error = ruby_errinfo;
- ruby_errinfo = old_errinfo;
- if (rb_funcall(local_error, rb_intern("respond_to?"), 1, ID2SYM(rb_intern("copy_ruby_stack_to_deck"))))
- rb_funcall(local_error, rb_intern("copy_ruby_stack_to_deck"), 0);
+ if (rb_funcall(local_error, rb_intern("respond_to?"), 1, ID2SYM(rb_intern("copy_ruby_stack_to_deck"))))
+ rb_funcall(local_error, rb_intern("copy_ruby_stack_to_deck"), 0);
- VALUE rb_runtime = (VALUE)JS_GetRuntimePrivate(runtime->js);
- rb_iv_set(local_error, "@js_stack", rb_funcall(rb_runtime, rb_intern("current_stack"), 0));
+ VALUE rb_runtime = (VALUE)JS_GetRuntimePrivate(runtime->js);
+ rb_iv_set(local_error, "@js_stack", rb_funcall(rb_runtime, rb_intern("current_stack"), 0));
- jsval js_error;
- convert_to_js(runtime, local_error, &js_error);
- JS_SetPendingException(context, js_error);
+ jsval js_error;
+ convert_to_js(runtime, local_error, &js_error);
+ JS_SetPendingException(context, js_error);
- return JS_FALSE ;
- }
-
- case TAG_THROW:
- // FIXME: This should be propagated to JS... as an exception?
+ return JS_FALSE;
+}
- default:
- {
- JSString* str = JS_NewStringCopyZ(context, "Unexpected longjmp from ruby!");
- if (str)
- JS_SetPendingException(context, STRING_TO_JSVAL(str));
- return JS_FALSE;
- }
- }
+VALUE jprotect_error_handler(VALUE caller_info, VALUE exception) {
+ jroot_info_t *_jroot = (jroot_info_t*)caller_info;
+ REMOVE_JROOTS;
+ if (_jroot->ruby)
+ rb_exc_raise(exception);
+ else
+ report_ruby_error_in_js(OUR_RUNTIME(_jroot->context), exception);
+ return caller_info;
}
View
4 ext/tracemonkey/conversions.h
@@ -27,6 +27,8 @@ VALUE convert_to_ruby(JohnsonRuntime* runtime, jsval js);
VALUE convert_js_string_to_ruby(JohnsonRuntime* runtime, JSString* str);
NORETURN(void raise_js_error_in_ruby(JohnsonRuntime* runtime));
-JSBool report_ruby_error_in_js(JohnsonRuntime* runtime, int state, VALUE old_errinfo);
+JSBool report_ruby_error_in_js(JohnsonRuntime* runtime, VALUE old_errinfo);
+
+VALUE jprotect_error_handler(VALUE caller_info, VALUE exception);
#endif
View
16 ext/tracemonkey/jroot.h
@@ -22,7 +22,7 @@
Data_Get_Struct(_ruby_runtime, JohnsonRuntime, _johnson_runtime); \
_johnson_runtime; \
})
-
+
typedef struct {
void (*func)(JSContext*, void*);
@@ -127,20 +127,10 @@ typedef struct {
#define _JPROTECT(func, data, cast) \
({ \
- int _state; \
- const VALUE _old_errinfo = ruby_errinfo; \
- const VALUE _result = rb_protect((func), (data), &_state); \
- if (_state) \
- { \
- REMOVE_JROOTS; \
- if (_jroot->ruby) \
- rb_jump_tag(_state); \
- else \
- return cast(report_ruby_error_in_js(OUR_RUNTIME(_jroot->context), _state, _old_errinfo)); \
- } \
+ const VALUE _result = rb_rescue2((VALUE(*)(ANYARGS))(func), (data), (VALUE(*)(ANYARGS))&jprotect_error_handler, (VALUE)(_jroot), rb_cObject, 0); \
+ if (!_jroot->ruby && _result == (VALUE)(_jroot)) return cast(JS_FALSE); \
_result; \
})
-
#define JPROTECT(func, data) \
_JPROTECT(func, data, )
#define JPROTECT_T(T, func, data) \
View
17 ext/tracemonkey/js_land_proxy.cc
@@ -58,9 +58,14 @@ static VALUE call_ruby_from_js_invoke(VALUE args)
return rb_apply(self, SYM2ID(id), args);
}
+VALUE call_ruby_from_js_err(VALUE runtime_ptr, VALUE exception)
+{
+ report_ruby_error_in_js((JohnsonRuntime*)runtime_ptr, exception);
+ return runtime_ptr;
+}
+
JSBool call_ruby_from_js_va(JohnsonRuntime* runtime, VALUE* result, VALUE self, ID id, int argc, va_list va)
{
- VALUE old_errinfo = ruby_errinfo;
VALUE args = rb_ary_new2((long)argc + 2);
long i;
@@ -70,11 +75,13 @@ JSBool call_ruby_from_js_va(JohnsonRuntime* runtime, VALUE* result, VALUE self,
rb_ary_store(args, (long)argc, ID2SYM(id));
rb_ary_store(args, (long)argc + 1, self);
- int state;
- *result = rb_protect(call_ruby_from_js_invoke, args, &state);
+ VALUE rt_ptr = (VALUE)runtime;
+
+ VALUE temp = rb_rescue2((VALUE(*)(ANYARGS))call_ruby_from_js_invoke, args, (VALUE(*)(ANYARGS))call_ruby_from_js_err, rt_ptr, rb_cObject, 0);
+ if (temp == rt_ptr)
+ return JS_FALSE;
- if (state)
- return report_ruby_error_in_js(runtime, state, old_errinfo);
+ *result = temp;
return JS_TRUE;
}

0 comments on commit 51afedb

Please sign in to comment.