summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2015-01-08 16:56:24 -0200
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2015-01-08 16:56:24 -0200
commitc892457bc1f4098260186d67a5abeaaa19ac02ce (patch)
treedffebdb499da91053ec5f54a5caecfe29570f13d
parent9c21c736728332464df9969ae00c47b43f63680d (diff)
downloadefl-c892457bc1f4098260186d67a5abeaaa19ac02ce.tar.gz
eina-js: Fixes for container for compatibilization
-rw-r--r--src/bindings/eina_js/eina_js_container.cc21
-rw-r--r--src/bindings/eina_js/eina_js_list.hh7
-rw-r--r--src/tests/eina_js/eina_js_suite.cc25
-rwxr-xr-xsrc/tests/eina_js/eina_js_suite.js7
4 files changed, 51 insertions, 9 deletions
diff --git a/src/bindings/eina_js/eina_js_container.cc b/src/bindings/eina_js/eina_js_container.cc
index a4dda20367..f7c205e6eb 100644
--- a/src/bindings/eina_js/eina_js_container.cc
+++ b/src/bindings/eina_js/eina_js_container.cc
@@ -27,6 +27,7 @@ struct tag { typedef T type; };
namespace {
compatibility_persistent<v8::ObjectTemplate> instance_persistents[container_type_size];
+compatibility_persistent<v8::FunctionTemplate> constructor_persistents[container_type_size];
v8::Handle<v8::FunctionTemplate> instance_templates[container_type_size];
v8::Local<v8::Object> concat(eina_container_base& lhs, v8::Isolate* isolate, v8::Local<v8::Value> other)
@@ -40,12 +41,17 @@ v8::Local<v8::Object> concat(eina_container_base& lhs, v8::Isolate* isolate, v8:
{
eina_container_base& rhs = *static_cast<eina_container_base*>
(efl::eina::js::compatibility_get_pointer_internal_field(obj, 0));
+ std::cout << "me " << &lhs << " other " << &rhs << std::endl;
std::type_info const& typeinfo_lhs = typeid(lhs)
, &typeinfo_rhs = typeid(rhs);
if(!typeinfo_lhs.before(typeinfo_rhs) && !typeinfo_rhs.before(typeinfo_lhs))
{
- v8::Handle<v8::Value> a[] = {efl::eina::js::compatibility_new<v8::External>(isolate, rhs.concat(lhs))};
- v8::Local<v8::Object> result = instance_templates[lhs.get_container_type()]->GetFunction()->NewInstance(1, a);
+ v8::Handle<v8::Value> a[] =
+ {efl::eina::js::compatibility_new<v8::External>(isolate, rhs.concat(lhs))};
+ std::cerr << __func__ << ":" << __LINE__<< std::endl;
+ v8::Local<v8::Object> result =
+ instance_templates[lhs.get_container_type()]->GetFunction()->NewInstance(1, a);
+ std::cerr << __func__ << ":" << __LINE__<< std::endl;
return result;
}
else
@@ -83,7 +89,8 @@ compatibility_accessor_getter_return_type length
v8::Local<v8::Object> self_obj = v8::Local<v8::Object>::Cast(info.This());
eina_container_base* self = static_cast<eina_container_base*>
(compatibility_get_pointer_internal_field(self_obj, 0));
- return compatibility_return(compatibility_new<v8::Number>(nullptr, self->size()), info);
+ std::cout << "size " << self->size() << std::endl;
+ return compatibility_return(js::get_value_from_c(self->size(), info.GetIsolate()), info);
}
compatibility_accessor_getter_return_type index_get
@@ -98,6 +105,7 @@ compatibility_accessor_getter_return_type index_get
compatibility_return_type new_eina_list(compatibility_callback_info_type args)
{
+ std::cerr << "new_eina_list" << std::endl;
if(args.IsConstructCall())
{
if(args.Length() == 0)
@@ -130,6 +138,7 @@ compatibility_return_type new_eina_list(compatibility_callback_info_type args)
compatibility_return_type new_eina_array(compatibility_callback_info_type args)
{
+ std::cerr << "new_eina_array" << std::endl;
if(args.IsConstructCall())
{
if(args.Length() == 0)
@@ -219,7 +228,8 @@ R call_impl(v8::Isolate* isolate
std::cout << "was called" << std::endl;
}
} print_;
- std::cout << "self " << self << " pointer " << (void*)f << std::endl;
+ std::cout << "self " << self << " pointer " << (void*)f
+ << " F " << typeid(F).name() << std::endl;
assert(self != 0);
return (*f)(*self, isolate, js::get_element<N, Sig>(isolate, args)...);
}
@@ -357,6 +367,8 @@ void register_class(v8::Isolate* isolate, container_type type, const char* class
efl::eina::js::instance_persistents[type]
= compatibility_persistent<v8::ObjectTemplate> {isolate, instance_t};
+ efl::eina::js::constructor_persistents[type]
+ = compatibility_persistent<v8::FunctionTemplate> {isolate, constructor};
efl::eina::js::instance_templates[type] = constructor;
}
@@ -374,3 +386,4 @@ EAPI v8::Handle<v8::FunctionTemplate> get_list_instance_template()
{
return efl::eina::js::instance_templates[efl::eina::js::list_container_type];
}
+
diff --git a/src/bindings/eina_js/eina_js_list.hh b/src/bindings/eina_js/eina_js_list.hh
index b45a9fddf2..f943b74094 100644
--- a/src/bindings/eina_js/eina_js_list.hh
+++ b/src/bindings/eina_js/eina_js_list.hh
@@ -44,7 +44,7 @@ namespace detail {
template <typename T>
eina_container_base* concat(T const& self, eina_container_base const& other)
{
- std::cout << __func__ << std::endl;
+ std::cout << __func__ << " " << typeid(container_type).name() << std::endl;
T const& rhs = static_cast<T const&>(other);
typedef typename T::container_type container_type;
container_type container(self._container.begin(), self._container.end());
@@ -106,11 +106,14 @@ struct range_eina_list : eina_container_common<efl::eina::range_list<T> >
eina_container_base* concat(eina_container_base const& other) const
{
- std::cout << __func__ << std::endl;
+ std::cout << __func__ << " " << typeid(container_type).name() << std::endl;
range_eina_list<T>const& rhs = static_cast<range_eina_list<T>const&>(other);
+ std::cout << __func__ << ":" << __LINE__ << std::endl;
efl::eina::list<T, clone_allocator_type>
list(this->_container.begin(), this->_container.end());
+ std::cout << __func__ << ":" << __LINE__ << std::endl;
list.insert(list.end(), rhs._container.begin(), rhs._container.end());
+ std::cout << __func__ << ":" << __LINE__ << std::endl;
return new eina_list<T>(list.release_native_handle());
}
eina_container_base* slice(std::int64_t i, std::int64_t j) const
diff --git a/src/tests/eina_js/eina_js_suite.cc b/src/tests/eina_js/eina_js_suite.cc
index 64866dc4ed..3385715d57 100644
--- a/src/tests/eina_js/eina_js_suite.cc
+++ b/src/tests/eina_js/eina_js_suite.cc
@@ -198,15 +198,38 @@ int main(int, char*[])
namespace {
+efl::eina::ptr_list<int> list;
+efl::eina::js::range_eina_list<int> raw_list;
+
void init(v8::Handle<v8::Object> exports)
{
try
{
+ eina_init();
+ eo_init();
+
+ std::cerr << __LINE__ << std::endl;
+ list.push_back(new int(5));
+ list.push_back(new int(10));
+ list.push_back(new int(15));
+ std::cerr << __LINE__ << std::endl;
+
+ raw_list = efl::eina::js::range_eina_list<int>(list.native_handle());
+
+ std::cerr << __LINE__ << std::endl;
eina_container_register(exports, v8::Isolate::GetCurrent());
+ std::cerr << __LINE__ << std::endl;
+
+ 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));
+
+ std::cerr << "registered" << std::endl;
}
catch(...)
{
- std::cout << "Error" << std::endl;
+ std::cerr << "Error" << std::endl;
}
}
diff --git a/src/tests/eina_js/eina_js_suite.js b/src/tests/eina_js/eina_js_suite.js
index 080059b2a0..9c80c81fcb 100755
--- a/src/tests/eina_js/eina_js_suite.js
+++ b/src/tests/eina_js/eina_js_suite.js
@@ -3,6 +3,7 @@
console.log("teste1");
var suite = require('../../../build/src/tests/eina_js/eina_js_suite');
+assert = require('assert');
// function assert(condition, message)
// {
@@ -12,10 +13,10 @@ var suite = require('../../../build/src/tests/eina_js/eina_js_suite');
// }
console.log("teste");
-var l1 = raw_list;
+var l1 = suite.raw_list;
console.log ("l1 ", l1.toString());
assert (l1.length == 3);
-var l2 = raw_list;
+var l2 = suite.raw_list;
console.log ("l2 ", l2.toString());
assert (l2.length == 3);
var c = l1.concat(l2);
@@ -49,3 +50,5 @@ console.log ("s2 ", s2.toString());
assert (s2.length == 2);
assert (s2[0] == l1[1]);
assert (s2[1] == l1[2]);
+
+console.log ("Test execution with success");