felipealmeida pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=c08eedfd11c7aed67bc5341d5cdb08765919ad24

commit c08eedfd11c7aed67bc5341d5cdb08765919ad24
Author: Lauro Moura <lauromo...@expertisesolutions.com.br>
Date:   Mon Jul 11 16:38:40 2016 -0300

    eo_js: Instead of abort, throw an Exception
    
    * When the constructor fails
    * On cast error.
---
 src/bindings/js/eina_js/eina_js_compatibility.hh | 35 ++++++++++++++----------
 src/bindings/js/eo_js/eo_js_constructor.hh       | 15 ++++++----
 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)
   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 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
         }
       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
       {

-- 


Reply via email to