diff options
author | VinÃcius dos Santos Oliveira <vini.ipsmaker@expertisesolutions.com.br> | 2014-10-07 03:52:31 -0300 |
---|---|---|
committer | VinÃcius dos Santos Oliveira <vini.ipsmaker@expertisesolutions.com.br> | 2015-01-02 16:50:12 -0300 |
commit | 5c9ffed096ee8a20b6ab0face4a5bc2b8ea1a55d (patch) | |
tree | 097d04718832793aeca231cfa60e2061ac575fa5 | |
parent | 9065b4bed8c838eb9cce922c9992af11e68bc43c (diff) | |
download | efl-5c9ffed096ee8a20b6ab0face4a5bc2b8ea1a55d.tar.gz |
eina_js: now eina_value JS side correctly handle errors
The only work still missing is the investigation on why tests are
failing with string types. Maybe it's a bug on eina-cxx. Needs to be
investigate.
-rw-r--r-- | src/bindings/eina_js/eina_js_value.cc | 38 | ||||
-rw-r--r-- | src/tests/eina_js/eina_js_value.cc | 18 |
2 files changed, 51 insertions, 5 deletions
diff --git a/src/bindings/eina_js/eina_js_value.cc b/src/bindings/eina_js/eina_js_value.cc index b0d82dfc91..6fb68a5aae 100644 --- a/src/bindings/eina_js/eina_js_value.cc +++ b/src/bindings/eina_js/eina_js_value.cc @@ -11,8 +11,10 @@ void register_make_value(v8::Isolate *isolate, v8::Handle<v8::ObjectTemplate> global, v8::Handle<v8::String> name) { + using v8::Isolate; using v8::Local; using v8::Value; + using v8::Integer; using v8::String; using v8::Object; using v8::FunctionTemplate; @@ -27,10 +29,23 @@ void register_make_value(v8::Isolate *isolate, return; void *ptr = info.Holder()->GetAlignedPointerFromInternalField(0); + Isolate *isolate = info.GetIsolate(); try { *static_cast<ptr_type>(ptr) = value_cast<value_type>(info[0]); } catch(const std::bad_cast &e) { + Local<Object> je = Object::New(isolate); + je->Set(String::NewFromUtf8(isolate, "code"), + String::NewFromUtf8(isolate, "std::bad_cast")); + isolate->ThrowException(je); } catch(const ::efl::eina::system_error &e) { + Local<Object> je = Object::New(isolate); + je->Set(String::NewFromUtf8(isolate, "code"), + String::NewFromUtf8(isolate, "std::error_code")); + je->Set(String::NewFromUtf8(isolate, "category"), + String::NewFromUtf8(isolate, e.code().category().name())); + je->Set(String::NewFromUtf8(isolate, "value"), + Integer::New(isolate, e.code().value())); + isolate->ThrowException(je); } }; auto get = [](const FunctionCallbackInfo<Value> &info) { @@ -43,16 +58,17 @@ void register_make_value(v8::Isolate *isolate, if (info.Length() != 1) return; - auto obj_tpl = v8::ObjectTemplate::New(info.GetIsolate()); + Isolate *isolate = info.GetIsolate(); + auto obj_tpl = v8::ObjectTemplate::New(isolate); obj_tpl->SetInternalFieldCount(1); auto ret = obj_tpl->NewInstance(); info.GetReturnValue().Set(ret); - ret->Set(String::NewFromUtf8(info.GetIsolate(), "set"), - FunctionTemplate::New(info.GetIsolate(), set)->GetFunction()); - ret->Set(String::NewFromUtf8(info.GetIsolate(), "get"), - FunctionTemplate::New(info.GetIsolate(), get)->GetFunction()); + ret->Set(String::NewFromUtf8(isolate, "set"), + FunctionTemplate::New(isolate, set)->GetFunction()); + ret->Set(String::NewFromUtf8(isolate, "get"), + FunctionTemplate::New(isolate, get)->GetFunction()); try { std::unique_ptr<value_type> @@ -60,7 +76,19 @@ void register_make_value(v8::Isolate *isolate, ret->SetAlignedPointerInInternalField(0, ptr.get()); ptr.release(); } catch(const std::bad_cast &e) { + Local<Object> je = Object::New(isolate); + je->Set(String::NewFromUtf8(isolate, "code"), + String::NewFromUtf8(isolate, "std::bad_cast")); + isolate->ThrowException(je); } catch(const ::efl::eina::system_error &e) { + Local<Object> je = Object::New(isolate); + je->Set(String::NewFromUtf8(isolate, "code"), + String::NewFromUtf8(isolate, "std::error_code")); + je->Set(String::NewFromUtf8(isolate, "category"), + String::NewFromUtf8(isolate, e.code().category().name())); + je->Set(String::NewFromUtf8(isolate, "value"), + Integer::New(isolate, e.code().value())); + isolate->ThrowException(je); } }; diff --git a/src/tests/eina_js/eina_js_value.cc b/src/tests/eina_js/eina_js_value.cc index 592c826957..2d652d5d8d 100644 --- a/src/tests/eina_js/eina_js_value.cc +++ b/src/tests/eina_js/eina_js_value.cc @@ -44,6 +44,24 @@ static const char script[] = "assert(typeof(wrapped) === 'number', '#7');" "assert(wrapped === 1, '#8');" + "var captured = false;" + "try {" + " my_value.set({type: 'complex object'});" + "} catch(e) {" + " assert(e.code === 'std::bad_cast', '#9');" + " captured = true;" + "}" + "assert(captured === true, '#10');" + + "captured = false;" + "try {" + " my_value = make_value({type: 'complex object'});" + "} catch(e) {" + " assert(e.code === 'std::bad_cast', '#11');" + " captured = true;" + "}" + "assert(captured === true, '#12');" + "destroy_value(my_value);" ; |