Skip to content

Commit

Permalink
better js exc handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tokuhirom committed Sep 17, 2012
1 parent 68af031 commit 2ad7425
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/node_object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ static mrb_value node_object_method_missing(mrb_state *mrb, mrb_value self) {
if (!mrb_nil_p(b)) {
args[alen] = rubyproc2jsfunc(mrb, b);
}
Handle<String> err;
{
TryCatch try_catch;
Local<Value> retval = Function::Cast(*elem)->Call(jsobj, alen2, args);
Expand All @@ -54,14 +55,23 @@ static mrb_value node_object_method_missing(mrb_state *mrb, mrb_value self) {
} else { // got exception
assert(try_catch.HasCaught());
Local<Value> exc(try_catch.Exception());
Local<Message> msg = try_catch.Message();
DisplayExceptionLine(try_catch);
if (*msg) {
err = msg->Get();
}
DBG("JS LEVEL Exception");
// TODO: better exception
}
}
// You need to raise exception after TryCatch object was released.
// mrb_raise calls longjmp, it doesn't call the destructor.
mrb_raise(mrb, E_RUNTIME_ERROR, "Got js exception");
if (*err) {
String::Utf8Value uerr(err);
mrb_raise(mrb, E_RUNTIME_ERROR, *uerr);
} else {
mrb_raise(mrb, E_RUNTIME_ERROR, "Unknown exception was occurred in NodeJS");
}
return mrb_undef_value(); // should not reach here
} else {
DBG("Is not a function");
Expand Down
2 changes: 1 addition & 1 deletion vendor/mruby
Submodule mruby updated 3 files
+14 −3 mrblib/numeric.rb
+16 −0 test/t/integer.rb
+1 −1 test/t/kernel.rb

0 comments on commit 2ad7425

Please sign in to comment.