From c08eedfd11c7aed67bc5341d5cdb08765919ad24 Mon Sep 17 00:00:00 2001 From: Lauro Moura Date: Mon, 11 Jul 2016 16:38:40 -0300 Subject: [PATCH] eo_js: Instead of abort, throw an Exception * When the constructor fails * On cast error. --- .../js/eina_js/eina_js_compatibility.hh | 31 ++++++++++++------- src/bindings/js/eo_js/eo_js_constructor.hh | 15 +++++---- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/bindings/js/eina_js/eina_js_compatibility.hh b/src/bindings/js/eina_js/eina_js_compatibility.hh index 7a4671424c..48cebc5738 100644 --- a/src/bindings/js/eina_js/eina_js_compatibility.hh +++ b/src/bindings/js/eina_js/eina_js_compatibility.hh @@ -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 type; - if(args.Length() == 1 && (type = args[0])->IsString()) + try { - v8::Local self = args.This(); - v8::Local external = self->GetInternalField(0); - Eo* eo = static_cast(v8::External::Cast(*external)->Value()); + if(args.Length() == 1 && (type = args[0])->IsString()) + { + v8::Local self = args.This(); + v8::Local external = self->GetInternalField(0); + Eo* eo = static_cast(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(isolate, "Type expected is different. Expected String type"))); + (eina::js::compatibility_new(isolate, error.what()))); return compatibility_return(); } } diff --git a/src/bindings/js/eo_js/eo_js_constructor.hh b/src/bindings/js/eo_js/eo_js_constructor.hh index 6ca02ce533..497f626789 100644 --- a/src/bindings/js/eo_js/eo_js_constructor.hh +++ b/src/bindings/js/eo_js/eo_js_constructor.hh @@ -68,10 +68,7 @@ struct constructor_caller } else { - eina::js::compatibility_throw - (v8::Exception::TypeError - (eina::js::compatibility_new(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, ¤t_index, &args}) ); - assert(eo != 0); + if (!eo) + throw std::logic_error("Failed to create object."); v8::Local self = args.This(); self->SetInternalField(0, eina::js::compatibility_new(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(args.GetIsolate(), error.what()))); + } } else {