summaryrefslogtreecommitdiff
path: root/src/bindings
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2016-07-11 16:38:40 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2016-10-25 12:23:34 -0200
commitc08eedfd11c7aed67bc5341d5cdb08765919ad24 (patch)
tree0a129c99065beac21787f37b4c06f82c17ea5fa7 /src/bindings
parentc364844f673c75582c6c40f1e882b2c88b71d59b (diff)
eo_js: Instead of abort, throw an Exception
* When the constructor fails * On cast error.
Diffstat (limited to 'src/bindings')
-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 7a46714..48cebc5 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)
917 auto isolate = args.GetIsolate(); 917 auto isolate = args.GetIsolate();
918 compatibility_handle_scope scope(isolate); 918 compatibility_handle_scope scope(isolate);
919 v8::Local<v8::Value> type; 919 v8::Local<v8::Value> type;
920 if(args.Length() == 1 && (type = args[0])->IsString()) 920 try
921 { 921 {
922 v8::Local<v8::Object> self = args.This(); 922 if(args.Length() == 1 && (type = args[0])->IsString())
923 v8::Local<v8::Value> external = self->GetInternalField(0); 923 {
924 Eo* eo = static_cast<Eo*>(v8::External::Cast(*external)->Value()); 924 v8::Local<v8::Object> self = args.This();
925 925 v8::Local<v8::Value> external = self->GetInternalField(0);
926 v8::String::Utf8Value str(type->ToString()); 926 Eo* eo = static_cast<Eo*>(v8::External::Cast(*external)->Value());
927 char* class_name = *str; 927
928 928 v8::String::Utf8Value str(type->ToString());
929 auto ctor = ::efl::eina::js::get_class_constructor(class_name); 929 char* class_name = *str;
930 auto obj = new_v8_external_instance(ctor, ::eo_ref(eo), isolate); 930
931 efl::eina::js::make_weak(isolate, obj, [eo]{ ::eo_unref(eo); }); 931 auto ctor = ::efl::eina::js::get_class_constructor(class_name);
932 return compatibility_return(obj, args); 932 auto obj = new_v8_external_instance(ctor, ::eo_ref(eo), isolate);
933 efl::eina::js::make_weak(isolate, obj, [eo]{ ::eo_unref(eo); });
934 return compatibility_return(obj, args);
935 }
936 else
937 {
938 throw std::runtime_error("Type expected is different. Expected String type");
939 }
933 } 940 }
934 else 941 catch (std::runtime_error const& error)
935 { 942 {
936 eina::js::compatibility_throw 943 eina::js::compatibility_throw
937 (isolate, v8::Exception::TypeError 944 (isolate, v8::Exception::TypeError
938 (eina::js::compatibility_new<v8::String>(isolate, "Type expected is different. Expected String type"))); 945 (eina::js::compatibility_new<v8::String>(isolate, error.what())));
939 return compatibility_return(); 946 return compatibility_return();
940 } 947 }
941} 948}
diff --git a/src/bindings/js/eo_js/eo_js_constructor.hh b/src/bindings/js/eo_js/eo_js_constructor.hh
index 6ca02ce..497f626 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
68 } 68 }
69 else 69 else
70 { 70 {
71 eina::js::compatibility_throw 71 throw std::logic_error("Expected more arguments for this call");
72 (v8::Exception::TypeError
73 (eina::js::compatibility_new<v8::String>(args->GetIsolate(), "Expected more arguments for this call")));
74 throw std::logic_error("");
75 } 72 }
76 } 73 }
77 74
@@ -114,7 +111,8 @@ struct constructor_caller
114 , parent 111 , parent
115 , eina::_mpl::for_each(constructors, call{eo_self, &current_index, &args}) 112 , eina::_mpl::for_each(constructors, call{eo_self, &current_index, &args})
116 ); 113 );
117 assert(eo != 0); 114 if (!eo)
115 throw std::logic_error("Failed to create object.");
118 v8::Local<v8::Object> self = args.This(); 116 v8::Local<v8::Object> self = args.This();
119 self->SetInternalField(0, eina::js::compatibility_new<v8::External>(args.GetIsolate(), eo)); 117 self->SetInternalField(0, eina::js::compatibility_new<v8::External>(args.GetIsolate(), eo));
120 efl::eina::js::make_weak(args.GetIsolate(), self 118 efl::eina::js::make_weak(args.GetIsolate(), self
@@ -123,7 +121,12 @@ struct constructor_caller
123 eo_unref(eo); 121 eo_unref(eo);
124 }); 122 });
125 } 123 }
126 catch(std::logic_error const&) {} 124 catch(std::logic_error const& error)
125 {
126 eina::js::compatibility_throw
127 (v8::Exception::TypeError
128 (eina::js::compatibility_new<v8::String>(args.GetIsolate(), error.what())));
129 }
127 } 130 }
128 else 131 else
129 { 132 {