aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2016-07-11 16:38:40 -0300
committerLauro Moura <lauromoura@expertisesolutions.com.br>2016-08-01 20:14:32 -0300
commitff82752590a4d73fcadb486a3d7e0388f0bec782 (patch)
treec4c293e2f433037c5d03f88063cb693f9e3796ec
parenteolian-js: Fix dependency on Ecore.eo.hh (diff)
downloadefl-ff82752590a4d73fcadb486a3d7e0388f0bec782.tar.gz
eo_js: Instead of abort, throw an Exception
* When the constructor fails * On cast error.
-rw-r--r--src/bindings/js/eina_js/eina_js_compatibility.hh35
-rw-r--r--src/bindings/js/eo_js/eo_js_constructor.hh15
2 files changed, 30 insertions, 20 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<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());
-
- 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);
+ 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;
+
+ 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();
}
}
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<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
{