Skip to content

Commit

Permalink
add test case for exception from C++ ctor
Browse files Browse the repository at this point in the history
Idea suggested by pull-request #99
  • Loading branch information
pmed committed Oct 20, 2018
1 parent a159a8e commit 131f50a
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion test/test_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,15 @@ template<typename Traits, typename X_ptr = typename v8pp::class_<X, Traits>::obj
static X_ptr create_X(v8::FunctionCallbackInfo<v8::Value> const& args)
{
X_ptr x(new X);
if (args.Length() > 0)
switch (args.Length())
{
case 1:
x->var = v8pp::from_v8<int>(args.GetIsolate(), args[0]);
break;
case 2:
throw std::runtime_error("C++ exception");
case 3:
v8pp::throw_ex(args.GetIsolate(), "JS exception");
}
return x;
}
Expand Down Expand Up @@ -168,6 +174,13 @@ void test_class_()
.set("Y", Y_class)
;

check_eq("C++ exception from X ctor",
run_script<std::string>(context, "ret = ''; try { new X(1, 2); } catch(err) { ret = err; } ret"),
"C++ exception");
check_eq("V8 exception from X ctor",
run_script<std::string>(context, "ret = ''; try { new X(1, 2, 3); } catch(err) { ret = err; } ret"),
"JS exception");

check_eq("X object", run_script<int>(context, "x = new X(); x.var += x.konst"), 100);
check_eq("X::rprop", run_script<int>(context, "x = new X(); x.rprop"), 1);
check_eq("X::wprop", run_script<int>(context, "x = new X(); ++x.wprop"), 2);
Expand Down

0 comments on commit 131f50a

Please sign in to comment.