ext/h8/main.cpp in h8-0.2.5 vs ext/h8/main.cpp in h8-0.3.0

- old
+ new

@@ -19,11 +19,16 @@ VALUE protect_ruby(const std::function<VALUE()> &block) { try { return block(); } catch (JsError& e) { - e.raise(); + try { + e.raise(); + } + catch(...) { + rb_raise(js_exception, "error while converting JS exception (pls report a bug)"); + } } catch (...) { rb_raise(rb_eStandardError, "unknown error in JS"); } return Qnil; } @@ -124,17 +129,18 @@ H8 *prcxt; Data_Get_Struct(self, H8, prcxt); return prcxt; } -static VALUE context_eval(VALUE self, VALUE script,VALUE timeout,VALUE script_name_ruby) { +static VALUE context_eval(VALUE self, VALUE script, VALUE timeout, + VALUE script_name_ruby) { return protect_ruby([&] { - H8* cxt = rc(self);// v8::Locker l(cxt->getIsolate()); - H8::Scope s(cxt); - const char* script_name = script_name_ruby != Qnil ? StringValueCStr(script_name_ruby) : NULL; - return cxt->eval_to_ruby(StringValueCStr(script), FIX2INT(timeout), script_name); - }); + H8* cxt = rc(self); // v8::Locker l(cxt->getIsolate()); + H8::Scope s(cxt); + const char* script_name = script_name_ruby != Qnil ? StringValueCStr(script_name_ruby) : NULL; + return cxt->eval_to_ruby(StringValueCStr(script), FIX2INT(timeout), script_name); + }); } static VALUE context_set_var(VALUE self, VALUE name, VALUE value) { return protect_ruby([&] { rc(self)->set_var(name, value); @@ -183,11 +189,12 @@ ruby_gate_class = rb_define_class_under(h8, "RubyGate", rb_cObject); rb_define_alloc_func(context_class, context_alloc); rb_define_method(context_class, "_eval", (ruby_method) context_eval, 3); rb_define_method(context_class, "_set_var", (ruby_method) context_set_var, 2); - rb_define_method(context_class, "javascript_gc", (ruby_method) context_force_gc, 0); + rb_define_method(context_class, "javascript_gc", + (ruby_method) context_force_gc, 0); value_class = rb_define_class_under(h8, "Value", rb_cObject); rb_define_alloc_func(value_class, rvalue_alloc); rb_define_method(value_class, "to_s", (ruby_method) rvalue_to_s, 0); rb_define_method(value_class, "to_i", (ruby_method) rvalue_to_i, 0); @@ -212,10 +219,11 @@ rb_define_method(value_class, "context", (ruby_method) rvalue_get_ruby_context, 0); h8_exception = rb_define_class_under(h8, "Error", rb_eStandardError); js_exception = rb_define_class_under(h8, "JsError", h8_exception); - js_timeout_exception = rb_define_class_under(h8, "TimeoutError", js_exception); + js_timeout_exception = rb_define_class_under(h8, "TimeoutError", + js_exception); VALUE u_class = rb_define_class_under(h8, "UndefinedClass", rb_cObject); Rundefined = rb_funcall(u_class, rb_intern("instance"), 0); }