eo_js: Instead of abort, throw an Exception

* When the constructor fails
* On cast error.
This commit is contained in:
Lauro Moura 2016-07-11 16:38:40 -03:00 committed by Felipe Magno de Almeida
parent c364844f67
commit c08eedfd11
2 changed files with 28 additions and 18 deletions

View File

@ -917,25 +917,32 @@ compatibility_return_type cast_function(compatibility_callback_info_type args)
auto isolate = args.GetIsolate();
compatibility_handle_scope scope(isolate);
v8::Local<v8::Value> type;
if(args.Length() == 1 && (type = args[0])->IsString())
try
{
v8::Local<v8::Object> self = args.This();
v8::Local<v8::Value> external = self->GetInternalField(0);
Eo* eo = static_cast<Eo*>(v8::External::Cast(*external)->Value());
if(args.Length() == 1 && (type = args[0])->IsString())
{
v8::Local<v8::Object> self = args.This();
v8::Local<v8::Value> external = self->GetInternalField(0);
Eo* eo = static_cast<Eo*>(v8::External::Cast(*external)->Value());
v8::String::Utf8Value str(type->ToString());
char* class_name = *str;
v8::String::Utf8Value str(type->ToString());
char* class_name = *str;
auto ctor = ::efl::eina::js::get_class_constructor(class_name);
auto obj = new_v8_external_instance(ctor, ::eo_ref(eo), isolate);
efl::eina::js::make_weak(isolate, obj, [eo]{ ::eo_unref(eo); });
return compatibility_return(obj, args);
auto ctor = ::efl::eina::js::get_class_constructor(class_name);
auto obj = new_v8_external_instance(ctor, ::eo_ref(eo), isolate);
efl::eina::js::make_weak(isolate, obj, [eo]{ ::eo_unref(eo); });
return compatibility_return(obj, args);
}
else
{
throw std::runtime_error("Type expected is different. Expected String type");
}
}
else
catch (std::runtime_error const& error)
{
eina::js::compatibility_throw
(isolate, v8::Exception::TypeError
(eina::js::compatibility_new<v8::String>(isolate, "Type expected is different. Expected String type")));
(eina::js::compatibility_new<v8::String>(isolate, error.what())));
return compatibility_return();
}
}

View File

@ -68,10 +68,7 @@ struct constructor_caller
}
else
{
eina::js::compatibility_throw
(v8::Exception::TypeError
(eina::js::compatibility_new<v8::String>(args->GetIsolate(), "Expected more arguments for this call")));
throw std::logic_error("");
throw std::logic_error("Expected more arguments for this call");
}
}
@ -114,7 +111,8 @@ struct constructor_caller
, parent
, eina::_mpl::for_each(constructors, call{eo_self, &current_index, &args})
);
assert(eo != 0);
if (!eo)
throw std::logic_error("Failed to create object.");
v8::Local<v8::Object> self = args.This();
self->SetInternalField(0, eina::js::compatibility_new<v8::External>(args.GetIsolate(), eo));
efl::eina::js::make_weak(args.GetIsolate(), self
@ -123,7 +121,12 @@ struct constructor_caller
eo_unref(eo);
});
}
catch(std::logic_error const&) {}
catch(std::logic_error const& error)
{
eina::js::compatibility_throw
(v8::Exception::TypeError
(eina::js::compatibility_new<v8::String>(args.GetIsolate(), error.what())));
}
}
else
{