js: Raise exception to js instead of crashing
This commit is contained in:
parent
add91ee80e
commit
26f6254225
|
@ -890,7 +890,7 @@ inline v8::Handle<v8::Function> get_class_constructor(std::string const& class_n
|
||||||
{
|
{
|
||||||
auto it = constructors_map_.find(class_name);
|
auto it = constructors_map_.find(class_name);
|
||||||
if (it == constructors_map_.end())
|
if (it == constructors_map_.end())
|
||||||
throw std::runtime_error("Class not found");
|
throw std::runtime_error("Class not found: " + class_name);
|
||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -142,34 +142,65 @@ get_value_from_c(T object, v8::Isolate* isolate, const char* class_name
|
||||||
inline v8::Local<v8::Value>
|
inline v8::Local<v8::Value>
|
||||||
get_value_from_c(Eo* v, v8::Isolate* isolate, const char* class_name)
|
get_value_from_c(Eo* v, v8::Isolate* isolate, const char* class_name)
|
||||||
{
|
{
|
||||||
auto ctor = ::efl::eina::js::get_class_constructor(class_name);
|
try
|
||||||
auto obj = new_v8_external_instance(ctor, ::efl_ref(v), isolate);
|
{
|
||||||
efl::eina::js::make_weak(isolate, obj, [v]{ ::efl_unref(v); });
|
auto ctor = ::efl::eina::js::get_class_constructor(class_name);
|
||||||
return obj;
|
auto obj = new_v8_external_instance(ctor, ::efl_ref(v), isolate);
|
||||||
|
efl::eina::js::make_weak(isolate, obj, [v]{ ::efl_unref(v); });
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
catch (std::runtime_error const& error)
|
||||||
|
{
|
||||||
|
eina::js::compatibility_throw
|
||||||
|
(isolate, v8::Exception::TypeError
|
||||||
|
(eina::js::compatibility_new<v8::String>(isolate, error.what())));
|
||||||
|
return v8::Null(isolate);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline v8::Local<v8::Value>
|
inline v8::Local<v8::Value>
|
||||||
get_value_from_c(const Eo* v, v8::Isolate* isolate, const char* class_name)
|
get_value_from_c(const Eo* v, v8::Isolate* isolate, const char* class_name)
|
||||||
{
|
{
|
||||||
// TODO: implement const objects?
|
// TODO: implement const objects?
|
||||||
auto ctor = ::efl::eina::js::get_class_constructor(class_name);
|
try
|
||||||
auto obj = new_v8_external_instance(ctor, ::efl_ref(v), isolate);
|
{
|
||||||
efl::eina::js::make_weak(isolate, obj, [v]{ ::efl_unref(v); });
|
auto ctor = ::efl::eina::js::get_class_constructor(class_name);
|
||||||
return obj;
|
auto obj = new_v8_external_instance(ctor, ::efl_ref(v), isolate);
|
||||||
|
efl::eina::js::make_weak(isolate, obj, [v]{ ::efl_unref(v); });
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
catch (std::runtime_error const& error)
|
||||||
|
{
|
||||||
|
eina::js::compatibility_throw
|
||||||
|
(isolate, v8::Exception::TypeError
|
||||||
|
(eina::js::compatibility_new<v8::String>(isolate, error.what())));
|
||||||
|
return v8::Null(isolate);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline v8::Local<v8::Value>
|
inline v8::Local<v8::Value>
|
||||||
get_value_from_c(struct_ptr_tag<T*> v, v8::Isolate* isolate, const char* class_name)
|
get_value_from_c(struct_ptr_tag<T*> v, v8::Isolate* isolate, const char* class_name)
|
||||||
{
|
{
|
||||||
using nonconst_type = typename std::remove_const<T>::type;
|
try
|
||||||
bool own = false; // TODO: handle ownership
|
{
|
||||||
auto ptr = const_cast<nonconst_type*>(v.value);
|
using nonconst_type = typename std::remove_const<T>::type;
|
||||||
auto ctor = ::efl::eina::js::get_class_constructor(class_name);
|
bool own = false; // TODO: handle ownership
|
||||||
auto obj = new_v8_external_instance(ctor, ptr, isolate);
|
auto ptr = const_cast<nonconst_type*>(v.value);
|
||||||
if (own)
|
auto ctor = ::efl::eina::js::get_class_constructor(class_name);
|
||||||
efl::eina::js::make_weak(isolate, obj, [ptr]{ free(ptr); });
|
auto obj = new_v8_external_instance(ctor, ptr, isolate);
|
||||||
return obj;
|
if (own)
|
||||||
|
efl::eina::js::make_weak(isolate, obj, [ptr]{ free(ptr); });
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
catch (std::runtime_error const& error)
|
||||||
|
{
|
||||||
|
eina::js::compatibility_throw
|
||||||
|
(isolate, v8::Exception::TypeError
|
||||||
|
(eina::js::compatibility_new<v8::String>(isolate, error.what())));
|
||||||
|
return v8::Null(isolate);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|
Loading…
Reference in New Issue