aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2015-04-13 16:38:28 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2015-04-13 16:38:28 -0300
commit9857af34ddd461e7de6d764cf037d94254b6ff18 (patch)
tree0fb725339dfba064d49dc47a83ab46c942620419
parentjs: Fixed conditional for JavaScript bindings in Makefiles (diff)
downloadefl-9857af34ddd461e7de6d764cf037d94254b6ff18.tar.gz
eolian-js: Fixed crashes in nodejs
-rw-r--r--src/bin/eolian_js/main.cc2
-rw-r--r--src/bindings/eina_js/eina_js_accessor.hh14
-rw-r--r--src/bindings/eina_js/eina_js_compatibility.hh12
-rw-r--r--src/bindings/eina_js/eina_js_container.cc17
-rw-r--r--src/bindings/eina_js/eina_js_value.cc14
-rw-r--r--src/bindings/eo_js/eo_js_event.hh4
-rw-r--r--src/tests/eina_js/eina_js_suite.cc4
7 files changed, 33 insertions, 34 deletions
diff --git a/src/bin/eolian_js/main.cc b/src/bin/eolian_js/main.cc
index 641e3cc030..6e1053bc49 100644
--- a/src/bin/eolian_js/main.cc
+++ b/src/bin/eolian_js/main.cc
@@ -391,7 +391,7 @@ int main(int argc, char** argv)
os << " {\n";
os << " static efl::eo::js::event_information const event_information\n";
- os << " = {&constructor_from_eo.handle(), ";
+ os << " = {&constructor_from_eo, ";
os << eolian_event_c_name_get(&*first);
os << "};\n\n";
os << " /* should include event " << ::eolian_event_name_get(&*first) << "*/" << std::endl;
diff --git a/src/bindings/eina_js/eina_js_accessor.hh b/src/bindings/eina_js/eina_js_accessor.hh
index e99fa75d09..174b009659 100644
--- a/src/bindings/eina_js/eina_js_accessor.hh
+++ b/src/bindings/eina_js/eina_js_accessor.hh
@@ -38,19 +38,19 @@ template<class T>
v8::Local<v8::Object> export_accessor( ::efl::eina::accessor<T> &a, v8::Isolate *isolate)
{
typedef ::efl::eina::accessor<T> accessor_type;
-
- static auto obj_tpl = [&]() -> compatibility_persistent<v8::ObjectTemplate>
+
+ auto obj_tpl = [&]() -> compatibility_persistent<v8::ObjectTemplate>*
{
auto obj_tpl = compatibility_new<v8::ObjectTemplate>(isolate);
- obj_tpl->SetInternalFieldCount(1);
+ (*obj_tpl)->SetInternalFieldCount(1);
- obj_tpl->Set(js::compatibility_new<v8::String>(isolate, "get")
- , js::compatibility_new<v8::FunctionTemplate>(isolate, &accessor_get<accessor_type>));
+ (*obj_tpl)->Set(js::compatibility_new<v8::String>(isolate, "get")
+ , js::compatibility_new<v8::FunctionTemplate>(isolate, &accessor_get<accessor_type>));
- return {isolate, obj_tpl};
+ return new compatibility_persistent<v8::ObjectTemplate> {isolate, obj_tpl};
}();
- auto instance = obj_tpl.handle()->NewInstance();
+ auto instance = obj_tpl->handle()->NewInstance();
compatibility_set_pointer_internal_field(instance, 0, &a);
return instance;
}
diff --git a/src/bindings/eina_js/eina_js_compatibility.hh b/src/bindings/eina_js/eina_js_compatibility.hh
index 15e98eabb2..b41f1862d6 100644
--- a/src/bindings/eina_js/eina_js_compatibility.hh
+++ b/src/bindings/eina_js/eina_js_compatibility.hh
@@ -325,31 +325,27 @@ struct compatibility_persistent<T, true> : v8::UniquePersistent<T>
typedef v8::UniquePersistent<T> _base;
compatibility_persistent(compatibility_persistent&& other)
- : _base(other.Pass()), handle_(other.handle())
+ : _base(other.Pass())
{
}
compatibility_persistent& operator=(compatibility_persistent&& other)
{
this->_base::operator=(other.Pass());
- handle_ = other.handle();
return *this;
}
compatibility_persistent() {}
compatibility_persistent(v8::Isolate* isolate, v8::Handle<T> v)
- : _base(isolate, v), handle_(v)
+ : _base(isolate, v)
{
}
T* operator->() const
{
- return *handle_;
+ return *handle();
}
- v8::Handle<T>& handle() { return handle_; }
- v8::Handle<T> const& handle() const { return handle_; }
-
- v8::Handle<T> handle_;
+ v8::Local<T> handle() const { return v8::Local<T>::New(v8::Isolate::GetCurrent(), *this); }
};
template <typename T>
diff --git a/src/bindings/eina_js/eina_js_container.cc b/src/bindings/eina_js/eina_js_container.cc
index 7a04ec8068..68130ce4d8 100644
--- a/src/bindings/eina_js/eina_js_container.cc
+++ b/src/bindings/eina_js/eina_js_container.cc
@@ -27,8 +27,8 @@ struct tag { typedef T type; };
namespace {
-compatibility_persistent<v8::ObjectTemplate> instance_persistents[container_type_size];
-v8::Handle<v8::Function> instance_templates[container_type_size];
+compatibility_persistent<v8::ObjectTemplate>* instance_persistents[container_type_size];
+compatibility_persistent<v8::Function>* instance_templates[container_type_size];
v8::Local<v8::Object> concat(eina_container_base& lhs, v8::Isolate* isolate, v8::Local<v8::Value> other)
{
@@ -49,8 +49,9 @@ v8::Local<v8::Object> concat(eina_container_base& lhs, v8::Isolate* isolate, v8:
v8::Handle<v8::Value> a[] =
{efl::eina::js::compatibility_new<v8::External>(isolate, rhs.concat(lhs))};
std::cerr << __func__ << ":" << __LINE__<< " " << lhs.get_container_type() << std::endl;
+ assert(!!*instance_templates[lhs.get_container_type()]->handle());
v8::Local<v8::Object> result =
- instance_templates[lhs.get_container_type()]->NewInstance(1, a);
+ instance_templates[lhs.get_container_type()]->handle()->NewInstance(1, a);
std::cerr << __func__ << ":" << __LINE__<< std::endl;
return result;
}
@@ -73,7 +74,7 @@ v8::Local<v8::Object> slice(eina_container_base& self, v8::Isolate* isolate, v8:
{
std::int64_t i = iv->IntegerValue(), j = jv->IntegerValue();
v8::Handle<v8::Value> a[] = {efl::eina::js::compatibility_new<v8::External>(isolate, self.slice(i, j))};
- v8::Local<v8::Object> result = instance_templates[self.get_container_type()]
+ v8::Local<v8::Object> result = instance_templates[self.get_container_type()]->handle()
->NewInstance(1, a);
return result;
}
@@ -365,8 +366,8 @@ void register_class(v8::Isolate* isolate, container_type type, const char* class
v8::Local<v8::ObjectTemplate> instance_t = efl::eina::js::register_template(isolate, constructor);
- efl::eina::js::instance_persistents[type] = {isolate, instance_t};
- efl::eina::js::instance_templates[type] = constructor->GetFunction();
+ efl::eina::js::instance_persistents[type] = new compatibility_persistent<v8::ObjectTemplate>{isolate, instance_t};
+ efl::eina::js::instance_templates[type] = new compatibility_persistent<v8::Function>{isolate, constructor->GetFunction()};
}
} } } }
@@ -379,8 +380,8 @@ EAPI void eina_container_register(v8::Handle<v8::Object>, v8::Isolate* isolate)
, "eina_array", &efl::eina::js::new_eina_array);
}
-EAPI v8::Handle<v8::Function> get_list_instance_template()
+EAPI v8::Local<v8::Function> get_list_instance_template()
{
- return efl::eina::js::instance_templates[efl::eina::js::list_container_type];
+ return efl::eina::js::instance_templates[efl::eina::js::list_container_type]->handle();
}
diff --git a/src/bindings/eina_js/eina_js_value.cc b/src/bindings/eina_js/eina_js_value.cc
index 369b663e5b..484b1a1cf4 100644
--- a/src/bindings/eina_js/eina_js_value.cc
+++ b/src/bindings/eina_js/eina_js_value.cc
@@ -104,21 +104,23 @@ void register_value(v8::Isolate *isolate, v8::Handle<v8::Object> global,
typedef ::efl::eina::value value_type;
typedef value_type *ptr_type;
- static compatibility_persistent<v8::FunctionTemplate> constructor
+ static compatibility_persistent<v8::FunctionTemplate>* constructor
+ = new compatibility_persistent<v8::FunctionTemplate>
{isolate, compatibility_new<v8::FunctionTemplate>(isolate, &eina_value_constructor)};
- static compatibility_persistent<v8::ObjectTemplate>
- instance = {isolate, constructor.handle()->InstanceTemplate()};
- instance.handle()->SetInternalFieldCount(1);
+ static compatibility_persistent<v8::ObjectTemplate>* instance
+ = new compatibility_persistent<v8::ObjectTemplate>
+ {isolate, constructor->handle()->InstanceTemplate()};
+ instance->handle()->SetInternalFieldCount(1);
- auto prototype = constructor.handle()->PrototypeTemplate();
+ auto prototype = constructor->handle()->PrototypeTemplate();
prototype->Set(compatibility_new<v8::String>(isolate, "set")
, compatibility_new<FunctionTemplate>(isolate, &eina_value_set));
prototype->Set(compatibility_new<v8::String>(isolate, "get")
, compatibility_new<FunctionTemplate>(isolate, &eina_value_get));
- global->Set(name, constructor.handle()->GetFunction());
+ global->Set(name, constructor->handle()->GetFunction());
}
EAPI
diff --git a/src/bindings/eo_js/eo_js_event.hh b/src/bindings/eo_js/eo_js_event.hh
index 910535bb7a..6dde022adf 100644
--- a/src/bindings/eo_js/eo_js_event.hh
+++ b/src/bindings/eo_js/eo_js_event.hh
@@ -21,7 +21,7 @@ namespace efl { namespace eo { namespace js {
struct event_information
{
- v8::Handle<v8::Function>* constructor;
+ eina::js::compatibility_persistent<v8::Function>* constructor;
Eo_Event_Description const* event;
};
@@ -36,7 +36,7 @@ inline Eina_Bool event_callback(void* data, Eo* obj, Eo_Event_Description const*
{
event_callback_information* event = static_cast<event_callback_information*>(data);
v8::Handle<v8::Value> a[] = {eina::js::compatibility_new<v8::External>(nullptr, obj)};
- v8::Local<v8::Object> self = (*event->event_info->constructor)->NewInstance(1, a);
+ v8::Local<v8::Object> self = (event->event_info->constructor->handle())->NewInstance(1, a);
v8::Handle<v8::Value> call_args[] = {self};
event->function->Call(eina::js::compatibility_global(), 1, call_args);
diff --git a/src/tests/eina_js/eina_js_suite.cc b/src/tests/eina_js/eina_js_suite.cc
index ff7e067b7d..42ec6d384f 100644
--- a/src/tests/eina_js/eina_js_suite.cc
+++ b/src/tests/eina_js/eina_js_suite.cc
@@ -101,7 +101,7 @@ efl::eina::js::compatibility_return_type set_eina_error(efl::eina::js::compatibi
}
EAPI void eina_container_register(v8::Handle<v8::Object> global, v8::Isolate* isolate);
-EAPI v8::Handle<v8::FunctionTemplate> get_list_instance_template();
+EAPI v8::Local<v8::Function> get_list_instance_template();
efl::eina::ptr_list<int> list;
efl::eina::js::range_eina_list<int> raw_list;
@@ -128,7 +128,7 @@ void test_setup(v8::Handle<v8::Object> exports)
v8::Handle<v8::Value> a[] = {efl::eina::js::compatibility_new<v8::External>(nullptr, &raw_list)};
std::cerr << __LINE__ << std::endl;
exports->Set(efl::eina::js::compatibility_new<v8::String>(nullptr, "raw_list")
- , get_list_instance_template()->GetFunction()->NewInstance(1, a));
+ , get_list_instance_template()->NewInstance(1, a));
std::cerr << __LINE__ << std::endl;
// error globals