aboutsummaryrefslogtreecommitdiffstats
path: root/src/bindings
diff options
context:
space:
mode:
Diffstat (limited to 'src/bindings')
-rw-r--r--src/bindings/ecore_js/Ecore_Js.hh58
-rw-r--r--src/bindings/ecore_js/ecore_js_animator.cc728
-rw-r--r--src/bindings/ecore_js/ecore_js_event.cc772
-rw-r--r--src/bindings/ecore_js/ecore_js_file.cc1457
-rw-r--r--src/bindings/ecore_js/ecore_js_idle.cc294
-rw-r--r--src/bindings/ecore_js/ecore_js_init.cc77
-rw-r--r--src/bindings/ecore_js/ecore_js_job.cc83
-rw-r--r--src/bindings/ecore_js/ecore_js_mainloop.cc207
-rw-r--r--src/bindings/ecore_js/ecore_js_poller.cc190
-rw-r--r--src/bindings/ecore_js/ecore_js_throttle.cc63
-rw-r--r--src/bindings/ecore_js/ecore_js_timer.cc263
-rw-r--r--src/bindings/ecore_js/ecore_js_timer.hh38
-rw-r--r--src/bindings/eina_cxx/Eina.hh1
-rw-r--r--src/bindings/eina_cxx/eina_accessor.hh5
-rw-r--r--src/bindings/eina_cxx/eina_array.hh250
-rw-r--r--src/bindings/eina_cxx/eina_clone_allocators.hh3
-rw-r--r--src/bindings/eina_cxx/eina_function.hh26
-rw-r--r--src/bindings/eina_cxx/eina_integer_sequence.hh2
-rw-r--r--src/bindings/eina_cxx/eina_list.hh14
-rw-r--r--src/bindings/eina_cxx/eina_logical.hh34
-rw-r--r--src/bindings/eina_cxx/eina_pp.hh8
-rw-r--r--src/bindings/eina_cxx/eina_ptrarray.hh16
-rw-r--r--src/bindings/eina_cxx/eina_ptrlist.hh79
-rw-r--r--src/bindings/eina_cxx/eina_range_types.hh58
-rw-r--r--src/bindings/eina_cxx/eina_tuple.hh60
-rw-r--r--src/bindings/eina_cxx/eina_tuple_c.hh24
-rw-r--r--src/bindings/eina_cxx/eina_type_traits.hh16
-rw-r--r--src/bindings/eina_js/Eina_Js.hh50
-rw-r--r--src/bindings/eina_js/eina_js_accessor.cc34
-rw-r--r--src/bindings/eina_js/eina_js_accessor.hh87
-rw-r--r--src/bindings/eina_js/eina_js_array.hh119
-rw-r--r--src/bindings/eina_js/eina_js_compatibility.cc12
-rw-r--r--src/bindings/eina_js/eina_js_compatibility.hh918
-rw-r--r--src/bindings/eina_js/eina_js_container.cc495
-rw-r--r--src/bindings/eina_js/eina_js_container.hh351
-rw-r--r--src/bindings/eina_js/eina_js_error.cc24
-rw-r--r--src/bindings/eina_js/eina_js_error.hh25
-rw-r--r--src/bindings/eina_js/eina_js_get_value.hh449
-rw-r--r--src/bindings/eina_js/eina_js_get_value_from_c.hh261
-rw-r--r--src/bindings/eina_js/eina_js_iterator.cc32
-rw-r--r--src/bindings/eina_js/eina_js_iterator.hh81
-rw-r--r--src/bindings/eina_js/eina_js_list.hh132
-rw-r--r--src/bindings/eina_js/eina_js_log.cc742
-rw-r--r--src/bindings/eina_js/eina_js_log.hh133
-rw-r--r--src/bindings/eina_js/eina_js_node.hh14
-rw-r--r--src/bindings/eina_js/eina_js_value.cc132
-rw-r--r--src/bindings/eina_js/eina_js_value.hh142
-rw-r--r--src/bindings/eio_js/Eio_Js.hh44
-rw-r--r--src/bindings/eio_js/eio_js.cc1756
-rw-r--r--src/bindings/eldbus_cxx/eldbus_freedesktop.hh1
-rw-r--r--src/bindings/eldbus_js/Eldbus_Js.hh48
-rw-r--r--src/bindings/eldbus_js/eldbus_js_connection.cc543
-rw-r--r--src/bindings/eldbus_js/eldbus_js_core.cc183
-rw-r--r--src/bindings/eldbus_js/eldbus_js_message.cc103
-rw-r--r--src/bindings/eldbus_js/eldbus_js_object_mapper.cc100
-rw-r--r--src/bindings/eldbus_js/eldbus_js_util.hh836
-rw-r--r--src/bindings/eo_cxx/eo_concrete.hh7
-rw-r--r--src/bindings/eo_js/Eo_Js.hh15
-rw-r--r--src/bindings/eo_js/eo_js_call_function.hh288
-rw-r--r--src/bindings/eo_js/eo_js_construct_from_eo.hh39
-rw-r--r--src/bindings/eo_js/eo_js_constructor.hh136
-rw-r--r--src/bindings/eo_js/eo_js_direction.hh12
-rw-r--r--src/bindings/eo_js/eo_js_event.hh126
-rw-r--r--src/bindings/eo_js/eo_js_namespace.hh24
-rw-r--r--src/bindings/eo_js/eo_js_struct.hh106
-rw-r--r--src/bindings/ethumb_js/Ethumb_Js.hh48
-rw-r--r--src/bindings/ethumb_js/ethumb_js_client.cc571
67 files changed, 13984 insertions, 61 deletions
diff --git a/src/bindings/ecore_js/Ecore_Js.hh b/src/bindings/ecore_js/Ecore_Js.hh
new file mode 100644
index 0000000000..3f877f3fc8
--- /dev/null
+++ b/src/bindings/ecore_js/Ecore_Js.hh
@@ -0,0 +1,58 @@
+
+#ifndef EFL_ECORE_JS_HH
+#define EFL_ECORE_JS_HH
+
+#include <Ecore.hh>
+#include <Ecore_File.h>
+#include <Eina_Js.hh>
+
+#ifdef EAPI
+# undef EAPI
+#endif
+
+#ifdef _WIN32
+# ifdef EFL_ECORE_JS_BUILD
+# ifdef DLL_EXPORT
+# define EAPI __declspec(dllexport)
+# else
+# define EAPI
+# endif /* ! DLL_EXPORT */
+# else
+# define EAPI __declspec(dllimport)
+# endif /* ! EFL_ECORE_BUILD */
+#else
+# ifdef __GNUC__
+# if __GNUC__ >= 4
+# define EAPI __attribute__ ((visibility("default")))
+# else
+# define EAPI
+# endif
+# else
+# define EAPI
+# endif
+#endif /* ! _WIN32 */
+
+namespace efl { namespace ecore { namespace js {
+
+using ::efl::eina::js::compatibility_new;
+using ::efl::eina::js::compatibility_return_type;
+using ::efl::eina::js::compatibility_callback_info_type;
+using ::efl::eina::js::compatibility_return;
+using ::efl::eina::js::compatibility_get_pointer_internal_field;
+using ::efl::eina::js::compatibility_set_pointer_internal_field;
+
+EAPI void register_ecore_animator(v8::Isolate *isolate,v8::Handle<v8::Object> exports);
+EAPI void register_ecore_event(v8::Isolate* isolate, v8::Handle<v8::Object> exports);
+EAPI void register_ecore_file(v8::Isolate* isolate, v8::Handle<v8::Object> exports);
+EAPI void register_ecore_idle(v8::Isolate *isolate,v8::Handle<v8::Object> exports);
+EAPI void register_ecore_job(v8::Isolate *isolate,v8::Handle<v8::Object> exports);
+EAPI void register_ecore_mainloop(v8::Isolate *isolate,v8::Handle<v8::Object> exports);
+EAPI void register_ecore_poller(v8::Isolate *isolate,v8::Handle<v8::Object> exports);
+EAPI void register_ecore_throttle(v8::Isolate *isolate,v8::Handle<v8::Object> exports);
+EAPI void register_ecore_timer(v8::Isolate *isolate,v8::Handle<v8::Object> exports);
+
+EAPI void register_ecore(v8::Isolate *isolate,v8::Handle<v8::Object> exports);
+
+} } }
+
+#endif
diff --git a/src/bindings/ecore_js/ecore_js_animator.cc b/src/bindings/ecore_js/ecore_js_animator.cc
new file mode 100644
index 0000000000..52f8576dee
--- /dev/null
+++ b/src/bindings/ecore_js/ecore_js_animator.cc
@@ -0,0 +1,728 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <Ecore_Js.hh>
+
+namespace efl { namespace ecore { namespace js {
+
+static Ecore_Animator* extract_animator(v8::Local<v8::Object> object)
+{
+ auto ptr = v8::External::Cast(*object->GetInternalField(0))->Value();
+ return reinterpret_cast<Ecore_Animator*>(ptr);
+}
+
+static v8::Local<v8::Object> wrap_animator(Ecore_Animator *animator,
+ v8::Isolate *isolate)
+{
+ using v8::Boolean;
+ using v8::String;
+ using v8::ObjectTemplate;
+ using v8::FunctionTemplate;
+
+ auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
+ obj_tpl->SetInternalFieldCount(1);
+ auto ret = obj_tpl->NewInstance();
+
+ auto del = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ ecore_animator_del(extract_animator(info.This()));
+ return compatibility_return();
+ };
+
+ auto freeze = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ ecore_animator_freeze(extract_animator(info.This()));
+ return compatibility_return();
+ };
+
+ auto thaw = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ ecore_animator_thaw(extract_animator(info.This()));
+ return compatibility_return();
+ };
+
+ ret->Set(compatibility_new<String>(isolate, "del"),
+ compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "freeze"),
+ compatibility_new<FunctionTemplate>(isolate, freeze)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "thaw"),
+ compatibility_new<FunctionTemplate>(isolate, thaw)->GetFunction());
+
+ ret->SetInternalField(0, compatibility_new<v8::External>(isolate,
+ animator));
+
+ return ret;
+}
+
+void register_pos_map_linear(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+
+ global->Set(name,
+ compatibility_new<Integer>(isolate, ECORE_POS_MAP_LINEAR));
+}
+
+void register_pos_map_accelerate(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+
+ global->Set(name,
+ compatibility_new<Integer>(isolate, ECORE_POS_MAP_ACCELERATE));
+}
+
+void register_pos_map_decelerate(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+
+ global->Set(name,
+ compatibility_new<Integer>(isolate, ECORE_POS_MAP_DECELERATE));
+}
+
+void register_pos_map_sinusoidal(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+
+ global->Set(name,
+ compatibility_new<Integer>(isolate, ECORE_POS_MAP_SINUSOIDAL));
+}
+
+void register_pos_map_accelerate_factor(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+
+ global->Set(name,
+ compatibility_new<Integer>(isolate,
+ ECORE_POS_MAP_ACCELERATE_FACTOR));
+}
+
+void register_pos_map_decelerate_factor(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+
+ global->Set(name,
+ compatibility_new<Integer>(isolate,
+ ECORE_POS_MAP_DECELERATE_FACTOR));
+}
+
+void register_pos_map_sinusoidal_factor(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+
+ global->Set(name,
+ compatibility_new<Integer>(isolate,
+ ECORE_POS_MAP_SINUSOIDAL_FACTOR));
+}
+
+void register_pos_map_divisor_interp(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+
+ global->Set(name,
+ compatibility_new<Integer>(isolate,
+ ECORE_POS_MAP_DIVISOR_INTERP));
+}
+
+void register_pos_map_bounce(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+
+ global->Set(name,
+ compatibility_new<Integer>(isolate, ECORE_POS_MAP_BOUNCE));
+}
+
+void register_pos_map_spring(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+
+ global->Set(name,
+ compatibility_new<Integer>(isolate, ECORE_POS_MAP_SPRING));
+}
+
+void register_pos_map_cubic_bezier(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+
+ global->Set(name,
+ compatibility_new<Integer>(isolate,
+ ECORE_POS_MAP_CUBIC_BEZIER));
+}
+
+void register_animator_source_timer(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+
+ global->Set(name,
+ compatibility_new<Integer>(isolate,
+ ECORE_ANIMATOR_SOURCE_TIMER));
+}
+
+void register_animator_source_custom(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+
+ global->Set(name,
+ compatibility_new<Integer>(isolate,
+ ECORE_ANIMATOR_SOURCE_CUSTOM));
+}
+
+void register_animator_frametime_set(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsNumber())
+ return compatibility_return();
+
+ ecore_animator_frametime_set(args[0]->NumberValue());
+ return compatibility_return();
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_animator_frametime_get(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Number;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_animator_frametime_get();
+ return compatibility_return(compatibility_new<Number>(isolate, ret),
+ args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_animator_pos_map(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Number;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 4 || !args[0]->IsNumber() || !args[1]->IsNumber()
+ || !args[2]->IsNumber() || !args[3]->IsNumber())
+ return compatibility_return();
+
+ Ecore_Pos_Map map;
+
+ switch ((int)(args[1]->NumberValue())) {
+ case ECORE_POS_MAP_LINEAR:
+ map = ECORE_POS_MAP_LINEAR;
+ break;
+ case ECORE_POS_MAP_ACCELERATE:
+ map = ECORE_POS_MAP_ACCELERATE;
+ break;
+ case ECORE_POS_MAP_DECELERATE:
+ map = ECORE_POS_MAP_DECELERATE;
+ break;
+ case ECORE_POS_MAP_SINUSOIDAL:
+ map = ECORE_POS_MAP_SINUSOIDAL;
+ break;
+ case ECORE_POS_MAP_ACCELERATE_FACTOR:
+ map = ECORE_POS_MAP_ACCELERATE_FACTOR;
+ break;
+ case ECORE_POS_MAP_DECELERATE_FACTOR:
+ map = ECORE_POS_MAP_DECELERATE_FACTOR;
+ break;
+ case ECORE_POS_MAP_SINUSOIDAL_FACTOR:
+ map = ECORE_POS_MAP_SINUSOIDAL_FACTOR;
+ break;
+ case ECORE_POS_MAP_DIVISOR_INTERP:
+ map = ECORE_POS_MAP_DIVISOR_INTERP;
+ break;
+ case ECORE_POS_MAP_BOUNCE:
+ map = ECORE_POS_MAP_BOUNCE;
+ break;
+ case ECORE_POS_MAP_SPRING:
+ map = ECORE_POS_MAP_SPRING;
+ break;
+ case ECORE_POS_MAP_CUBIC_BEZIER:
+ map = ECORE_POS_MAP_CUBIC_BEZIER;
+ break;
+ default:
+ return compatibility_return();
+ }
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_animator_pos_map(args[0]->NumberValue(), map,
+ args[2]->NumberValue(),
+ args[3]->NumberValue());
+ return compatibility_return(compatibility_new<Number>(isolate, ret),
+ args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_animator_pos_map_n(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Number;
+ using v8::NumberObject;
+ using v8::FunctionTemplate;
+ using v8::Array;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 3 || !args[0]->IsNumber() || !args[1]->IsNumber()
+ || !args[2]->IsArray())
+ return compatibility_return();
+
+ Ecore_Pos_Map map;
+
+ switch ((int)(args[1]->NumberValue())) {
+ case ECORE_POS_MAP_LINEAR:
+ map = ECORE_POS_MAP_LINEAR;
+ break;
+ case ECORE_POS_MAP_ACCELERATE:
+ map = ECORE_POS_MAP_ACCELERATE;
+ break;
+ case ECORE_POS_MAP_DECELERATE:
+ map = ECORE_POS_MAP_DECELERATE;
+ break;
+ case ECORE_POS_MAP_SINUSOIDAL:
+ map = ECORE_POS_MAP_SINUSOIDAL;
+ break;
+ case ECORE_POS_MAP_ACCELERATE_FACTOR:
+ map = ECORE_POS_MAP_ACCELERATE_FACTOR;
+ break;
+ case ECORE_POS_MAP_DECELERATE_FACTOR:
+ map = ECORE_POS_MAP_DECELERATE_FACTOR;
+ break;
+ case ECORE_POS_MAP_SINUSOIDAL_FACTOR:
+ map = ECORE_POS_MAP_SINUSOIDAL_FACTOR;
+ break;
+ case ECORE_POS_MAP_DIVISOR_INTERP:
+ map = ECORE_POS_MAP_DIVISOR_INTERP;
+ break;
+ case ECORE_POS_MAP_BOUNCE:
+ map = ECORE_POS_MAP_BOUNCE;
+ break;
+ case ECORE_POS_MAP_SPRING:
+ map = ECORE_POS_MAP_SPRING;
+ break;
+ case ECORE_POS_MAP_CUBIC_BEZIER:
+ map = ECORE_POS_MAP_CUBIC_BEZIER;
+ break;
+ default:
+ return compatibility_return();
+ }
+
+ std::vector<double> v;
+ {
+ auto array = Array::Cast(*args[2]);
+ auto s = array->Length();
+ v.reserve(s);
+ for (decltype(s) i = 0;i != s;++i) {
+ auto e = array->Get(i);
+ if (!e->IsNumber())
+ return compatibility_return();
+
+ v.push_back(e->NumberValue());
+ }
+ }
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_animator_pos_map_n(args[0]->NumberValue(), map,
+ v.size(), v.data());
+ return compatibility_return(compatibility_new<Number>(isolate, ret),
+ args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_animator_source_set(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsNumber())
+ return compatibility_return();
+
+ Ecore_Animator_Source source;
+
+ switch ((int)(args[0]->NumberValue())) {
+ case ECORE_ANIMATOR_SOURCE_TIMER:
+ source = ECORE_ANIMATOR_SOURCE_TIMER;
+ break;
+ case ECORE_ANIMATOR_SOURCE_CUSTOM:
+ source = ECORE_ANIMATOR_SOURCE_CUSTOM;
+ break;
+ default:
+ return compatibility_return();
+ }
+
+ ecore_animator_source_set(source);
+ return compatibility_return();
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_animator_source_get(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_animator_source_get();
+ return compatibility_return(compatibility_new<Integer>(isolate, ret),
+ args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+static
+efl::eina::js::global_ref<v8::Value> animator_custom_source_tick_begin_cb_data;
+static
+efl::eina::js::global_ref<v8::Value> animator_custom_source_tick_end_cb_data;
+
+void
+register_animator_custom_source_tick_begin_callback_set(v8::Isolate *isolate,
+ v8::Handle<v8::Object>
+ global,
+ v8::Handle<v8::String>
+ name)
+{
+ using v8::FunctionCallbackInfo;
+ using v8::Value;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args) {
+ if (args.Length() != 1 || !args[0]->IsFunction())
+ return compatibility_return();
+
+ animator_custom_source_tick_begin_cb_data
+ = efl::eina::js::global_ref<Value>(args.GetIsolate(), args[0]);
+ ecore_animator_custom_source_tick_begin_callback_set([](void*) {
+ using v8::Function;
+ using v8::Undefined;
+ using v8::Isolate;
+
+ auto o = animator_custom_source_tick_begin_cb_data.handle();
+ Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
+ }, NULL);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void
+register_animator_custom_source_tick_end_callback_set(v8::Isolate *isolate,
+ v8::Handle<v8::Object>
+ global,
+ v8::Handle<v8::String>
+ name)
+{
+ using v8::FunctionCallbackInfo;
+ using v8::Value;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args) {
+ if (args.Length() != 1 || !args[0]->IsFunction())
+ return compatibility_return();
+
+ efl::eina::js::global_ref<v8::Value>* data
+ = new efl::eina::js::global_ref<v8::Value>(args.GetIsolate(), args[0]);
+ ecore_animator_custom_source_tick_end_callback_set([](void* data) {
+ using v8::Function;
+ using v8::Undefined;
+ using v8::Isolate;
+
+ efl::eina::js::global_ref<v8::Value>*
+ d = static_cast<efl::eina::js::global_ref<v8::Value>*>(data);
+ auto o = d->handle();
+ Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
+ d->dispose();
+ delete d;
+ }, data);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void
+register_animator_custom_tick(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::FunctionCallbackInfo;
+ using v8::Value;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args) {
+ if (args.Length() != 0)
+ return compatibility_return();
+
+ ecore_animator_custom_tick();
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_animator_add(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Local;
+ using v8::Value;
+ using v8::Undefined;
+ using v8::Function;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsFunction())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto f = new efl::eina::js::global_ref<Value>(isolate, args[0]);
+
+ auto cb = [](void *data) -> Eina_Bool {
+ auto persistent = static_cast<efl::eina::js::global_ref<Value>*>(data);
+ auto o = persistent->handle();
+
+ auto ret = Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
+ auto bret = ret->IsBoolean() && ret->BooleanValue();
+
+ if (!bret)
+ {
+ persistent->dispose();
+ delete persistent;
+ }
+
+ return bret ? EINA_TRUE : EINA_FALSE;
+ };
+
+ auto ret = ecore_animator_add(cb, f);
+ return compatibility_return(wrap_animator(ret, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_animator_timeline_add(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Handle;
+ using v8::Local;
+ using v8::Value;
+ using v8::Undefined;
+ using v8::Function;
+ using v8::FunctionTemplate;
+ using v8::Number;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 2 || !args[0]->IsNumber()
+ || !args[1]->IsFunction()) {
+ return compatibility_return();
+ }
+
+ auto f = new efl::eina::js::global_ref<Value>(args.GetIsolate(), args[1]);
+
+ auto cb = [](void *data, double pos) -> Eina_Bool {
+ auto persistent
+ = reinterpret_cast<efl::eina::js::global_ref<Value>*>(data);
+ auto o = persistent->handle();
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args = compatibility_new<Number>(isolate, pos);
+
+ auto ret = Function::Cast(*o)->Call(o->ToObject(), 1, &args);
+ auto bret = ret->IsBoolean() && ret->BooleanValue();
+
+ if (!bret)
+ {
+ persistent->dispose();
+ delete persistent;
+ }
+
+ return bret ? EINA_TRUE : EINA_FALSE;
+ };
+
+ auto ret = ecore_animator_timeline_add(args[0]->NumberValue(), cb, f);
+ return compatibility_return(wrap_animator(ret, args.GetIsolate()),
+ args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_ecore_animator(v8::Isolate* isolate, v8::Handle<v8::Object> exports)
+{
+ register_pos_map_linear(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ECORE_POS_MAP_LINEAR"));
+ register_pos_map_accelerate(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ECORE_POS_MAP"
+ "_ACCELERATE"));
+ register_pos_map_decelerate(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ECORE_POS_MAP"
+ "_DECELERATE"));
+ register_pos_map_sinusoidal(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ECORE_POS_MAP"
+ "_SINUSOIDAL"));
+ register_pos_map_accelerate_factor(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ECORE_POS_MAP"
+ "_ACCELERATE"
+ "_FACTOR"));
+ register_pos_map_decelerate_factor(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ECORE_POS_MAP"
+ "_DECELERATE"
+ "_FACTOR"));
+ register_pos_map_sinusoidal_factor(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ECORE_POS_MAP"
+ "_SINUSOIDAL"
+ "_FACTOR"));
+ register_pos_map_divisor_interp(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ECORE_POS_MAP"
+ "_DIVISOR_INTERP"));
+ register_pos_map_bounce(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ECORE_POS_MAP_BOUNCE"));
+ register_pos_map_spring(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ECORE_POS_MAP_SPRING"));
+ register_pos_map_cubic_bezier(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ECORE_POS_MAP_CUBIC"
+ "_BEZIER"));
+ register_animator_source_timer(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ECORE_ANIMATOR"
+ "_SOURCE_TIMER"));
+ register_animator_source_custom(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ECORE_ANIMATOR"
+ "_SOURCE_CUSTOM"));
+ register_animator_frametime_set(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_animator"
+ "_frametime_set"));
+ register_animator_frametime_get(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_animator"
+ "_frametime_get"));
+ register_animator_pos_map(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_animator_pos"
+ "_map"));
+ register_animator_pos_map_n(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_animator_pos_map"
+ "_n"));
+ register_animator_source_set(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_animator_source"
+ "_set"));
+ register_animator_source_get(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_animator_source"
+ "_get"));
+ register_animator_custom_source_tick_begin_callback_set
+ (isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_animator_custom_source_tick_begin"
+ "_callback_set"));
+ register_animator_custom_source_tick_end_callback_set
+ (isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_animator_custom_source_tick_end"
+ "_callback_set"));
+ register_animator_custom_tick(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_animator"
+ "_custom_tick"));
+ register_animator_add(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_animator_add"));
+ register_animator_timeline_add(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_animator"
+ "_timeline_add"));
+}
+
+} } } // namespace efl { namespace js {
diff --git a/src/bindings/ecore_js/ecore_js_event.cc b/src/bindings/ecore_js/ecore_js_event.cc
new file mode 100644
index 0000000000..a086d989d6
--- /dev/null
+++ b/src/bindings/ecore_js/ecore_js_event.cc
@@ -0,0 +1,772 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <Ecore_Js.hh>
+
+namespace efl { namespace ecore { namespace js {
+
+static Ecore_Event *extract_event(v8::Local<v8::Object> object)
+{
+ return compatibility_get_pointer_internal_field<Ecore_Event*>(object, 0);
+}
+
+static v8::Local<v8::Object> wrap_event(Ecore_Event *event,
+ v8::Isolate *isolate)
+{
+ using v8::String;
+ using v8::ObjectTemplate;
+ using v8::FunctionTemplate;
+
+ auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
+ obj_tpl->SetInternalFieldCount(1);
+ auto ret = obj_tpl->NewInstance();
+
+ auto del = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ ecore_event_del(extract_event(info.This()));
+ return compatibility_return();
+ };
+
+ ret->Set(compatibility_new<String>(isolate, "del"),
+ compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
+
+ compatibility_set_pointer_internal_field(ret, 0, event);
+
+ return ret;
+}
+
+static Ecore_Event_Handler *extract_event_handler(v8::Local<v8::Object> object)
+{
+ return compatibility_get_pointer_internal_field<Ecore_Event_Handler*>
+ (object, 0);
+}
+
+static v8::Local<v8::Object> wrap_event_handler(Ecore_Event_Handler *handler,
+ v8::Isolate *isolate)
+{
+ using v8::String;
+ using v8::ObjectTemplate;
+ using v8::FunctionTemplate;
+ using v8::Value;
+
+ auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
+ obj_tpl->SetInternalFieldCount(1);
+ auto ret = obj_tpl->NewInstance();
+
+ auto del = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto p = ecore_event_handler_del(extract_event_handler(info.This()));
+
+ delete static_cast<efl::eina::js::global_ref<Value>*>(p);
+ return compatibility_return();
+ };
+
+ ret->Set(compatibility_new<String>(isolate, "del"),
+ compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
+
+ compatibility_set_pointer_internal_field(ret, 0, handler);
+
+ return ret;
+}
+
+static Ecore_Event_Filter *extract_event_filter(v8::Local<v8::Object> object)
+{
+ return compatibility_get_pointer_internal_field<Ecore_Event_Filter*>
+ (object, 0);
+}
+
+static v8::Local<v8::Object> wrap_event_filter(Ecore_Event_Filter *filter,
+ v8::Isolate *isolate)
+{
+ using v8::String;
+ using v8::ObjectTemplate;
+ using v8::FunctionTemplate;
+ using v8::Value;
+
+ auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
+ obj_tpl->SetInternalFieldCount(1);
+ auto ret = obj_tpl->NewInstance();
+
+ auto del = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto p = ecore_event_filter_del(extract_event_filter(info.This()));
+ delete[] static_cast<efl::eina::js::global_ref<Value>*>(p);
+ return compatibility_return();
+ };
+
+ ret->Set(compatibility_new<String>(isolate, "del"),
+ compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
+
+ compatibility_set_pointer_internal_field(ret, 0, filter);
+
+ return ret;
+}
+
+EAPI
+void register_event_none(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate, ECORE_EVENT_NONE));
+}
+
+EAPI
+void register_event_signal_user(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate, ECORE_EVENT_SIGNAL_USER));
+}
+
+EAPI
+void register_event_signal_hup(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate, ECORE_EVENT_SIGNAL_HUP));
+}
+
+EAPI
+void register_event_signal_exit(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate, ECORE_EVENT_SIGNAL_EXIT));
+}
+
+EAPI
+void register_event_signal_power(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate, ECORE_EVENT_SIGNAL_POWER));
+}
+
+EAPI
+void register_event_signal_realtime(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate,
+ ECORE_EVENT_SIGNAL_REALTIME));
+}
+
+EAPI
+void register_event_memory_state(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate, ECORE_EVENT_MEMORY_STATE));
+}
+
+EAPI
+void register_event_power_state(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate, ECORE_EVENT_POWER_STATE));
+}
+
+EAPI
+void register_event_locale_changed(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate,
+ ECORE_EVENT_LOCALE_CHANGED));
+}
+
+EAPI
+void register_event_hostname_changed(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate,
+ ECORE_EVENT_HOSTNAME_CHANGED));
+}
+
+EAPI
+void register_event_system_timedate_changed(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate,
+ ECORE_EVENT_SYSTEM_TIMEDATE_CHANGED));
+}
+
+EAPI
+void register_event_type_new(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_event_type_new();
+ return compatibility_return(compatibility_new<Integer>(isolate, ret),
+ args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_event_add(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsNumber())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_event_add(args[0]->NumberValue(), NULL, NULL, NULL);
+ return compatibility_return(wrap_event(ret, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_event_handler_add(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::Value;
+ using v8::Function;
+ using v8::Handle;
+ using v8::Local;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 2 || !args[0]->IsNumber()
+ || !args[1]->IsFunction()) {
+ return compatibility_return();
+ }
+
+ auto isolate = args.GetIsolate();
+
+ auto p = new efl::eina::js::global_ref<Value>(isolate, args[1]);
+
+ auto cb = [](void *d, int type, void */*event*/) -> Eina_Bool {
+ auto persistent = static_cast<efl::eina::js::global_ref<Value>*>(d);
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+ Handle<Value> args = compatibility_new<Integer>(isolate, type);
+
+ auto ret = Function::Cast(*o)->Call(o->ToObject(), 1, &args);
+ auto bret = ret->IsBoolean() && ret->BooleanValue();
+
+ return bret ? EINA_TRUE : EINA_FALSE;
+ };
+
+ auto ret = ecore_event_handler_add(args[0]->Int32Value(), cb, p);
+ return compatibility_return(wrap_event_handler(ret, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_event_filter_add(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::Value;
+ using v8::Function;
+ using v8::Handle;
+ using v8::Local;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 3 || !args[0]->IsFunction()
+ || !args[1]->IsFunction() || !args[2]->IsFunction()) {
+ return compatibility_return();
+ }
+
+ auto isolate = args.GetIsolate();
+
+ auto p = new efl::eina::js::global_ref<Value>[3]{{isolate, args[0]},
+ {isolate, args[1]},
+ {isolate, args[2]}};
+
+ auto start_cb = [](void *data) -> void* {
+ auto p = static_cast<efl::eina::js::global_ref<Value>*>(data);
+ auto isolate = v8::Isolate::GetCurrent();
+ auto o = p->handle();
+
+ auto ret = Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
+ return new efl::eina::js::global_ref<Value>{isolate, ret};
+ };
+
+ auto filter_cb = [](void *data, void *loop_data, int type,
+ void */*event*/) -> Eina_Bool {
+ typedef efl::eina::js::global_ref<Value> p_t;
+
+ auto p = static_cast<p_t*>(data) + 1;
+ auto isolate = v8::Isolate::GetCurrent();
+ auto o = p->handle();
+
+ Handle<Value> args[2]{
+ static_cast<p_t*>(loop_data)->handle(),
+ compatibility_new<Integer>(isolate, type)
+ };
+
+ auto ret = Function::Cast(*o)->Call(o->ToObject(), 2, args);
+ auto bret = ret->IsBoolean() && ret->BooleanValue();
+
+ return bret ? EINA_TRUE : EINA_FALSE;
+ };
+
+ auto end_cb = [](void *user_data, void *func_data) -> void {
+ typedef efl::eina::js::global_ref<Value> p_t;
+
+ auto loop_data = std::unique_ptr<p_t>(static_cast<p_t*>
+ (func_data));
+ auto p = static_cast<p_t*>(user_data) + 2;
+ auto o = p->handle();
+
+ Handle<Value> args = p->handle();
+
+ Function::Cast(*o)->Call(o->ToObject(), 1, &args);
+ };
+
+ auto ret = ecore_event_filter_add(start_cb, filter_cb, end_cb, p);
+ return compatibility_return(wrap_event_filter(ret, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_event_current_type_get(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_event_current_type_get();
+ return compatibility_return(compatibility_new<Integer>(isolate, ret),
+ args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_memory_state_normal(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate, ECORE_MEMORY_STATE_NORMAL));
+}
+
+EAPI
+void register_memory_state_low(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate, ECORE_MEMORY_STATE_LOW));
+}
+
+EAPI
+void register_power_state_mains(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate, ECORE_POWER_STATE_MAINS));
+}
+
+EAPI
+void register_power_state_battery(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate, ECORE_POWER_STATE_BATTERY));
+}
+
+EAPI
+void register_power_state_low(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate, ECORE_POWER_STATE_LOW));
+}
+
+EAPI
+void register_memory_state_get(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_memory_state_get();
+ return compatibility_return(compatibility_new<Integer>(isolate, ret),
+ args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_power_state_get(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_power_state_get();
+ return compatibility_return(compatibility_new<Integer>(isolate, ret),
+ args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_event_signal_user_handler_add(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::String;
+ using v8::Value;
+ using v8::Object;
+ using v8::Function;
+ using v8::Handle;
+ using v8::Local;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsFunction())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+
+ auto p = new efl::eina::js::global_ref<Value>(isolate, args[0]);
+
+ auto cb = [](void *d, int type, void *event) -> Eina_Bool {
+ auto p = static_cast<efl::eina::js::global_ref<Value>*>(d);
+ auto isolate = v8::Isolate::GetCurrent();
+ auto o = p->handle();
+
+ auto wrapped_event = compatibility_new<Object>(isolate);
+
+ {
+ auto n
+ = reinterpret_cast<Ecore_Event_Signal_User*>(event)->number;
+ wrapped_event->Set(compatibility_new<String>(isolate, "number"),
+ compatibility_new<Integer>(isolate, n));
+ }
+
+ Handle<Value> args[2]{
+ compatibility_new<Integer>(isolate, type),
+ wrapped_event
+ };
+
+ auto ret = Function::Cast(*o)->Call(o->ToObject(), 2, args);
+ auto bret = ret->IsBoolean() && ret->BooleanValue();
+
+ return bret ? EINA_TRUE : EINA_FALSE;
+ };
+
+ auto ret = ecore_event_handler_add(ECORE_EVENT_SIGNAL_USER, cb, p);
+ return compatibility_return(wrap_event_handler(ret, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_event_signal_exit_handler_add(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::Boolean;
+ using v8::String;
+ using v8::Value;
+ using v8::Object;
+ using v8::Function;
+ using v8::Handle;
+ using v8::Local;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsFunction())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+
+ auto p = new efl::eina::js::global_ref<Value>(isolate, args[0]);
+
+ auto cb = [](void *d, int type, void *ev) -> Eina_Bool {
+ auto p = static_cast<efl::eina::js::global_ref<Value>*>(d);
+ auto isolate = v8::Isolate::GetCurrent();
+ auto o = p->handle();
+
+ auto wrapped_event = compatibility_new<Object>(isolate);
+
+ {
+ auto event = reinterpret_cast<Ecore_Event_Signal_Exit*>(ev);
+ auto interrupt = event->interrupt;
+ auto quit = event->quit;
+ auto terminate = event->terminate;
+
+ wrapped_event->Set(compatibility_new<String>(isolate,
+ "interrupt"),
+ compatibility_new<Boolean>(isolate,
+ interrupt));
+ wrapped_event->Set(compatibility_new<String>(isolate, "quit"),
+ compatibility_new<Boolean>(isolate, quit));
+ wrapped_event->Set(compatibility_new<String>(isolate,
+ "terminate"),
+ compatibility_new<Boolean>(isolate,
+ terminate));
+ }
+
+ Handle<Value> args[2]{
+ compatibility_new<Integer>(isolate, type),
+ wrapped_event
+ };
+
+ auto ret = Function::Cast(*o)->Call(o->ToObject(), 2, args);
+ auto bret = ret->IsBoolean() && ret->BooleanValue();
+
+ return bret ? EINA_TRUE : EINA_FALSE;
+ };
+
+ auto ret = ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT, cb, p);
+ return compatibility_return(wrap_event_handler(ret, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_event_signal_realtime_handler_add(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::String;
+ using v8::Value;
+ using v8::Object;
+ using v8::Function;
+ using v8::Handle;
+ using v8::Local;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsFunction())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+
+ auto p = new efl::eina::js::global_ref<Value>(isolate, args[0]);
+
+ auto cb = [](void *d, int type, void *ev) -> Eina_Bool {
+ auto p = static_cast<efl::eina::js::global_ref<Value>*>(d);
+ auto isolate = v8::Isolate::GetCurrent();
+ auto o = p->handle();
+
+ auto wrapped_event = compatibility_new<Object>(isolate);
+
+ {
+ auto n
+ = reinterpret_cast<Ecore_Event_Signal_Realtime*>(ev)->num;
+ wrapped_event->Set(compatibility_new<String>(isolate, "num"),
+ compatibility_new<Integer>(isolate, n));
+ }
+
+ Handle<Value> args[2]{
+ compatibility_new<Integer>(isolate, type),
+ wrapped_event
+ };
+
+ auto ret = Function::Cast(*o)->Call(o->ToObject(), 2, args);
+ auto bret = ret->IsBoolean() && ret->BooleanValue();
+
+ return bret ? EINA_TRUE : EINA_FALSE;
+ };
+
+ auto ret = ecore_event_handler_add(ECORE_EVENT_SIGNAL_REALTIME, cb, p);
+ return compatibility_return(wrap_event_handler(ret, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_ecore_event(v8::Isolate* isolate, v8::Handle<v8::Object> exports)
+{
+ register_event_none(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ECORE_EVENT_NONE"));
+ register_event_signal_user(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate, "ECORE_EVENT_SIGNAL_USER"));
+ register_event_signal_hup(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate, "ECORE_EVENT_SIGNAL_HUP"));
+ register_event_signal_exit(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate, "ECORE_EVENT_SIGNAL_EXIT"));
+ register_event_signal_power(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate, "ECORE_EVENT_SIGNAL_POWER"));
+ register_event_signal_realtime(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate, "ECORE_EVENT_SIGNAL_REALTIME"));
+ register_event_memory_state(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate, "ECORE_EVENT_MEMORY_STATE"));
+ register_event_power_state(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate, "ECORE_EVENT_POWER_STATE"));
+ register_event_locale_changed(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate, "ECORE_EVENT_LOCALE_CHANGED"));
+ register_event_hostname_changed(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate, "ECORE_EVENT_HOSTNAME_CHANGED"));
+ register_event_system_timedate_changed(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate,
+ "ECORE_EVENT_SYSTEM_TIMEDATE"
+ "_CHANGED"));
+ register_event_type_new(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_event_type_new"));
+ register_event_add(isolate, exports,
+ compatibility_new<v8::String>(isolate, "ecore_event_add"));
+ register_event_handler_add(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate, "ecore_event_handler_add"));
+ register_event_filter_add(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate, "ecore_event_filter_add"));
+ register_event_current_type_get(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate, "ecore_event_current_type_get"));
+ register_memory_state_normal(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate, "ECORE_MEMORY_STATE_NORMAL"));
+ register_memory_state_low(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate, "ECORE_MEMORY_STATE_LOW"));
+ register_power_state_mains(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate, "ECORE_POWER_STATE_MAINS"));
+ register_power_state_battery(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate, "ECORE_POWER_STATE_BATTERY"));
+ register_power_state_low(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ECORE_POWER_STATE_LOW"));
+ register_event_signal_user_handler_add(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate,
+ "ecore_event_signal_user_handler"
+ "_add"));
+ register_event_signal_exit_handler_add(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate,
+ "ecore_event_signal_exit_handler"
+ "_add"));
+ register_event_signal_realtime_handler_add(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate,
+ "ecore_event_signal_realtime"
+ "_handler_add"));
+}
+
+} } } // namespace efl { namespace js {
diff --git a/src/bindings/ecore_js/ecore_js_file.cc b/src/bindings/ecore_js/ecore_js_file.cc
new file mode 100644
index 0000000000..eea300f8dd
--- /dev/null
+++ b/src/bindings/ecore_js/ecore_js_file.cc
@@ -0,0 +1,1457 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <Ecore_Js.hh>
+
+#include <memory>
+#include <cstdlib>
+
+#include <unistd.h>
+
+namespace efl { namespace ecore { namespace js {
+
+namespace {
+
+Ecore_File_Monitor* extract_monitor(v8::Local<v8::Object> object)
+{
+ return compatibility_get_pointer_internal_field<Ecore_File_Monitor*>(object,
+ 0);
+}
+
+v8::Local<v8::Object> wrap_monitor(Ecore_File_Monitor *monitor,
+ v8::Isolate *isolate)
+{
+ using v8::String;
+ using v8::ObjectTemplate;
+ using v8::FunctionTemplate;
+
+ auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
+ obj_tpl->SetInternalFieldCount(1);
+ auto ret = obj_tpl->NewInstance();
+
+ auto del = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ ecore_file_monitor_del(extract_monitor(info.This()));
+ return compatibility_return();
+ };
+
+ auto path_get = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto ret = ecore_file_monitor_path_get(extract_monitor(info.This()));
+ return compatibility_return(compatibility_new<String>(info.GetIsolate(),
+ ret),
+ info);
+ };
+
+ ret->Set(compatibility_new<String>(isolate, "del"),
+ compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "path_get"),
+ compatibility_new<FunctionTemplate>(isolate, path_get)
+ ->GetFunction());
+
+ compatibility_set_pointer_internal_field(ret, 0, monitor);
+
+ return ret;
+}
+
+static Ecore_File_Download_Job *extract_download_job(v8::Local<v8::Object> o)
+{
+ return compatibility_get_pointer_internal_field<Ecore_File_Download_Job*>
+ (o, 0);
+}
+
+static
+v8::Local<v8::Object> wrap_download_job(Ecore_File_Download_Job *download_job,
+ v8::Isolate *isolate)
+{
+ using v8::String;
+ using v8::ObjectTemplate;
+ using v8::FunctionTemplate;
+
+ auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
+ obj_tpl->SetInternalFieldCount(1);
+ auto ret = obj_tpl->NewInstance();
+
+ auto abort = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ ecore_file_download_abort(extract_download_job(info.This()));
+ return compatibility_return();
+ };
+
+ ret->Set(compatibility_new<String>(isolate, "abort"),
+ compatibility_new<FunctionTemplate>(isolate, abort)
+ ->GetFunction());
+
+ compatibility_set_pointer_internal_field(ret, 0, download_job);
+
+ return ret;
+}
+
+void register_file_event_none(v8::Isolate *isolate,
+ v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ exports->Set(name,
+ compatibility_new<Integer>(isolate, ECORE_FILE_EVENT_NONE));
+}
+
+void register_file_event_created_file(v8::Isolate *isolate,
+ v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ exports->Set(name,
+ compatibility_new<Integer>(isolate,
+ ECORE_FILE_EVENT_CREATED_FILE));
+}
+
+void register_file_event_created_directory(v8::Isolate *isolate,
+ v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ exports->Set(name,
+ compatibility_new<Integer>(isolate,
+ ECORE_FILE_EVENT_CREATED_DIRECTORY));
+}
+
+void register_file_event_deleted_file(v8::Isolate *isolate,
+ v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ exports->Set(name,
+ compatibility_new<Integer>(isolate,
+ ECORE_FILE_EVENT_DELETED_FILE));
+}
+
+void register_file_event_deleted_directory(v8::Isolate *isolate,
+ v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ exports->Set(name,
+ compatibility_new<Integer>(isolate,
+ ECORE_FILE_EVENT_DELETED_DIRECTORY));
+}
+
+void register_file_event_deleted_self(v8::Isolate *isolate,
+ v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ exports->Set(name,
+ compatibility_new<Integer>(isolate,
+ ECORE_FILE_EVENT_DELETED_SELF));
+}
+
+void register_file_event_modified(v8::Isolate *isolate,
+ v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ exports->Set(name,
+ compatibility_new<Integer>(isolate, ECORE_FILE_EVENT_MODIFIED));
+}
+
+void register_file_event_closed(v8::Isolate *isolate,
+ v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ exports->Set(name,
+ compatibility_new<Integer>(isolate, ECORE_FILE_EVENT_CLOSED));
+}
+
+void register_file_progress_continue(v8::Isolate *isolate,
+ v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ exports->Set(name,
+ compatibility_new<Integer>(isolate,
+ ECORE_FILE_PROGRESS_CONTINUE));
+}
+
+void register_file_progress_abort(v8::Isolate *isolate,
+ v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ exports->Set(name,
+ compatibility_new<Integer>(isolate, ECORE_FILE_PROGRESS_ABORT));
+}
+
+void register_file_init(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_file_init();
+ return compatibility_return(compatibility_new<Integer>(isolate, ret),
+ args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_shutdown(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_file_shutdown();
+ return compatibility_return(compatibility_new<Integer>(isolate, ret),
+ args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_mod_time(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Date;
+ using v8::String;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsString())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+
+ /* TODO: be less ofensive on the comment below once the documentation of
+ `ecore_file_mod_time` is fixed. I'm planning to submit a patch. */
+ /* `ecore_file_mod_time` returns "the time of the last data
+ modification", which is one of the most useless descriptions of a
+ function I ever found. The return type is `long long`, but looking at
+ the implementation, I see the value is the number of seconds since
+ the Epoch.
+
+ v8's `Date` constructor takes the number of milliseconds since the
+ Epoch represented as a `double`. */
+ double ret = ecore_file_mod_time(*String::Utf8Value(args[0]));
+ ret *= 1000;
+
+ return compatibility_return(compatibility_new<Date>(isolate, ret),
+ args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_size(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::String;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsString())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_file_size(*String::Utf8Value(args[0]));
+ return compatibility_return(compatibility_new<Integer>(isolate, ret),
+ args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_exists(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Boolean;
+ using v8::String;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsString())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_file_exists(*String::Utf8Value(args[0]));
+ return compatibility_return(compatibility_new<Boolean>(isolate, ret),
+ args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_is_dir(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Boolean;
+ using v8::String;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsString())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_file_is_dir(*String::Utf8Value(args[0]));
+ return compatibility_return(compatibility_new<Boolean>(isolate, ret),
+ args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_mkdir(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Boolean;
+ using v8::String;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsString())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_file_mkdir(*String::Utf8Value(args[0]));
+ return compatibility_return(compatibility_new<Boolean>(isolate, ret),
+ args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_mkdirs(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::String;
+ using v8::Array;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsArray())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ std::vector<std::string> dirs_data;
+ std::vector<const char*> dirs;
+ {
+ auto array = Array::Cast(*args[0]);
+ auto s = array->Length();
+ dirs_data.reserve(s);
+ dirs.reserve(s + 1);
+ for (decltype(s) i = 0;i != s;++i) {
+ auto e = array->Get(i);
+ if (!e->IsString())
+ return compatibility_return();
+
+ dirs_data.push_back(*String::Utf8Value(e));
+ dirs.push_back(dirs_data.back().data());
+ }
+ }
+ dirs.push_back(NULL);
+ auto ret = ecore_file_mkdirs(dirs.data());
+ return compatibility_return(compatibility_new<Integer>(isolate, ret),
+ args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_mksubdirs(v8::Isolate *isolate,
+ v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::String;
+ using v8::Array;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 2 || !args[0]->IsString() || !args[1]->IsArray())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ std::vector<std::string> subdirs_data;
+ std::vector<const char*> subdirs;
+ {
+ auto array = Array::Cast(*args[1]);
+ auto s = array->Length();
+ subdirs_data.reserve(s);
+ subdirs.reserve(s + 1);
+ for (decltype(s) i = 0;i != s;++i) {
+ auto e = array->Get(i);
+ if (!e->IsString())
+ return compatibility_return();
+
+ subdirs_data.push_back(*String::Utf8Value(e));
+ subdirs.push_back(subdirs_data.back().data());
+ }
+ }
+ subdirs.push_back(NULL);
+ auto ret = ecore_file_mksubdirs(*String::Utf8Value(args[0]),
+ subdirs.data());
+ return compatibility_return(compatibility_new<Integer>(isolate, ret),
+ args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_rmdir(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Boolean;
+ using v8::String;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsString())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_file_rmdir(*String::Utf8Value(args[0]));
+ return compatibility_return(compatibility_new<Boolean>(isolate, ret),
+ args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_unlink(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Boolean;
+ using v8::String;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsString())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_file_unlink(*String::Utf8Value(args[0]));
+ return compatibility_return(compatibility_new<Boolean>(isolate, ret),
+ args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_remove(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Boolean;
+ using v8::String;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsString())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_file_remove(*String::Utf8Value(args[0]));
+ return compatibility_return(compatibility_new<Boolean>(isolate, ret),
+ args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_recursive_rm(v8::Isolate *isolate,
+ v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Boolean;
+ using v8::String;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsString())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_file_recursive_rm(*String::Utf8Value(args[0]));
+ return compatibility_return(compatibility_new<Boolean>(isolate, ret),
+ args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_mkpath(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Boolean;
+ using v8::String;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsString())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_file_mkpath(*String::Utf8Value(args[0]));
+ return compatibility_return(compatibility_new<Boolean>(isolate, ret),
+ args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_mkpaths(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::String;
+ using v8::Array;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsArray())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ std::vector<std::string> paths_data;
+ std::vector<const char*> paths;
+ {
+ auto array = Array::Cast(*args[0]);
+ auto s = array->Length();
+ paths_data.reserve(s);
+ paths.reserve(s + 1);
+ for (decltype(s) i = 0;i != s;++i) {
+ auto e = array->Get(i);
+ if (!e->IsString())
+ return compatibility_return();
+
+ paths_data.push_back(*String::Utf8Value(e));
+ paths.push_back(paths_data.back().data());
+ }
+ }
+ paths.push_back(NULL);
+ auto ret = ecore_file_mkpaths(paths.data());
+ return compatibility_return(compatibility_new<Integer>(isolate, ret),
+ args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_cp(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Boolean;
+ using v8::String;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 2 || !args[0]->IsString() || !args[1]->IsString())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_file_cp(*String::Utf8Value(args[0]),
+ *String::Utf8Value(args[1]));
+ return compatibility_return(compatibility_new<Boolean>(isolate, ret),
+ args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_mv(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Boolean;
+ using v8::String;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 2 || !args[0]->IsString() || !args[1]->IsString())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_file_mv(*String::Utf8Value(args[0]),
+ *String::Utf8Value(args[1]));
+ return compatibility_return(compatibility_new<Boolean>(isolate, ret),
+ args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_symlink(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Boolean;
+ using v8::String;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 2 || !args[0]->IsString() || !args[1]->IsString())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_file_symlink(*String::Utf8Value(args[0]),
+ *String::Utf8Value(args[1]));
+ return compatibility_return(compatibility_new<Boolean>(isolate, ret),
+ args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_realpath(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::String;
+ using v8::FunctionTemplate;
+ using std::unique_ptr;
+ using std::free;
+
+ typedef unique_ptr<char, void(*)(char*)> guard_t;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsString())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto rp = guard_t(ecore_file_realpath(*String::Utf8Value(args[0])),
+ [](char *str) { free(str); });
+ auto ret = compatibility_new<String>(isolate, rp ? rp.get() : "");
+ return compatibility_return(ret, args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_file_get(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::String;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsString())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ String::Utf8Value str(args[0]);
+ auto ret = ecore_file_file_get(*str);
+ return compatibility_return(compatibility_new<String>(isolate, ret),
+ args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_dir_get(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::String;
+ using v8::FunctionTemplate;
+ using std::unique_ptr;
+ using std::free;
+
+ typedef unique_ptr<char, void(*)(char*)> guard_t;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsString())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto d = guard_t(ecore_file_dir_get(*String::Utf8Value(args[0])),
+ [](char *str) { free(str); });
+ auto ret = compatibility_new<String>(isolate, d ? d.get() : "");
+ return compatibility_return(ret, args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_can_read(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Boolean;
+ using v8::String;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsString())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_file_can_read(*String::Utf8Value(args[0]));
+ return compatibility_return(compatibility_new<Boolean>(isolate, ret),
+ args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_can_write(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Boolean;
+ using v8::String;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsString())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_file_can_write(*String::Utf8Value(args[0]));
+ return compatibility_return(compatibility_new<Boolean>(isolate, ret),
+ args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_can_exec(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Boolean;
+ using v8::String;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsString())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_file_can_exec(*String::Utf8Value(args[0]));
+ return compatibility_return(compatibility_new<Boolean>(isolate, ret),
+ args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_readlink(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::String;
+ using v8::FunctionTemplate;
+ using std::unique_ptr;
+ using std::free;
+
+ typedef unique_ptr<char, void(*)(char*)> guard_t;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsString())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto l = guard_t(ecore_file_readlink(*String::Utf8Value(args[0])),
+ [](char *str) { free(str); });
+ auto ret = compatibility_new<String>(isolate, l ? l.get() : "");
+ return compatibility_return(ret, args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_ls(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Array;
+ using v8::String;
+ using v8::FunctionTemplate;
+ using std::unique_ptr;
+ using std::free;
+
+ typedef unique_ptr<Eina_List, Eina_List*(*)(Eina_List*)> guard_t;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsString())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto list = guard_t(ecore_file_ls(*String::Utf8Value(args[0])),
+ eina_list_free);
+ auto ret = compatibility_new<Array>(isolate);
+ {
+ uint32_t idx = 0;
+ for (Eina_List *l = list.get() ; l ; l = eina_list_next(l)) {
+ /* Not using idiomatic RAII here because it'd be a fake safety,
+ given that remaining objects would leak if an exception is
+ throw. It shouldn't be a problem because v8 doesn't use
+ exceptions (nor idiomatic C++). */
+ auto data = reinterpret_cast<char*>(eina_list_data_get(l));
+ ret->Set(idx++, compatibility_new<String>(isolate, data));
+ free(data);
+ }
+ }
+ return compatibility_return(ret, args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_app_exe_get(v8::Isolate *isolate,
+ v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::String;
+ using v8::FunctionTemplate;
+ using std::unique_ptr;
+ using std::free;
+
+ typedef unique_ptr<char, void(*)(char*)> guard_t;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsString())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto e = guard_t(ecore_file_app_exe_get(*String::Utf8Value(args[0])),
+ [](char *str) { free(str); });
+ auto ret = compatibility_new<String>(isolate, e ? e.get() : "");
+ return compatibility_return(ret, args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_escape_name(v8::Isolate *isolate,
+ v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::String;
+ using v8::FunctionTemplate;
+ using std::unique_ptr;
+ using std::free;
+
+ typedef unique_ptr<char, void(*)(char*)> guard_t;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsString())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto n = guard_t(ecore_file_escape_name(*String::Utf8Value(args[0])),
+ [](char *str) { free(str); });
+ auto ret = compatibility_new<String>(isolate, n ? n.get() : "");
+ return compatibility_return(ret, args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_strip_ext(v8::Isolate *isolate,
+ v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::String;
+ using v8::FunctionTemplate;
+ using std::unique_ptr;
+ using std::free;
+
+ typedef unique_ptr<char, void(*)(char*)> guard_t;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsString())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto n = guard_t(ecore_file_strip_ext(*String::Utf8Value(args[0])),
+ [](char *str) { free(str); });
+ auto ret = compatibility_new<String>(isolate, n ? n.get() : "");
+ return compatibility_return(ret, args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_dir_is_empty(v8::Isolate *isolate,
+ v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::String;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsString())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_file_dir_is_empty(*String::Utf8Value(args[0]));
+ return compatibility_return(compatibility_new<Integer>(isolate, ret),
+ args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_monitor_add(v8::Isolate *isolate,
+ v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::String;
+ using v8::Integer;
+ using v8::FunctionTemplate;
+ using v8::Handle;
+ using v8::Value;
+ using v8::Function;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 2 || !args[0]->IsString()
+ || !args[1]->IsFunction()) {
+ return compatibility_return();
+ }
+
+ auto f = new efl::eina::js::global_ref<Value>(args.GetIsolate(), args[1]);
+
+ auto cb = [](void *data, Ecore_File_Monitor *em, Ecore_File_Event event,
+ const char *path) {
+ auto persistent = static_cast<efl::eina::js::global_ref<Value>*>(data);
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args[3] = {
+ wrap_monitor(em, isolate),
+ compatibility_new<Integer>(isolate, event),
+ compatibility_new<String>(isolate, path)
+ };
+
+ Function::Cast(*o)->Call(o->ToObject(), 3, args);
+
+ persistent->dispose();
+ delete persistent;
+ };
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_file_monitor_add(*String::Utf8Value(args[0]), cb, f);
+ return compatibility_return(wrap_monitor(ret, isolate), args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_path_dir_exists(v8::Isolate *isolate,
+ v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Boolean;
+ using v8::String;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsString())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ Eina_Bool ret = ecore_file_path_dir_exists(*String::Utf8Value(args[0]));
+ return compatibility_return(compatibility_new<Boolean>(isolate, ret == EINA_TRUE ? true : false),
+ args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_app_installed(v8::Isolate *isolate,
+ v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Boolean;
+ using v8::String;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsString())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_file_app_installed(*String::Utf8Value(args[0]));
+ return compatibility_return(compatibility_new<Boolean>(isolate, ret),
+ args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_app_list(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Array;
+ using v8::String;
+ using v8::FunctionTemplate;
+ using std::unique_ptr;
+ using std::free;
+
+ typedef unique_ptr<Eina_List, Eina_List*(*)(Eina_List*)> guard_t;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto list = guard_t(ecore_file_app_list(), eina_list_free);
+ auto ret = compatibility_new<Array>(isolate);
+ {
+ uint32_t idx = 0;
+ for (Eina_List *l = list.get() ; l ; l = eina_list_next(l)) {
+ /* Not using idiomatic RAII here because it'd be a fake safety,
+ given that remaining objects would leak if an exception is
+ throw. It shouldn't be a problem because v8 doesn't use
+ exceptions (nor idiomatic C++). */
+ auto data = reinterpret_cast<char*>(eina_list_data_get(l));
+ ret->Set(idx++, compatibility_new<String>(isolate, data));
+ free(data);
+ }
+ }
+ return compatibility_return(ret, args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_download(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Boolean;
+ using v8::Integer;
+ using v8::String;
+ using v8::Object;
+ using v8::Function;
+ using v8::Value;
+ using v8::Handle;
+ using v8::FunctionTemplate;
+ using std::unique_ptr;
+ using std::free;
+
+ typedef unique_ptr<Eina_Hash, void(*)(Eina_Hash*)> guard_t;
+ typedef efl::eina::js::global_ref<Value> persistent_t;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if ((args.Length() != 4 && args.Length() != 5) || !args[0]->IsString()
+ || !args[1]->IsString() || !args[2]->IsFunction()
+ || !args[3]->IsFunction()
+ || (args.Length() == 5 && !args[4]->IsObject()))
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+
+ auto cb_data = unique_ptr<persistent_t[]>(new persistent_t[2]);
+ cb_data[0] = persistent_t(isolate, args[2]);
+ cb_data[1] = persistent_t(isolate, args[3]);
+
+ String::Utf8Value url(args[0]);
+ String::Utf8Value dst(args[1]);
+ auto completion_cb = [](void *data, const char *file, int status) {
+ auto persistent = reinterpret_cast<persistent_t*>(data);
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args[2] = {
+ compatibility_new<String>(isolate, file),
+ compatibility_new<Integer>(isolate, status)
+ };
+
+ Function::Cast(*o)->Call(o->ToObject(), 2, args);
+
+ delete[] persistent;
+ };
+ auto progress_cb = [](void *data, const char *file, long int dltotal,
+ long int dlnow, long int ultotal,
+ long int ulnow) -> int {
+ auto persistent = reinterpret_cast<persistent_t*>(data) + 1;
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args[5] = {
+ compatibility_new<String>(isolate, file),
+ compatibility_new<Integer>(isolate, dltotal),
+ compatibility_new<Integer>(isolate, dlnow),
+ compatibility_new<Integer>(isolate, ultotal),
+ compatibility_new<Integer>(isolate, ulnow)
+ };
+
+ auto ret = Function::Cast(*o)->Call(o->ToObject(), 5, args);
+ auto iret = ret->IsNumber() ? int(ret->NumberValue()) : 0;
+ if (iret != ECORE_FILE_PROGRESS_CONTINUE)
+ delete[] (persistent - 1);
+
+ return iret;
+ };
+ Ecore_File_Download_Job *job_ret = NULL;
+ auto ret = compatibility_new<Object>(isolate);
+ bool bret;
+
+ if (args.Length() == 4) {
+ bret = ecore_file_download(*url, *dst, completion_cb, progress_cb,
+ cb_data.get(), &job_ret);
+ } else {
+ auto headers = guard_t(eina_hash_string_djb2_new(free),
+ eina_hash_free);
+ auto js_headers = Object::Cast(*args[4]);
+ auto keys = js_headers->GetOwnPropertyNames();
+ for (uint32_t i = 0;i != keys->Length();++i) {
+ auto key = keys->CloneElementAt(i);
+ if (!key->IsString())
+ return compatibility_return();
+
+ auto value = js_headers->Get(key);
+ if (!value->IsString())
+ return compatibility_return();
+
+ eina_hash_add(headers.get(), *String::Utf8Value(key),
+ strdup(*String::Utf8Value(value)));
+ }
+ bret = ecore_file_download_full(*url, *dst, completion_cb,
+ progress_cb, cb_data.get(),
+ &job_ret, headers.get());
+ }
+ if (bret)
+ cb_data.release();
+
+ ret->Set(compatibility_new<String>(isolate, "ok"),
+ compatibility_new<Boolean>(isolate, bret));
+
+ if (job_ret) {
+ ret->Set(compatibility_new<String>(isolate, "job"),
+ wrap_download_job(job_ret, isolate));
+ }
+
+ return compatibility_return(ret, args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_download_abort_all(v8::Isolate *isolate,
+ v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 0)
+ return compatibility_return();
+
+ ecore_file_download_abort_all();
+ return compatibility_return();
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_download_protocol_available(v8::Isolate *isolate,
+ v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ using v8::Boolean;
+ using v8::String;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsString())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ String::Utf8Value protocol(args[0]);
+ auto ret = ecore_file_download_protocol_available(*protocol);
+ return compatibility_return(compatibility_new<Boolean>(isolate, ret),
+ args);
+ };
+
+ exports->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_mkstemp(v8::Isolate *isolate,
+ v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsString())
+ return compatibility_return();
+
+ v8::String::Utf8Value buffer(args[0]);
+ char* buf = (char*)malloc(std::strlen(*buffer)+1);
+ struct free_buf
+ {
+ free_buf(char* p) : p(p) {}
+ ~free_buf() { free(p); }
+ char* p;
+ } free_buf_(buf);
+ std::strcpy(buf, *buffer);
+ int fd = mkstemp(buf);
+
+ if(fd > 0)
+ {
+ close(fd);
+
+ return compatibility_return(compatibility_new<v8::String>(nullptr, buf), args);
+ }
+ else
+ return compatibility_return();
+ };
+ exports->Set(name, compatibility_new<v8::FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_file_environment_tmp(v8::Isolate *isolate,
+ v8::Handle<v8::Object> exports,
+ v8::Handle<v8::String> name)
+{
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+
+ return compatibility_return(compatibility_new<v8::String>(nullptr, eina_environment_tmp_get()), args);
+ };
+ exports->Set(name, compatibility_new<v8::FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+}
+
+EAPI
+void register_ecore_file(v8::Isolate* isolate, v8::Handle<v8::Object> exports)
+{
+ register_file_event_none(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ECORE_FILE_EVENT_NONE"));
+ register_file_event_created_file(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ECORE_FILE_EVENT"
+ "_CREATED_FILE"));
+ register_file_event_created_directory(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate,
+ "ECORE_FILE_EVENT_CREATED_DIRECTORY"));
+ register_file_event_deleted_file(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ECORE_FILE_EVENT"
+ "_DELETED_FILE"));
+ register_file_event_deleted_directory(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate,
+ "ECORE_FILE_EVENT_DELETED_DIRECTORY"));
+ register_file_event_deleted_self(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ECORE_FILE_EVENT"
+ "_DELETED_SELF"));
+ register_file_event_modified(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ECORE_FILE_EVENT"
+ "_MODIFIED"));
+ register_file_event_closed(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ECORE_FILE_EVENT"
+ "_CLOSED"));
+ register_file_progress_continue(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate, "ECORE_FILE_PROGRESS_CONTINUE"));
+ register_file_progress_abort(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate, "ECORE_FILE_PROGRESS_ABORT"));
+ register_file_init(isolate, exports,
+ compatibility_new<v8::String>(isolate, "ecore_file_init"));
+ register_file_shutdown(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_file_shutdown"));
+ register_file_mod_time(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_file_mod_time"));
+ register_file_size(isolate, exports,
+ compatibility_new<v8::String>(isolate, "ecore_file_size"));
+ register_file_exists(isolate, exports,
+ compatibility_new<v8::String>(isolate, "ecore_file_exists"));
+ register_file_is_dir(isolate, exports,
+ compatibility_new<v8::String>(isolate, "ecore_file_is_dir"));
+ register_file_mkdir(isolate, exports,
+ compatibility_new<v8::String>(isolate, "ecore_file_mkdir"));
+ register_file_mkdirs(isolate, exports,
+ compatibility_new<v8::String>(isolate, "ecore_file_mkdirs"));
+ register_file_mksubdirs(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_file_mksubdirs"));
+ register_file_rmdir(isolate, exports,
+ compatibility_new<v8::String>(isolate, "ecore_file_rmdir"));
+ register_file_unlink(isolate, exports,
+ compatibility_new<v8::String>(isolate, "ecore_file_unlink"));
+ register_file_remove(isolate, exports,
+ compatibility_new<v8::String>(isolate, "ecore_file_remove"));
+ register_file_recursive_rm(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate, "ecore_file_recursive_rm"));
+ register_file_mkpath(isolate, exports,
+ compatibility_new<v8::String>(isolate, "ecore_file_mkpath"));
+ register_file_mkpaths(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_file_mkpaths"));
+ register_file_cp(isolate, exports,
+ compatibility_new<v8::String>(isolate, "ecore_file_cp"));
+ register_file_mv(isolate, exports,
+ compatibility_new<v8::String>(isolate, "ecore_file_mv"));
+ register_file_symlink(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_file_symlink"));
+ register_file_realpath(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_file_realpath"));
+ register_file_file_get(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_file_file_get"));
+ register_file_dir_get(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_file_dir_get"));
+ register_file_can_read(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_file_can_read"));
+ register_file_can_write(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_file_can_write"));
+ register_file_can_exec(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_file_can_exec"));
+ register_file_readlink(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_file_readlink"));
+ register_file_ls(isolate, exports,
+ compatibility_new<v8::String>(isolate, "ecore_file_ls"));
+ register_file_app_exe_get(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate, "ecore_file_app_exe_get"));
+ register_file_escape_name(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate, "ecore_file_escape_name"));
+ register_file_strip_ext(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_file_strip_ext"));
+ register_file_dir_is_empty(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate, "ecore_file_dir_is_empty"));
+ register_file_monitor_add(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate, "ecore_file_monitor_add"));
+ register_file_path_dir_exists(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate, "ecore_file_path_dir_exists"));
+ register_file_app_installed(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate, "ecore_file_app_installed"));
+ register_file_app_list(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_file_app_list"));
+ register_file_download(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_file_download"));
+ register_file_download_abort_all(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate, "ecore_file_download_abort_all"));
+ register_file_download_protocol_available(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate,
+ "ecore_file_download_protocol"
+ "_available"));
+ register_file_mkstemp(isolate, exports,
+ compatibility_new<v8::String>(isolate, "mkstemp"));
+ register_file_environment_tmp(isolate, exports,
+ compatibility_new<v8::String>(isolate, "environment_tmp"));
+}
+
+} } } // namespace efl { namespace ecore { namespace js {
diff --git a/src/bindings/ecore_js/ecore_js_idle.cc b/src/bindings/ecore_js/ecore_js_idle.cc
new file mode 100644
index 0000000000..293cef2f45
--- /dev/null
+++ b/src/bindings/ecore_js/ecore_js_idle.cc
@@ -0,0 +1,294 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <Ecore_Js.hh>
+
+namespace efl { namespace ecore { namespace js {
+
+static Ecore_Idler* extract_idler(v8::Local<v8::Object> object)
+{
+ auto ptr = v8::External::Cast(*object->GetInternalField(0))->Value();
+ return reinterpret_cast<Ecore_Idler*>(ptr);
+}
+
+static
+v8::Local<v8::Object> wrap_idler(Ecore_Idler *idler, v8::Isolate *isolate)
+{
+ using v8::Boolean;
+ using v8::String;
+ using v8::ObjectTemplate;
+ using v8::FunctionTemplate;
+
+ auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
+ obj_tpl->SetInternalFieldCount(1);
+ auto ret = obj_tpl->NewInstance();
+
+ auto del = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ ecore_idler_del(extract_idler(info.This()));
+ return compatibility_return();
+ };
+
+ ret->Set(compatibility_new<String>(isolate, "del"),
+ compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
+
+ ret->SetInternalField(0, compatibility_new<v8::External>(isolate, idler));
+
+ return ret;
+}
+
+static Ecore_Idle_Enterer* extract_idle_enterer(v8::Local<v8::Object> object)
+{
+ auto ptr = v8::External::Cast(*object->GetInternalField(0))->Value();
+ return reinterpret_cast<Ecore_Idle_Enterer*>(ptr);
+}
+
+static v8::Local<v8::Object> wrap_idle_enterer(Ecore_Idle_Enterer *idle_enterer,
+ v8::Isolate *isolate)
+{
+ using v8::Boolean;
+ using v8::String;
+ using v8::ObjectTemplate;
+ using v8::FunctionTemplate;
+ using v8::External;
+
+ auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
+ obj_tpl->SetInternalFieldCount(1);
+ auto ret = obj_tpl->NewInstance();
+
+ auto del = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ ecore_idle_enterer_del(extract_idle_enterer(info.This()));
+ return compatibility_return();
+ };
+
+ ret->Set(compatibility_new<String>(isolate, "del"),
+ compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
+
+ ret->SetInternalField(0,
+ compatibility_new<External>(isolate, idle_enterer));
+
+ return ret;
+}
+
+static Ecore_Idle_Exiter* extract_idle_exiter(v8::Local<v8::Object> object)
+{
+ auto ptr = v8::External::Cast(*object->GetInternalField(0))->Value();
+ return reinterpret_cast<Ecore_Idle_Exiter*>(ptr);
+}
+
+static v8::Local<v8::Object> wrap_idle_exiter(Ecore_Idle_Exiter *idle_exiter,
+ v8::Isolate *isolate)
+{
+ using v8::Boolean;
+ using v8::String;
+ using v8::ObjectTemplate;
+ using v8::FunctionTemplate;
+ using v8::External;
+
+ auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
+ obj_tpl->SetInternalFieldCount(1);
+ auto ret = obj_tpl->NewInstance();
+
+ auto del = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ ecore_idle_exiter_del(extract_idle_exiter(info.This()));
+ return compatibility_return();
+ };
+
+ ret->Set(compatibility_new<String>(isolate, "del"),
+ compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
+
+ ret->SetInternalField(0, compatibility_new<External>(isolate, idle_exiter));
+
+ return ret;
+}
+
+void register_idler_add(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Local;
+ using v8::Value;
+ using v8::Undefined;
+ using v8::Function;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsFunction())
+ return compatibility_return();
+
+ auto f = new efl::eina::js::global_ref<Value>(args.GetIsolate(), args[0]);
+ auto ret = ecore_idler_add([](void *data) -> Eina_Bool {
+ auto persistent = static_cast<efl::eina::js::global_ref<Value>*>(data);
+ auto o = persistent->handle();
+
+ auto ret = Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
+ auto bret = ret->IsBoolean() && ret->BooleanValue();
+
+ if (!bret)
+ {
+ persistent->dispose();
+ delete persistent;
+ }
+
+ return bret ? EINA_TRUE : EINA_FALSE;
+ }, f);
+
+ return compatibility_return(wrap_idler(ret, args.GetIsolate()), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_idle_enterer_add(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Local;
+ using v8::Value;
+ using v8::Undefined;
+ using v8::Function;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsFunction())
+ return compatibility_return();
+
+ auto f = new efl::eina::js::global_ref<Value>(args.GetIsolate(), args[0]);
+ auto ret = ecore_idle_enterer_add([](void *data) -> Eina_Bool {
+ auto persistent = static_cast<efl::eina::js::global_ref<Value>*>(data);
+ auto o = persistent->handle();
+
+ auto ret = Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
+ auto bret = ret->IsBoolean() && ret->BooleanValue();
+
+ if (!bret)
+ {
+ persistent->dispose();
+ delete persistent;
+ }
+
+ return bret ? EINA_TRUE : EINA_FALSE;
+ }, f);
+
+ return compatibility_return(wrap_idle_enterer(ret, args.GetIsolate()),
+ args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_idle_enterer_before_add(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Local;
+ using v8::Value;
+ using v8::Undefined;
+ using v8::Function;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsFunction())
+ return compatibility_return();
+
+ auto f = new efl::eina::js::global_ref<Value>(args.GetIsolate(), args[0]);
+ auto ret = ecore_idle_enterer_before_add([](void *data) -> Eina_Bool {
+ auto persistent = static_cast<efl::eina::js::global_ref<Value>*>(data);
+ auto o = persistent->handle();
+
+ auto ret = Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
+ auto bret = ret->IsBoolean() && ret->BooleanValue();
+
+ if (!bret)
+ {
+ persistent->dispose();
+ delete persistent;
+ }
+
+ return bret ? EINA_TRUE : EINA_FALSE;
+ }, f);
+
+ return compatibility_return(wrap_idle_enterer(ret, args.GetIsolate()),
+ args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_idle_exiter_add(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Local;
+ using v8::Value;
+ using v8::Undefined;
+ using v8::Function;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsFunction())
+ return compatibility_return();
+
+ auto f = new efl::eina::js::global_ref<Value>(args.GetIsolate(), args[0]);
+ auto ret = ecore_idle_exiter_add([](void *data) -> Eina_Bool {
+ auto persistent = static_cast<efl::eina::js::global_ref<Value>*>(data);
+ auto o = persistent->handle();
+
+ auto ret = Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
+ auto bret = ret->IsBoolean() && ret->BooleanValue();
+
+ if (!bret)
+ {
+ persistent->dispose();
+ delete persistent;
+ }
+
+ return bret ? EINA_TRUE : EINA_FALSE;
+ }, f);
+
+ return compatibility_return(wrap_idle_exiter(ret, args.GetIsolate()),
+ args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_ecore_idle(v8::Isolate *isolate,v8::Handle<v8::Object> exports)
+{
+ register_idler_add(isolate, exports,
+ compatibility_new<v8::String>(isolate, "ecore_idler_add"));
+ register_idle_enterer_add(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_idle_enterer"
+ "_add"));
+ register_idle_enterer_before_add(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_idle"
+ "_enterer_before"
+ "_add"));
+ register_idle_exiter_add(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_idle_exiter_add"));
+}
+
+} } } // namespace efl { namespace js {
diff --git a/src/bindings/ecore_js/ecore_js_init.cc b/src/bindings/ecore_js/ecore_js_init.cc
new file mode 100644
index 0000000000..724d16ae17
--- /dev/null
+++ b/src/bindings/ecore_js/ecore_js_init.cc
@@ -0,0 +1,77 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <Ecore_Js.hh>
+
+namespace efl { namespace ecore { namespace js {
+
+namespace {
+
+void register_init(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::FunctionTemplate;
+
+ auto init = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ::ecore_init();
+ return compatibility_return(compatibility_new<Integer>(isolate, ret),
+ args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, init)
+ ->GetFunction());
+}
+
+void register_shutdown(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::FunctionTemplate;
+
+ auto shutdown = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_shutdown();
+ return compatibility_return(compatibility_new<Integer>(isolate, ret),
+ args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, shutdown)
+ ->GetFunction());
+}
+
+}
+
+EAPI
+void register_ecore(v8::Isolate *isolate,v8::Handle<v8::Object> exports)
+{
+ efl::ecore::js::register_init(isolate, exports,
+ efl::eina::js::compatibility_new<v8::String>
+ (isolate, "ecore_init"));
+ efl::ecore::js::register_shutdown(isolate, exports,
+ efl::eina::js::compatibility_new<v8::String>
+ (isolate, "ecore_shutdown"));
+ register_ecore_animator(isolate, exports);
+ register_ecore_event(isolate, exports);
+ register_ecore_file(isolate, exports);
+ register_ecore_idle(isolate, exports);
+ register_ecore_job(isolate, exports);
+ register_ecore_mainloop(isolate, exports);
+ register_ecore_poller(isolate, exports);
+ register_ecore_throttle(isolate, exports);
+ register_ecore_timer(isolate, exports);
+}
+
+} } } // namespace efl { namespace js {
diff --git a/src/bindings/ecore_js/ecore_js_job.cc b/src/bindings/ecore_js/ecore_js_job.cc
new file mode 100644
index 0000000000..4ec438aaaf
--- /dev/null
+++ b/src/bindings/ecore_js/ecore_js_job.cc
@@ -0,0 +1,83 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <Ecore_Js.hh>
+
+namespace efl { namespace ecore { namespace js {
+
+static Ecore_Job* extract_job(v8::Local<v8::Object> object)
+{
+ auto ptr = v8::External::Cast(*object->GetInternalField(0))->Value();
+ return reinterpret_cast<Ecore_Job*>(ptr);
+}
+
+static v8::Local<v8::Object> wrap_job(Ecore_Job *job, v8::Isolate *isolate)
+{
+ using v8::Boolean;
+ using v8::String;
+ using v8::ObjectTemplate;
+ using v8::FunctionTemplate;
+
+ auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
+ obj_tpl->SetInternalFieldCount(1);
+ auto ret = obj_tpl->NewInstance();
+
+ auto del = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ ecore_job_del(extract_job(info.This()));
+ return compatibility_return();
+ };
+
+ ret->Set(compatibility_new<String>(isolate, "del"),
+ compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
+
+ ret->SetInternalField(0, compatibility_new<v8::External>(isolate, job));
+
+ return ret;
+}
+
+EAPI
+void register_job_add(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Local;
+ using v8::Value;
+ using v8::Undefined;
+ using v8::Function;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsFunction())
+ return compatibility_return();
+
+ auto f = new efl::eina::js::global_ref<Value>(args.GetIsolate(), args[0]);
+ auto ret = ecore_job_add([](void *data) {
+ auto persistent = static_cast<efl::eina::js::global_ref<Value>*>(data);
+ auto o = persistent->handle();
+
+ Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
+
+ persistent->dispose();
+ delete persistent;
+ }, f);
+
+ return compatibility_return(wrap_job(ret, args.GetIsolate()), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_ecore_job(v8::Isolate *isolate,v8::Handle<v8::Object> exports)
+{
+ register_job_add(isolate, exports,
+ compatibility_new<v8::String>(isolate, "ecore_job_add"));
+}
+
+} } } // namespace efl { namespace js {
diff --git a/src/bindings/ecore_js/ecore_js_mainloop.cc b/src/bindings/ecore_js/ecore_js_mainloop.cc
new file mode 100644
index 0000000000..180b35f0f6
--- /dev/null
+++ b/src/bindings/ecore_js/ecore_js_mainloop.cc
@@ -0,0 +1,207 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <Ecore_Js.hh>
+
+namespace efl { namespace ecore { namespace js {
+
+namespace {
+
+void register_callback_cancel(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Boolean;
+ global->Set(name, compatibility_new<Boolean>(isolate,
+ bool{ECORE_CALLBACK_CANCEL}));
+}
+
+void register_callback_renew(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Boolean;
+ global->Set(name, compatibility_new<Boolean>(isolate,
+ bool{ECORE_CALLBACK_RENEW}));
+}
+
+void register_callback_pass_on(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Boolean;
+ global->Set(name, compatibility_new<Boolean>(isolate,
+ bool{ECORE_CALLBACK_PASS_ON}));
+}
+
+void register_callback_done(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Boolean;
+ global->Set(name, compatibility_new<Boolean>(isolate,
+ bool{ECORE_CALLBACK_DONE}));
+}
+
+void register_mainloop_iterate(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 0)
+ return compatibility_return();
+
+ ecore_main_loop_iterate();
+ return compatibility_return();
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_mainloop_iterate_may_block(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsNumber())
+ return compatibility_return();
+
+ auto ret = ecore_main_loop_iterate_may_block(args[0]->NumberValue());
+ return compatibility_return(compatibility_new<Integer>
+ (args.GetIsolate(), ret), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_mainloop_begin(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 0)
+ return compatibility_return();
+
+ ecore_main_loop_begin();
+ return compatibility_return();
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_mainloop_quit(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 0)
+ return compatibility_return();
+
+ ecore_main_loop_quit();
+ return compatibility_return();
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_mainloop_animator_ticked_get(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Boolean;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 0)
+ return compatibility_return();
+
+ auto ret = ecore_main_loop_animator_ticked_get();
+ return compatibility_return(compatibility_new<Boolean>
+ (args.GetIsolate(), ret), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_mainloop_nested_get(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Boolean;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 0)
+ return compatibility_return();
+
+ auto ret = ecore_main_loop_nested_get();
+ return compatibility_return(compatibility_new<Boolean>
+ (args.GetIsolate(), ret), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+}
+
+EAPI
+void register_ecore_mainloop(v8::Isolate *isolate,v8::Handle<v8::Object> exports)
+{
+ register_callback_cancel(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate, "ECORE_CALLBACK_CANCEL"));
+ register_callback_renew(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate, "ECORE_CALLBACK_RENEW"));
+ register_callback_pass_on(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate, "ECORE_CALLBACK_PASS_ON"));
+ register_callback_done(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate, "ECORE_CALLBACK_DONE"));
+ register_mainloop_iterate(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate, "ecore_mainloop_iterate"));
+ register_mainloop_iterate_may_block(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate,
+ "ecore_mainloop_iterate_may_block"));
+ register_mainloop_begin(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate, "ecore_mainloop_begin"));
+ register_mainloop_quit(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate, "ecore_mainloop_quit"));
+ register_mainloop_animator_ticked_get(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate,
+ "ecore_mainlop_animator_ticked_get"));
+ register_mainloop_nested_get(isolate, exports,
+ compatibility_new<v8::String>
+ (isolate, "ecore_mainloop_nested_get"));
+}
+
+} } } // namespace efl { namespace js {
diff --git a/src/bindings/ecore_js/ecore_js_poller.cc b/src/bindings/ecore_js/ecore_js_poller.cc
new file mode 100644
index 0000000000..e3bfbc843a
--- /dev/null
+++ b/src/bindings/ecore_js/ecore_js_poller.cc
@@ -0,0 +1,190 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <Ecore_Js.hh>
+
+namespace efl { namespace ecore { namespace js {
+
+namespace {
+
+Ecore_Poller* extract_poller(v8::Local<v8::Object> object)
+{
+ auto ptr = v8::External::Cast(*object->GetInternalField(0))->Value();
+ return reinterpret_cast<Ecore_Poller*>(ptr);
+}
+
+v8::Local<v8::Object> wrap_poller(Ecore_Poller *poller,
+ v8::Isolate *isolate)
+{
+ using v8::Boolean;
+ using v8::String;
+ using v8::ObjectTemplate;
+ using v8::FunctionTemplate;
+
+ auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
+ obj_tpl->SetInternalFieldCount(1);
+ auto ret = obj_tpl->NewInstance();
+
+ auto del = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ ecore_poller_del(extract_poller(info.This()));
+ return compatibility_return();
+ };
+
+ ret->Set(compatibility_new<String>(isolate, "del"),
+ compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
+
+ ret->SetInternalField(0, compatibility_new<v8::External>(isolate, poller));
+
+ return ret;
+}
+
+void register_poller_core(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+
+ global->Set(name, compatibility_new<Integer>(isolate, ECORE_POLLER_CORE));
+}
+
+void register_poller_poll_interval_set(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 2 || !args[0]->IsNumber() || !args[1]->IsNumber())
+ return compatibility_return();
+
+ Ecore_Poller_Type type;
+
+ switch ((int)(args[0]->NumberValue())) {
+ case ECORE_POLLER_CORE:
+ type = ECORE_POLLER_CORE;
+ break;
+ default:
+ return compatibility_return();
+ }
+
+ ecore_poller_poll_interval_set(type, args[1]->NumberValue());
+ return compatibility_return();
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_poller_poll_interval_get(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsNumber())
+ return compatibility_return();
+
+ Ecore_Poller_Type type;
+
+ switch ((int)(args[0]->NumberValue())) {
+ case ECORE_POLLER_CORE:
+ type = ECORE_POLLER_CORE;
+ break;
+ default:
+ return compatibility_return();
+ }
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_poller_poll_interval_get(type);
+ return compatibility_return(compatibility_new<Integer>(isolate, ret),
+ args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_poller_add(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::Value;
+ using v8::FunctionTemplate;
+ using v8::Isolate;
+ using v8::Function;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 3 || !args[0]->IsNumber() || !args[1]->IsNumber()
+ || !args[2]->IsFunction()) {
+ return compatibility_return();
+ }
+
+ Ecore_Poller_Type type;
+
+ switch ((int)(args[0]->NumberValue())) {
+ case ECORE_POLLER_CORE:
+ type = ECORE_POLLER_CORE;
+ break;
+ default:
+ return compatibility_return();
+ }
+
+ auto isolate = args.GetIsolate();
+ auto f = new efl::eina::js::global_ref<Value>(isolate, args[2]);
+
+ auto cb = [](void *data) -> Eina_Bool {
+ auto persistent = static_cast<efl::eina::js::global_ref<Value>*>(data);
+ auto o = persistent->handle();
+
+ auto ret = Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
+ auto bret = ret->IsBoolean() && ret->BooleanValue();
+
+ if (!bret)
+ {
+ persistent->dispose();
+ delete persistent;
+ }
+
+ return bret ? EINA_TRUE : EINA_FALSE;
+ };
+
+ auto ret = ecore_poller_add(type, args[1]->NumberValue(), cb, f);
+ return compatibility_return(wrap_poller(ret, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+}
+
+EAPI
+void register_ecore_poller(v8::Isolate *isolate,v8::Handle<v8::Object> exports)
+{
+ register_poller_core(isolate, exports,
+ compatibility_new<v8::String>(isolate, "ECORE_POLLER_CORE"));
+ register_poller_poll_interval_set(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_poller"
+ "_poll_interval"
+ "_set"));
+ register_poller_poll_interval_get(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_poller"
+ "_poll_interval"
+ "_get"));
+ register_poller_add(isolate, exports,
+ compatibility_new<v8::String>(isolate, "ecore_poller_add"));
+}
+
+} } } // namespace efl { namespace js {
diff --git a/src/bindings/ecore_js/ecore_js_throttle.cc b/src/bindings/ecore_js/ecore_js_throttle.cc
new file mode 100644
index 0000000000..830a40fec6
--- /dev/null
+++ b/src/bindings/ecore_js/ecore_js_throttle.cc
@@ -0,0 +1,63 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <Ecore_Js.hh>
+
+namespace efl { namespace ecore { namespace js {
+
+namespace {
+
+void register_throttle_adjust(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsNumber())
+ return compatibility_return();
+
+ ecore_throttle_adjust(args[0]->NumberValue());
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_throttle_get(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Number;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_throttle_get();
+ return compatibility_return(compatibility_new<Number>(isolate, ret),
+ args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+}
+
+EAPI
+void register_ecore_throttle(v8::Isolate *isolate,v8::Handle<v8::Object> exports)
+{
+ register_throttle_adjust(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_throttle_adjust"));
+ register_throttle_get(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_throttle_get"));
+}
+
+} } } // namespace efl { namespace js {
diff --git a/src/bindings/ecore_js/ecore_js_timer.cc b/src/bindings/ecore_js/ecore_js_timer.cc
new file mode 100644
index 0000000000..38a3e51fac
--- /dev/null
+++ b/src/bindings/ecore_js/ecore_js_timer.cc
@@ -0,0 +1,263 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <Ecore_Js.hh>
+
+#include <memory>
+#include <cstdlib>
+
+namespace efl { namespace ecore { namespace js {
+
+namespace {
+
+Ecore_Timer* extract_timer(v8::Local<v8::Object> object)
+{
+ auto ptr = v8::External::Cast(*object->GetInternalField(0))->Value();
+ return reinterpret_cast<Ecore_Timer*>(ptr);
+}
+
+v8::Local<v8::Object> wrap_timer(Ecore_Timer *timer,
+ v8::Isolate *isolate)
+{
+ using v8::Boolean;
+ using v8::String;
+ using v8::ObjectTemplate;
+ using v8::FunctionTemplate;
+
+ auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
+ obj_tpl->SetInternalFieldCount(1);
+ auto ret = obj_tpl->NewInstance();
+
+ auto del = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ ecore_timer_del(extract_timer(info.This()));
+ return compatibility_return();
+ };
+
+ auto freeze = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ ecore_timer_freeze(extract_timer(info.This()));
+ return compatibility_return();
+ };
+
+ auto freeze_get = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto ret = ecore_timer_freeze_get(extract_timer(info.This()));
+ return compatibility_return(compatibility_new<Boolean>
+ (info.GetIsolate(), bool(ret)),
+ info);
+ };
+
+ auto thaw = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ ecore_timer_thaw(extract_timer(info.This()));
+ return compatibility_return();
+ };
+
+ ret->Set(compatibility_new<String>(isolate, "del"),
+ compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "freeze"),
+ compatibility_new<FunctionTemplate>(isolate, freeze)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "freeze_get"),
+ compatibility_new<FunctionTemplate>(isolate, freeze_get)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "thaw"),
+ compatibility_new<FunctionTemplate>(isolate, thaw)->GetFunction());
+
+ ret->SetInternalField(0, compatibility_new<v8::External>(isolate, timer));
+
+ return ret;
+}
+
+void register_timer_precision_get(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Number;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 0)
+ return compatibility_return();
+
+ auto ret = ecore_timer_precision_get();
+ return compatibility_return(compatibility_new<Number>
+ (args.GetIsolate(), ret), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_timer_precision_set(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsNumber())
+ return compatibility_return();
+
+ ecore_timer_precision_set(args[0]->NumberValue());
+ return compatibility_return();
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_timer_dump(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::String;
+ using v8::FunctionTemplate;
+ using std::unique_ptr;
+ using std::free;
+ using std::unique_ptr;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 0)
+ return compatibility_return();
+
+ auto dump = unique_ptr<char, void(*)(char*)>(ecore_timer_dump(),
+ [](char *str) {
+ free(str);
+ });
+ auto ret = (dump
+ ? compatibility_new<String>(args.GetIsolate(), dump.get())
+ : compatibility_new<String>(args.GetIsolate(), ""));
+
+ return compatibility_return(ret, args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_timer_add(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Local;
+ using v8::Value;
+ using v8::Undefined;
+ using v8::Function;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 2 || !args[0]->IsNumber()
+ || !args[1]->IsFunction()) {
+ return compatibility_return();
+ }
+
+ auto f = new efl::eina::js::global_ref<Value>(args.GetIsolate(), args[1]);
+
+ auto cb = [](void *data) -> Eina_Bool {
+ auto persistent = reinterpret_cast<efl::eina::js::global_ref<Value>*>(data);
+ auto o = persistent->handle();
+
+ auto ret = Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
+ auto bret = ret->IsBoolean() && ret->BooleanValue();
+
+ if (!bret)
+ {
+ persistent->dispose();
+ delete persistent;
+ }
+
+ return bret ? EINA_TRUE : EINA_FALSE;
+ };
+
+ auto ret = ecore_timer_add(args[0]->NumberValue(), cb, f);
+ return compatibility_return(wrap_timer(ret, args.GetIsolate()), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_timer_loop_add(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Local;
+ using v8::Value;
+ using v8::Undefined;
+ using v8::Function;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 2 || !args[0]->IsNumber()
+ || !args[1]->IsFunction()) {
+ return compatibility_return();
+ }
+
+ auto f = new efl::eina::js::global_ref<Value>(args.GetIsolate(), args[1]);
+
+ auto cb = [](void *d) -> Eina_Bool {
+ auto persistent = static_cast<efl::eina::js::global_ref<Value>*>(d);
+ auto o = persistent->handle();
+
+ auto ret = Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
+ auto bret = ret->IsBoolean() && ret->BooleanValue();
+
+ if (!bret)
+ {
+ persistent->dispose();
+ delete persistent;
+ }
+
+ return bret ? EINA_TRUE : EINA_FALSE;
+ };
+
+ auto ret = ecore_timer_loop_add(args[0]->NumberValue(), cb, f);
+
+ return compatibility_return(wrap_timer(ret, args.GetIsolate()), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+}
+
+EAPI
+void register_ecore_timer(v8::Isolate *isolate,v8::Handle<v8::Object> exports)
+{
+ register_timer_precision_get(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_timer_precision"
+ "_get"));
+ register_timer_precision_set(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_timer_precision"
+ "_set"));
+ register_timer_dump(isolate, exports,
+ compatibility_new<v8::String>(isolate, "ecore_timer_dump"));
+ register_timer_add(isolate, exports,
+ compatibility_new<v8::String>(isolate, "ecore_timer_add"));
+ register_timer_loop_add(isolate, exports,
+ compatibility_new<v8::String>(isolate,
+ "ecore_timer_loop_add"));
+}
+
+} } } // namespace efl { namespace ecore { namespace js {
diff --git a/src/bindings/ecore_js/ecore_js_timer.hh b/src/bindings/ecore_js/ecore_js_timer.hh
new file mode 100644
index 0000000000..e002587ee4
--- /dev/null
+++ b/src/bindings/ecore_js/ecore_js_timer.hh
@@ -0,0 +1,38 @@
+#ifndef ECORE_JS_TIMER_HH
+#define ECORE_JS_TIMER_HH
+
+#include <Eina.hh>
+
+#include <Eina_Js.hh>
+
+namespace efl { namespace ecore { namespace js {
+
+using ::efl::eina::js::compatibility_new;
+using ::efl::eina::js::compatibility_return_type;
+using ::efl::eina::js::compatibility_callback_info_type;
+using ::efl::eina::js::compatibility_return;
+using ::efl::eina::js::compatibility_get_pointer_internal_field;
+using ::efl::eina::js::compatibility_set_pointer_internal_field;
+using ::efl::eina::js::compatibility_persistent;
+
+void register_timer_precision_get(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_timer_precision_set(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_timer_dump(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_timer_add(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_timer_loop_add(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+} } } // namespace efl::js
+
+#endif /* ECORE_JS_TIMER_HH */
diff --git a/src/bindings/eina_cxx/Eina.hh b/src/bindings/eina_cxx/Eina.hh
index d12b0c930f..8f5462892e 100644
--- a/src/bindings/eina_cxx/Eina.hh
+++ b/src/bindings/eina_cxx/Eina.hh
@@ -22,6 +22,7 @@
#include <eina_log.hh>
#include <eina_optional.hh>
#include <eina_integer_sequence.hh>
+#include <eina_pp.hh>
/**
* @page eina_cxx_main Eina C++ (BETA)
diff --git a/src/bindings/eina_cxx/eina_accessor.hh b/src/bindings/eina_cxx/eina_accessor.hh
index b867f14248..d084918ca8 100644
--- a/src/bindings/eina_cxx/eina_accessor.hh
+++ b/src/bindings/eina_cxx/eina_accessor.hh
@@ -114,7 +114,10 @@ struct accessor_common_base
* @warning It is important to take care when using it, since the
* handle will be automatically release upon object destruction.
*/
- Eina_Accessor* native_handle() const;
+ Eina_Accessor* native_handle() const
+ {
+ return _impl;
+ }
/**
* @brief Swap content between both objects.
diff --git a/src/bindings/eina_cxx/eina_array.hh b/src/bindings/eina_cxx/eina_array.hh
index eb9e5578aa..d352de5ab7 100644
--- a/src/bindings/eina_cxx/eina_array.hh
+++ b/src/bindings/eina_cxx/eina_array.hh
@@ -32,6 +32,8 @@ public:
typedef typename _base_type::reverse_iterator reverse_iterator; /**< Type for reverse iterator for this container. */
typedef typename _base_type::const_reverse_iterator const_reverse_iterator; /**< Type for reverse iterator for this container. */
+ typedef typename _base_type::native_handle_type native_handle_type;
+
using _base_type::_base_type;
using _base_type::clear;
using _base_type::size;
@@ -59,6 +61,7 @@ public:
using _base_type::ciend;
using _base_type::swap;
using _base_type::max_size;
+ using _base_type::release_native_handle;
using _base_type::native_handle;
friend bool operator==(array<T, CloneAllocator> const& lhs, array<T, CloneAllocator> const& rhs)
@@ -131,6 +134,101 @@ struct _ptr_eo_array_iterator : _ptr_array_iterator<Eo>
using _base_type::native_handle;
};
+/**
+ * @internal
+ */
+struct _eo_array_access_traits : _ptr_array_access_traits
+{
+ template <typename T>
+ struct iterator
+ {
+ typedef _ptr_eo_array_iterator<T> type;
+ };
+ template <typename T>
+ struct const_iterator : iterator<T const> {};
+
+ template <typename T>
+ static T& back(Eina_Array* array)
+ {
+ return *static_cast<T*>(static_cast<void*>(array->data[size<T>(array)-1]));
+ }
+ template <typename T>
+ static T const& back(Eina_Array const* array)
+ {
+ return _eo_array_access_traits::back<T>(const_cast<Eina_Array*>(array));
+ }
+ template <typename T>
+ static T& front(Eina_Array* array)
+ {
+ return *static_cast<T*>(static_cast<void*>(array->data[0]));
+ }
+ template <typename T>
+ static T const& front(Eina_Array const* array)
+ {
+ return _eo_array_access_traits::front<T>(const_cast<Eina_Array*>(array));
+ }
+ template <typename T>
+ static typename iterator<T>::type begin(Eina_Array* array)
+ {
+ return _ptr_eo_array_iterator<T>(array->data);
+ }
+ template <typename T>
+ static typename iterator<T>::type end(Eina_Array* array)
+ {
+ return _ptr_eo_array_iterator<T>(array->data + size<T>(array));
+ }
+ template <typename T>
+ static typename const_iterator<T>::type begin(Eina_Array const* array)
+ {
+ return _eo_array_access_traits::begin<T>(const_cast<Eina_Array*>(array));
+ }
+ template <typename T>
+ static typename const_iterator<T>::type end(Eina_Array const* array)
+ {
+ return _eo_array_access_traits::end<T>(const_cast<Eina_Array*>(array));
+ }
+ template <typename T>
+ static std::reverse_iterator<typename iterator<T>::type> rbegin(Eina_Array* array)
+ {
+ return std::reverse_iterator<_ptr_eo_array_iterator<T> >(_eo_array_access_traits::end<T>(array));
+ }
+ template <typename T>
+ static std::reverse_iterator<typename iterator<T>::type> rend(Eina_Array* array)
+ {
+ return std::reverse_iterator<_ptr_eo_array_iterator<T> >(_eo_array_access_traits::begin<T>(array));
+ }
+ template <typename T>
+ static std::reverse_iterator<typename const_iterator<T>::type> rbegin(Eina_Array const* array)
+ {
+ return std::reverse_iterator<_ptr_eo_array_iterator<T>const>(_eo_array_access_traits::end<T>(array));
+ }
+ template <typename T>
+ static std::reverse_iterator<typename const_iterator<T>::type> rend(Eina_Array const* array)
+ {
+ return std::reverse_iterator<_ptr_eo_array_iterator<T>const>(_eo_array_access_traits::begin<T>(array));
+ }
+ template <typename T>
+ static typename const_iterator<T>::type cbegin(Eina_Array const* array)
+ {
+ return _eo_array_access_traits::begin<T>(array);
+ }
+ template <typename T>
+ static typename const_iterator<T>::type cend(Eina_Array const* array)
+ {
+ return _eo_array_access_traits::end<T>(array);
+ }
+ template <typename T>
+ static std::reverse_iterator<typename const_iterator<T>::type> crbegin(Eina_Array const* array)
+ {
+ return _eo_array_access_traits::rbegin<T>(array);
+ }
+ template <typename T>
+ static std::reverse_iterator<typename const_iterator<T>::type> crend(Eina_Array const* array)
+ {
+ return _eo_array_access_traits::rend<T>(array);
+ }
+};
+
template <typename T, typename CloneAllocator>
class array<T, CloneAllocator, typename std::enable_if<std::is_base_of<::efl::eo::concrete, T>::value>::type>
: ptr_array<Eo, typename std::conditional
@@ -156,7 +254,9 @@ public:
typedef std::reverse_iterator<iterator> reverse_iterator; /**< Type for reverse iterator for this container. */
typedef std::reverse_iterator<const_iterator> const_reverse_iterator; /**< Type for reverse iterator for this container. */
- explicit array(Eina_Array* handle)
+ typedef typename _base_type::native_handle_type native_handle_type; /**< Type for the native handle of the container. */
+
+ explicit array(native_handle_type handle)
: _base_type(handle) {}
array(clone_allocator_type alloc) : _base_type(alloc) {}
array() {}
@@ -318,6 +418,7 @@ public:
using _base_type::swap;
using _base_type::max_size;
+ using _base_type::release_native_handle;
using _base_type::native_handle;
friend bool operator==(array<T, CloneAllocator> const& lhs, array<T, CloneAllocator> const& rhs)
@@ -331,7 +432,154 @@ bool operator!=(array<T, CloneAllocator> const& lhs, array<T, CloneAllocator> co
{
return !(lhs == rhs);
}
+
+template <typename T, typename Enable = void>
+class range_array : range_ptr_array<T>
+{
+ typedef range_ptr_array<T> _base_type;
+public:
+ typedef typename _base_type::value_type value_type;
+ typedef typename _base_type::reference reference;
+ typedef typename _base_type::const_reference const_reference;
+ typedef typename _base_type::const_iterator const_iterator;
+ typedef typename _base_type::iterator iterator;
+ typedef typename _base_type::pointer pointer;
+ typedef typename _base_type::const_pointer const_pointer;
+ typedef typename _base_type::size_type size_type;
+ typedef typename _base_type::difference_type difference_type;
+
+ typedef typename _base_type::reverse_iterator reverse_iterator;
+ typedef typename _base_type::const_reverse_iterator const_reverse_iterator;
+
+ typedef typename _base_type::native_handle_type native_handle_type;
+
+ range_array& operator=(range_array&& other) = default;
+
+ using _base_type::_base_type;
+ using _base_type::size;
+ using _base_type::empty;
+ using _base_type::back;
+ using _base_type::front;
+ using _base_type::begin;
+ using _base_type::end;
+ using _base_type::rbegin;
+ using _base_type::rend;
+ using _base_type::cbegin;
+ using _base_type::cend;
+ using _base_type::crbegin;
+ using _base_type::crend;
+ using _base_type::release_native_handle;
+ using _base_type::native_handle;
+};
+
+template <typename T>
+class range_array<T, typename std::enable_if<std::is_base_of<::efl::eo::concrete, T>::value>::type>
+ : range_ptr_array<Eo>
+{
+ typedef range_ptr_array<Eo> _base_type;
+ typedef range_array<T> _self_type;
+public:
+ typedef T value_type;
+ typedef value_type& reference;
+ typedef value_type const& const_reference;
+ typedef _ptr_eo_array_iterator<value_type const> const_iterator;
+ typedef _ptr_eo_array_iterator<value_type> iterator;
+ typedef value_type* pointer;
+ typedef value_type const* const_pointer;
+ typedef std::size_t size_type;
+ typedef std::ptrdiff_t difference_type;
+
+ typedef std::reverse_iterator<iterator> reverse_iterator;
+ typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
+
+ typedef typename _base_type::native_handle_type native_handle_type;
+
+ explicit range_array(native_handle_type handle)
+ : _base_type(handle) {}
+ range_array() {}
+ range_array(range_array<T> const& other)
+ : _base_type(other.native_handle())
+ {
+ }
+ range_array<T>& operator=(range_array<T>const& other)
+ {
+ _base_type::_handle = other._handle;
+ return *this;
+ }
+ range_array& operator=(range_array&& other) = default;
+ range_array(range_array&& other) = default;
+ using _base_type::size;
+ using _base_type::empty;
+
+ reference front()
+ {
+ return _eo_array_access_traits::front<value_type>(native_handle());
+ }
+ reference back()
+ {
+ return _eo_array_access_traits::back<value_type>(native_handle());
+ }
+ const_reference front() const { return const_cast<_self_type*>(this)->front(); }
+ const_reference back() const { return const_cast<_self_type*>(this)->back(); }
+ iterator begin()
+ {
+ return _eo_array_access_traits::begin<value_type>(native_handle());
+ }
+ iterator end()
+ {
+ return _eo_array_access_traits::end<value_type>(native_handle());
+ }
+ const_iterator begin() const
+ {
+ return const_cast<_self_type*>(this)->begin();
+ }
+ const_iterator end() const
+ {
+ return const_cast<_self_type*>(this)->end();
+ }
+ const_iterator cbegin() const
+ {
+ return begin();
+ }
+ const_iterator cend() const
+ {
+ return end();
+ }
+ reverse_iterator rbegin()
+ {
+ return _eo_array_access_traits::rbegin<value_type>(native_handle());
+ }
+ reverse_iterator rend()
+ {
+ return _eo_array_access_traits::rend<value_type>(native_handle());
+ }
+ const_reverse_iterator rbegin() const
+ {
+ return const_cast<_self_type*>(this)->rbegin();
+ }
+ const_reverse_iterator rend() const
+ {
+ return const_cast<_self_type*>(this)->rend();
+ }
+ const_reverse_iterator crbegin() const
+ {
+ return rbegin();
+ }
+ const_reverse_iterator crend() const
+ {
+ return rend();
+ }
+ using _base_type::swap;
+ using _base_type::release_native_handle;
+ using _base_type::native_handle;
+
+ friend bool operator==(range_array<T> const& rhs, range_array<T> const& lhs)
+ {
+ return rhs.size() == lhs.size() && std::equal(rhs.begin(), rhs.end(), lhs.begin());
+ }
+};
+
} }
#endif
diff --git a/src/bindings/eina_cxx/eina_clone_allocators.hh b/src/bindings/eina_cxx/eina_clone_allocators.hh
index 824d6d6ce9..76ff620f98 100644
--- a/src/bindings/eina_cxx/eina_clone_allocators.hh
+++ b/src/bindings/eina_cxx/eina_clone_allocators.hh
@@ -154,7 +154,8 @@ struct malloc_clone_allocator
template <typename T>
static void deallocate_clone(T const* p)
{
- static_assert(std::is_pod<T>::value, "malloc_clone_allocator can only be used with POD types");
+ static_assert(std::is_pod<T>::value || std::is_void<T>::value
+ , "malloc_clone_allocator can only be used with POD types");
std::free(const_cast<T*>(p));
}
};
diff --git a/src/bindings/eina_cxx/eina_function.hh b/src/bindings/eina_cxx/eina_function.hh
new file mode 100644
index 0000000000..cef6da5a43
--- /dev/null
+++ b/src/bindings/eina_cxx/eina_function.hh
@@ -0,0 +1,26 @@
+#ifndef EFL_EINA_FUNCTION_HH
+#define EFL_EINA_FUNCTION_HH
+
+namespace efl { namespace eina { namespace _mpl {
+
+template <typename T>
+struct function_params;
+
+template <typename R, typename... P>
+struct function_params<R(*)(P...)>
+{
+ typedef std::tuple<P...> type;
+};
+
+template <typename T>
+struct function_return;
+
+template <typename R, typename... P>
+struct function_return<R(*)(P...)>
+{
+ typedef R type;
+};
+
+} } }
+
+#endif
diff --git a/src/bindings/eina_cxx/eina_integer_sequence.hh b/src/bindings/eina_cxx/eina_integer_sequence.hh
index 854bb8f3d0..f99c871c34 100644
--- a/src/bindings/eina_cxx/eina_integer_sequence.hh
+++ b/src/bindings/eina_cxx/eina_integer_sequence.hh
@@ -1,6 +1,8 @@
#ifndef EINA_CXX_EINA_INTEGER_SEQUENCE_HH
#define EINA_CXX_EINA_INTEGER_SEQUENCE_HH
+#include <cstdlib>
+
/**
* @addtogroup Eina_Cxx_Data_Types_Group
*
diff --git a/src/bindings/eina_cxx/eina_list.hh b/src/bindings/eina_cxx/eina_list.hh
index 760ada3963..1221867c7b 100644
--- a/src/bindings/eina_cxx/eina_list.hh
+++ b/src/bindings/eina_cxx/eina_list.hh
@@ -190,6 +190,8 @@ public:
typedef typename _base_type::reverse_iterator reverse_iterator;
typedef typename _base_type::const_reverse_iterator const_reverse_iterator;
+ using _base_type::native_handle_type;
+
list& operator=(list&& other) = default;
list(list&& other) = default;
list() = default;
@@ -224,6 +226,7 @@ public:
using _base_type::max_size;
using _base_type::native_handle;
using _base_type::accessor;
+ using _base_type::release_native_handle;
};
template <typename T, typename CloneAllocator>
@@ -251,7 +254,9 @@ public:
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
- explicit list(Eina_List* handle)
+ using _base_type::native_handle_type;
+
+ explicit list(typename _self_type::native_handle_type handle)
: _base_type(handle) {}
list(clone_allocator_type alloc) : _base_type(alloc) {}
list() {}
@@ -295,6 +300,7 @@ public:
using _base_type::get_clone_allocator;
using _base_type::pop_back;
using _base_type::pop_front;
+ using _base_type::release_native_handle;
void push_back(const_reference w)
{
@@ -464,6 +470,8 @@ public:
typedef typename _base_type::reverse_iterator reverse_iterator;
typedef typename _base_type::const_reverse_iterator const_reverse_iterator;
+ using _base_type::native_handle_type;
+
using _base_type::_base_type;
using _base_type::size;
using _base_type::empty;
@@ -501,9 +509,9 @@ public:
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
- typedef typename _base_type::native_handle_type native_handle_type;
+ using _base_type::native_handle_type;
- explicit range_list(native_handle_type handle)
+ explicit range_list(typename _self_type::native_handle_type handle)
: _base_type(handle) {}
range_list() {}
range_list(range_list<T> const& other)
diff --git a/src/bindings/eina_cxx/eina_logical.hh b/src/bindings/eina_cxx/eina_logical.hh
new file mode 100644
index 0000000000..d53d3541ad
--- /dev/null
+++ b/src/bindings/eina_cxx/eina_logical.hh
@@ -0,0 +1,34 @@
+#ifndef EFL_EINA_LOGICAL_HH
+#define EFL_EINA_LOGICAL_HH
+
+#include <type_traits>
+
+namespace efl { namespace eina { namespace _mpl {
+
+template <bool... N>
+struct or_;
+
+template <>
+struct or_<> : std::integral_constant<bool, false> {};
+
+template <bool B>
+struct or_<B> : std::integral_constant<bool, B> {};
+
+template <bool B1, bool B2, bool... Bs>
+struct or_<B1, B2, Bs...> : std::integral_constant<bool, B1 || B2 || or_<Bs...>::value> {};
+
+template <bool... N>
+struct and_;
+
+template <>
+struct and_<> : std::integral_constant<bool, true> {};
+
+template <bool B>
+struct and_<B> : std::integral_constant<bool, B> {};
+
+template <bool B1, bool B2, bool... Bs>
+struct and_<B1, B2, Bs...> : std::integral_constant<bool, B1 && B2 && and_<Bs...>::value> {};
+
+} } }
+
+#endif
diff --git a/src/bindings/eina_cxx/eina_pp.hh b/src/bindings/eina_cxx/eina_pp.hh
new file mode 100644
index 0000000000..22a6a22ef7
--- /dev/null
+++ b/src/bindings/eina_cxx/eina_pp.hh
@@ -0,0 +1,8 @@
+
+#ifndef EINA_PP_HH
+#define EINA_PP_HH
+
+#define EINA_STRINGIZE_IMPL(x) #x
+#define EINA_STRINGIZE(x) EINA_STRINGIZE_IMPL(x)
+
+#endif
diff --git a/src/bindings/eina_cxx/eina_ptrarray.hh b/src/bindings/eina_cxx/eina_ptrarray.hh
index 2f40627ce9..f47202ebb5 100644
--- a/src/bindings/eina_cxx/eina_ptrarray.hh
+++ b/src/bindings/eina_cxx/eina_ptrarray.hh
@@ -295,10 +295,12 @@ struct range_ptr_array : _range_template<T, _ptr_array_access_traits>
typedef _range_template<T, _ptr_array_access_traits> _base_type; /**< Type for the base class. */
typedef typename _base_type::value_type value_type; /**< The type of each element. */
+ typedef typename _base_type::native_handle_type native_handle_type;
+
/**
* @brief Creates a range from a native Eina array handle.
*/
- range_ptr_array(Eina_Array* array)
+ range_ptr_array(native_handle_type array)
: _base_type(array)
{}
@@ -391,7 +393,7 @@ struct _ptr_array_common_base
/**
* @internal
*/
- T* _new_clone(T const& a)
+ T* _new_clone(typename container_value_type<T>::type const& a)
{
return _get_clone_allocator().allocate_clone(a);
}
@@ -402,6 +404,7 @@ struct _ptr_array_common_base
struct _ptr_array_impl : CloneAllocator
{
_ptr_array_impl() : _array( ::eina_array_new(32u) ) {}
+ _ptr_array_impl(Eina_Array* array) : _array(array) {}
_ptr_array_impl(CloneAllocator allocator)
: clone_allocator_type(allocator), _array( ::eina_array_new(32u)) {}
@@ -449,6 +452,8 @@ public:
typedef std::unique_ptr<value_type, clone_allocator_deleter<clone_allocator_type> > _unique_ptr;
+ typedef Eina_Array* native_handle_type;
+
/**
* @brief Default constructor. Create an empty array.
*
@@ -1210,6 +1215,13 @@ public:
*/
size_type max_size() const { return -1; }
+ Eina_Array* release_native_handle()
+ {
+ Eina_Array* tmp = this->_impl._array;
+ this->_impl._array = ::eina_array_new(32u);
+ return tmp;
+ }
+
/**
* @brief Get a handle for the wrapped Eina_Array.
* @return Handle for the native Eina array.
diff --git a/src/bindings/eina_cxx/eina_ptrlist.hh b/src/bindings/eina_cxx/eina_ptrlist.hh
index 2f18d10ffb..f7254b1ef2 100644
--- a/src/bindings/eina_cxx/eina_ptrlist.hh
+++ b/src/bindings/eina_cxx/eina_ptrlist.hh
@@ -9,6 +9,7 @@
#include <eina_eo_concrete_fwd.hh>
#include <eina_iterator.hh>
#include <eina_throw.hh>
+#include <eina_range_types.hh>
#include <memory>
#include <iterator>
@@ -370,7 +371,7 @@ struct _ptr_list_common_base
/**
* @internal
*/
- T* _new_clone(T const& a)
+ T* _new_clone(typename container_value_type<T>::type const& a)
{
return _get_clone_allocator().allocate_clone(a);
}
@@ -413,11 +414,12 @@ class ptr_list : protected _ptr_list_common_base<T, CloneAllocator>
{
typedef _ptr_list_common_base<T, CloneAllocator> _base_type; /**< Type for the base class. */
public:
- typedef T value_type; /**< The type of each element. */
- typedef T& reference; /**< Type for a reference to an element. */
- typedef T const& const_reference; /**< Type for a constant reference to an element. */
- typedef _ptr_list_iterator<T const> const_iterator; /**< Type for a iterator for this container. */
- typedef _ptr_list_iterator<T> iterator; /**< Type for a constant iterator for this container. */
+ typedef typename container_value_type<T>::type
+ value_type; /**< The type of each element. */
+ typedef value_type& reference; /**< Type for a reference to an element. */
+ typedef value_type const& const_reference; /**< Type for a constant reference to an element. */
+ typedef _ptr_list_iterator<value_type const> const_iterator; /**< Type for a iterator for this container. */
+ typedef _ptr_list_iterator<value_type> iterator; /**< Type for a constant iterator for this container. */
typedef T* pointer; /**< Type for a pointer to an element. */
typedef T const* const_pointer; /**< Type for a constant pointer for an element. */
typedef std::size_t size_type; /**< Type for size information. */
@@ -427,6 +429,8 @@ public:
typedef std::reverse_iterator<iterator> reverse_iterator; /**< Type for reverse iterator for this container. */
typedef std::reverse_iterator<const_iterator> const_reverse_iterator; /**< Type for reverse iterator for this container. */
+ typedef Eina_List* native_handle_type;
+
typedef std::unique_ptr<value_type, clone_allocator_deleter<clone_allocator_type> > _unique_ptr;
/**
@@ -554,7 +558,7 @@ public:
*/
std::size_t size() const
{
- return _ptr_list_access_traits::size<T>(this->_impl._list);
+ return _ptr_list_access_traits::size<value_type>(this->_impl._list);
}
/**
@@ -566,7 +570,7 @@ public:
*/
bool empty() const
{
- return _ptr_list_access_traits::empty<T>(this->_impl._list);
+ return _ptr_list_access_traits::empty<value_type>(this->_impl._list);
}
/**
@@ -940,7 +944,7 @@ public:
*/
value_type& back()
{
- return _ptr_list_access_traits::back<T>(this->_impl._list);
+ return _ptr_list_access_traits::back<value_type>(this->_impl._list);
}
/**
@@ -952,7 +956,7 @@ public:
*/
value_type const& back() const
{
- return _ptr_list_access_traits::back<T>(this->_impl._list);
+ return _ptr_list_access_traits::back<value_type>(this->_impl._list);
}
/**
@@ -961,7 +965,7 @@ public:
*/
value_type& front()
{
- return _ptr_list_access_traits::front<T>(this->_impl._list);
+ return _ptr_list_access_traits::front<value_type>(this->_impl._list);
}
/**
@@ -973,7 +977,7 @@ public:
*/
value_type const& front() const
{
- return _ptr_list_access_traits::front<T>(this->_impl._list);
+ return _ptr_list_access_traits::front<value_type>(this->_impl._list);
}
/**
@@ -985,7 +989,7 @@ public:
*/
const_iterator begin() const
{
- return _ptr_list_access_traits::cbegin<T>(this->_impl._list);
+ return _ptr_list_access_traits::cbegin<value_type>(this->_impl._list);
}
/**
@@ -997,7 +1001,7 @@ public:
*/
const_iterator end() const
{
- return _ptr_list_access_traits::cend<T>(this->_impl._list);
+ return _ptr_list_access_traits::cend<value_type>(this->_impl._list);
}
/**
@@ -1010,7 +1014,7 @@ public:
*/
iterator begin()
{
- return _ptr_list_access_traits::begin<T>(this->_impl._list);
+ return _ptr_list_access_traits::begin<value_type>(this->_impl._list);
}
/**
@@ -1026,7 +1030,7 @@ public:
*/
iterator end()
{
- return _ptr_list_access_traits::end<T>(this->_impl._list);
+ return _ptr_list_access_traits::end<value_type>(this->_impl._list);
}
/**
@@ -1038,7 +1042,7 @@ public:
*/
const_reverse_iterator rbegin() const
{
- return _ptr_list_access_traits::rbegin<T>(this->_impl._list);
+ return _ptr_list_access_traits::rbegin<value_type>(this->_impl._list);
}
/**
@@ -1050,7 +1054,7 @@ public:
*/
const_reverse_iterator rend() const
{
- return _ptr_list_access_traits::rend<T>(this->_impl._list);
+ return _ptr_list_access_traits::rend<value_type>(this->_impl._list);
}
/**
@@ -1063,7 +1067,7 @@ public:
*/
reverse_iterator rbegin()
{
- return _ptr_list_access_traits::rbegin<T>(this->_impl._list);
+ return _ptr_list_access_traits::rbegin<value_type>(this->_impl._list);
}
/**
@@ -1080,7 +1084,7 @@ public:
*/
reverse_iterator rend()
{
- return _ptr_list_access_traits::rend<T>(this->_impl._list);
+ return _ptr_list_access_traits::rend<value_type>(this->_impl._list);
}
/**
@@ -1093,7 +1097,7 @@ public:
*/
const_iterator cbegin() const
{
- return _ptr_list_access_traits::cbegin<T>(this->_impl._list);
+ return _ptr_list_access_traits::cbegin<value_type>(this->_impl._list);
}
/**
@@ -1106,7 +1110,7 @@ public:
*/
const_iterator cend() const
{
- return _ptr_list_access_traits::cend<T>(this->_impl._list);
+ return _ptr_list_access_traits::cend<value_type>(this->_impl._list);
}
/**
@@ -1119,7 +1123,7 @@ public:
*/
const_reverse_iterator crbegin() const
{
- return _ptr_list_access_traits::crbegin<T>(this->_impl._list);
+ return _ptr_list_access_traits::crbegin<value_type>(this->_impl._list);
}
/**
@@ -1132,7 +1136,7 @@ public:
*/
const_reverse_iterator crend() const
{
- return _ptr_list_access_traits::crend<T>(this->_impl._list);
+ return _ptr_list_access_traits::crend<value_type>(this->_impl._list);
}
/**
@@ -1143,9 +1147,9 @@ public:
* the first element of the list. If the list is empty the returned
* iterator is the same as the one returned by @ref iend().
*/
- eina::iterator<T> ibegin()
+ eina::iterator<value_type> ibegin()
{
- return _ptr_list_access_traits::ibegin<T>(this->_impl._list);
+ return _ptr_list_access_traits::ibegin<value_type>(this->_impl._list);
}
/**
@@ -1160,9 +1164,9 @@ public:
* @note Note that attempting to access this position causes undefined
* behavior.
*/
- eina::iterator<T> iend()
+ eina::iterator<value_type> iend()
{
- return _ptr_list_access_traits::iend<T>(this->_impl._list);
+ return _ptr_list_access_traits::iend<value_type>(this->_impl._list);
}
/**
@@ -1174,7 +1178,7 @@ public:
*/
eina::iterator<T const> ibegin() const
{
- return _ptr_list_access_traits::ibegin<T>(this->_impl._list);
+ return _ptr_list_access_traits::ibegin<value_type>(this->_impl._list);
}
/**
@@ -1186,7 +1190,7 @@ public:
*/
eina::iterator<T const> iend() const
{
- return _ptr_list_access_traits::iend<T>(this->_impl._list);
+ return _ptr_list_access_traits::iend<value_type>(this->_impl._list);
}
/**
@@ -1199,7 +1203,7 @@ public:
*/
eina::iterator<T const> cibegin() const
{
- return _ptr_list_access_traits::cibegin<T>(this->_impl._list);
+ return _ptr_list_access_traits::cibegin<value_type>(this->_impl._list);
}
/**
@@ -1212,7 +1216,7 @@ public:
*/
eina::iterator<T const> ciend() const
{
- return _ptr_list_access_traits::ciend<T>(this->_impl._list);
+ return _ptr_list_access_traits::ciend<value_type>(this->_impl._list);
}
/**
@@ -1230,6 +1234,13 @@ public:
*/
size_type max_size() const { return -1; }
+ Eina_List* release_native_handle()
+ {
+ Eina_List* tmp = this->_impl._list;
+ this->_impl._list = 0;
+ return tmp;
+ }
+
/**
* @brief Get a handle for the wrapped @c Eina_List.
* @return Handle for the native Eina list.
@@ -1275,9 +1286,9 @@ public:
* @brief Get a @ref eina::accessor for the list.
* @return <tt>eina::accessor</tt> to the list.
*/
- eina::accessor<T> accessor()
+ eina::accessor<value_type> accessor()
{
- return eina::accessor<T>(eina_list_accessor_new(this->_impl._list));
+ return eina::accessor<value_type>(eina_list_accessor_new(this->_impl._list));
}
};
diff --git a/src/bindings/eina_cxx/eina_range_types.hh b/src/bindings/eina_cxx/eina_range_types.hh
index 844e2ef4cc..313ca05cd9 100644
--- a/src/bindings/eina_cxx/eina_range_types.hh
+++ b/src/bindings/eina_cxx/eina_range_types.hh
@@ -22,11 +22,12 @@ namespace efl { namespace eina {
template <typename T, typename Traits>
struct _const_range_template
{
- typedef typename Traits::template const_iterator<T>::type const_iterator; /**< Type for constant iterator to the range. */
- typedef typename Traits::template iterator<T>::type iterator; /**< Type for iterator to the range. */
- typedef T value_type; /**< The type of each element. */
- typedef T& reference; /**< Type for a reference to an element. */
- typedef T const& const_reference; /**< Type for a constant reference to an element. */
+ typedef typename container_value_type<T>::type
+ value_type; /**< The type of each element. */
+ typedef typename Traits::template const_iterator<value_type>::type const_iterator; /**< Type for constant iterator to the range. */
+ typedef typename Traits::template iterator<value_type>::type iterator; /**< Type for iterator to the range. */
+ typedef value_type& reference; /**< Type for a reference to an element. */
+ typedef value_type const& const_reference; /**< Type for a constant reference to an element. */
typedef T* pointer; /**< Type for a pointer to an element. */
typedef T const* const_pointer; /**< Type for a constant pointer to an element. */
typedef std::reverse_iterator<iterator> reverse_iterator; /**< Type for reverse iterator to the range. */
@@ -50,6 +51,17 @@ struct _const_range_template
: _handle(handle) {}
/**
+ * @brief Release the handle of the native Eina container.
+ * @return Handle for the native Eina container.
+ */
+ native_handle_type release_native_handle()
+ {
+ auto h = _handle;
+ _handle = nullptr;
+ return h;
+ }
+
+ /**
* @brief Get a constant handle for the native Eina container.
* @return Constant handle for the native Eina container.
*/
@@ -241,10 +253,13 @@ void swap(_const_range_template<T, Traits>& lhs, _const_range_template<T, Traits
template <typename T, typename Traits>
struct _mutable_range_template : _const_range_template<T, Traits>
{
- typedef T value_type; /**< The type of each element. */
- typedef typename Traits::template iterator<T>::type iterator; /**< Type for a iterator to the range. */
+ typedef typename container_value_type<T>::type
+ value_type; /**< The type of each element. */
+ typedef value_type& reference_type;
+ typedef value_type const& const_reference_type;
+ typedef typename Traits::template iterator<value_type>::type iterator; /**< Type for a iterator to the range. */
typedef std::reverse_iterator<iterator> reverse_iterator; /**< Type for constant reverse iterator to the range. */
- typedef typename Traits::template native_handle<T>::type native_handle_type; /**< Type for the native handle of the container. */
+ typedef typename Traits::template native_handle<value_type>::type native_handle_type; /**< Type for the native handle of the container. */
typedef _const_range_template<T, Traits> _base_type; /**< Type for the base class. */
/**
@@ -254,6 +269,17 @@ struct _mutable_range_template : _const_range_template<T, Traits>
: _base_type(handle) {}
/**
+ * @brief Release the handle of the native Eina container.
+ * @return Handle for the native Eina container.
+ */
+ native_handle_type release_native_handle()
+ {
+ auto h = _handle;
+ _handle = nullptr;
+ return h;
+ }
+
+ /**
* @brief Get a constant handle for the native Eina container.
* @return Constant handle for the native Eina container.
*/
@@ -266,7 +292,7 @@ struct _mutable_range_template : _const_range_template<T, Traits>
* @brief Get a reference to the last element.
* @return Reference to the last element of the range.
*/
- value_type& back() const
+ reference_type back() const
{
return Traits::template back<value_type>(native_handle());
}
@@ -275,7 +301,7 @@ struct _mutable_range_template : _const_range_template<T, Traits>
* @brief Get a reference to the first element.
* @return Reference to the first element of the range.
*/
- value_type& front() const
+ reference_type front() const
{
return Traits::template front<value_type>(native_handle());
}
@@ -355,11 +381,12 @@ protected:
template <typename T, typename Traits>
struct _range_template : private std::conditional
<std::is_const<T>::value
- , _const_range_template<typename std::remove_const<T>::type, Traits>
- , _mutable_range_template<T, Traits> >::type
+ , _const_range_template<typename nonconst_container_value_type<T>::type, Traits>
+ , _mutable_range_template<typename nonconst_container_value_type<T>::type, Traits>
+ >::type
{
typedef std::integral_constant<bool, !std::is_const<T>::value> is_mutable; /**< Type that specifies if the elements can be modified. */
- typedef typename std::remove_const<T>::type value_type; /**< The type of each element. */
+ typedef typename nonconst_container_value_type<T>::type value_type; /**< The type of each element. */
typedef typename std::conditional<is_mutable::value, _mutable_range_template<value_type, Traits>
, _const_range_template<value_type, Traits> >::type _base_type; /**< Type for the base class. */
typedef typename _base_type::native_handle_type native_handle_type; /**< Type for the native handle of the container. */
@@ -368,9 +395,9 @@ struct _range_template : private std::conditional
typedef value_type const& const_reference; /**< Type for a constant reference to an element. */
typedef value_type* pointer; /**< Type for a pointer to an element. */
typedef value_type const* const_pointer; /**< Type for a constant pointer to an element. */
- typedef typename Traits::template const_iterator<T>::type const_iterator; /**< Type for constant iterator to the range. */
+ typedef typename Traits::template const_iterator<value_type>::type const_iterator; /**< Type for constant iterator to the range. */
typedef typename _base_type::const_reverse_iterator const_reverse_iterator; /**< Type for constant reverse iterator to the range. */
- typedef typename Traits::template iterator<T>::type iterator; /**< Type for iterator to the range. */
+ typedef typename Traits::template iterator<value_type>::type iterator; /**< Type for iterator to the range. */
typedef typename _base_type::reverse_iterator reverse_iterator; /**< Type for reverse iterator to the range. */
typedef typename _base_type::size_type size_type; /**< Type for size information. */
typedef typename _base_type::difference_type difference_type; /**< Type to represent the distance between two iterators. */
@@ -388,6 +415,7 @@ struct _range_template : private std::conditional
: _base_type(handle)
{}
+ using _base_type::release_native_handle;
using _base_type::native_handle;
using _base_type::back;
using _base_type::front;
diff --git a/src/bindings/eina_cxx/eina_tuple.hh b/src/bindings/eina_cxx/eina_tuple.hh
index f0f22d9cae..45545c3702 100644
--- a/src/bindings/eina_cxx/eina_tuple.hh
+++ b/src/bindings/eina_cxx/eina_tuple.hh
@@ -1,6 +1,11 @@
#ifndef EFL_EINA_EINA_TUPLE_HH_
#define EFL_EINA_EINA_TUPLE_HH_
+#include <eina_integer_sequence.hh>
+#include <eina_logical.hh>
+
+#include <tuple>
+
namespace efl { namespace eina { namespace _mpl {
template <typename A, typename... Args>
@@ -21,15 +26,64 @@ struct push_front<C<Args...>, AArgs...>
typedef C<Args..., AArgs...> type;
};
-template <typename A>
+template <typename A, std::size_t N = 1>
struct pop_front;
-
+
template <template <typename...> class C, typename T, typename... Args>
-struct pop_front<C<T, Args...> >
+struct pop_front<C<T, Args...>, 1>
{
typedef C<Args...> type;
};
+template <typename A, std::size_t N>
+struct pop_front : pop_front<typename pop_front<A, 1>::type, N-1>
+{
+};
+
+template <typename T, typename F, std::size_t... I>
+void for_each_impl(T&& t, F&& f, eina::index_sequence<I...>)
+{
+ std::initializer_list<int> l = { (f(std::get<I>(t)), 0)...};
+ static_cast<void>(l);
+}
+
+template <typename T, typename F>
+void for_each(T&& t, F&& f)
+{
+ _mpl::for_each_impl(t, f, eina::make_index_sequence
+ <std::tuple_size<typename std::remove_reference<T>::type>::value>());
+}
+
+template <typename T, typename Transform>
+struct tuple_transform;
+
+template <typename...T, typename Transform>
+struct tuple_transform<std::tuple<T...>, Transform>
+{
+ typedef std::tuple<typename Transform::template apply<T>::type...> type;
+};
+
+template <typename T, typename Tuple>
+struct tuple_contains;
+
+
+
+template <typename T, typename...Ts>
+struct tuple_contains<T, std::tuple<Ts...> >
+ : _mpl::or_<std::is_same<T, Ts>::value...>
+{
+};
+
+template <typename T, typename Tuple>
+struct tuple_find : std::integral_constant<int, -1> {};
+
+template <typename T, typename... Ts>
+struct tuple_find<T, std::tuple<T, Ts...> > : std::integral_constant<std::size_t, 0> {};
+
+template <typename T, typename T1, typename... Ts>
+struct tuple_find<T, std::tuple<T1, Ts...> > : std::integral_constant
+ <std::size_t, 1 + tuple_find<T, std::tuple<Ts...> >::value> {};
+
} } }
#endif
diff --git a/src/bindings/eina_cxx/eina_tuple_c.hh b/src/bindings/eina_cxx/eina_tuple_c.hh
new file mode 100644
index 0000000000..64d67c49a9
--- /dev/null
+++ b/src/bindings/eina_cxx/eina_tuple_c.hh
@@ -0,0 +1,24 @@
+#ifndef EFL_EINA_EINA_TUPLE_C_HH_
+#define EFL_EINA_EINA_TUPLE_C_HH_
+
+#include <tuple>
+
+namespace efl { namespace eina { namespace _mpl {
+
+template <typename T, T... Ts>
+using tuple_c = std::tuple<std::integral_constant<T, Ts>...>;
+
+template <typename T, T... Ts>
+constexpr std::size_t tuple_c_size(tuple_c<T, Ts...> const&)
+{
+ return sizeof...(Ts);
+}
+
+constexpr std::size_t tuple_c_size(std::tuple<> const&)
+{
+ return 0;
+}
+
+} } }
+
+#endif
diff --git a/src/bindings/eina_cxx/eina_type_traits.hh b/src/bindings/eina_cxx/eina_type_traits.hh
index 9e8628ad90..ff8bfbbff9 100644
--- a/src/bindings/eina_cxx/eina_type_traits.hh
+++ b/src/bindings/eina_cxx/eina_type_traits.hh
@@ -64,6 +64,22 @@ struct if_ : if_c<U::value, T, F>
{
};
+template <typename T>
+struct container_value_type
+{
+ typedef typename std::conditional<
+ std::is_void<T>::value
+ , T*, T>::type type;
+};
+
+template <typename T>
+struct nonconst_container_value_type
+{
+ typedef typename std::conditional<
+ std::is_void<T>::value
+ , T*, typename std::remove_const<T>::type>::type type;
+};
+
/**
* @}
*/
diff --git a/src/bindings/eina_js/Eina_Js.hh b/src/bindings/eina_js/Eina_Js.hh
new file mode 100644
index 0000000000..b193b5461c
--- /dev/null
+++ b/src/bindings/eina_js/Eina_Js.hh
@@ -0,0 +1,50 @@
+
+#ifndef EFL_EINA_JS_HH
+#define EFL_EINA_JS_HH
+
+#include <Eina.hh>
+#include <eo_concrete.hh>
+
+#ifdef EAPI
+# undef EAPI
+#endif
+
+#ifdef _WIN32
+# ifdef EFL_EINA_JS_BUILD
+# ifdef DLL_EXPORT
+# define EAPI __declspec(dllexport)
+# else
+# define EAPI
+# endif /* ! DLL_EXPORT */
+# else
+# define EAPI __declspec(dllimport)
+# endif /* ! EFL_ECORE_BUILD */
+#else
+# ifdef __GNUC__
+# if __GNUC__ >= 4
+# define EAPI __attribute__ ((visibility("default")))
+# else
+# define EAPI
+# endif
+# else
+# define EAPI
+# endif
+#endif /* ! _WIN32 */
+
+#include <eina_js_container.hh>
+#include <eina_js_accessor.hh>
+#include <eina_js_array.hh>
+#include <eina_js_compatibility.hh>
+#include <eina_js_error.hh>
+#include <eina_js_get_value_from_c.hh>
+#include <eina_js_get_value.hh>
+#include <eina_js_iterator.hh>
+#include <eina_js_list.hh>
+#include <eina_js_log.hh>
+#include <eina_js_value.hh>
+#include <eina_js_log.hh>
+
+#undef EAPI
+#define EAPI
+
+#endif
diff --git a/src/bindings/eina_js/eina_js_accessor.cc b/src/bindings/eina_js/eina_js_accessor.cc
new file mode 100644
index 0000000000..d6891547ed
--- /dev/null
+++ b/src/bindings/eina_js/eina_js_accessor.cc
@@ -0,0 +1,34 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <Eina.hh>
+
+#include <Eina_Js.hh>
+
+#include <iostream>
+
+namespace efl { namespace eina { namespace js {
+
+EAPI void register_destroy_accessor(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ typedef void (*deleter_t)(void*);
+
+ auto f = [](compatibility_callback_info_type info) -> compatibility_return_type
+ {
+ if (info.Length() != 1 || !info[0]->IsObject())
+ return compatibility_return();
+
+ v8::Handle<v8::Object> o = info[0]->ToObject();
+
+ deleter_t deleter = compatibility_get_pointer_internal_field<deleter_t>(o, 1);
+ deleter(compatibility_get_pointer_internal_field<>(o, 0));
+ return compatibility_return();
+ };
+
+ global->Set(name, compatibility_new<v8::FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+} } } // namespace efl { namespace js {
diff --git a/src/bindings/eina_js/eina_js_accessor.hh b/src/bindings/eina_js/eina_js_accessor.hh
new file mode 100644
index 0000000000..abf3090fed
--- /dev/null
+++ b/src/bindings/eina_js/eina_js_accessor.hh
@@ -0,0 +1,87 @@
+#ifndef EINA_JS_ACCESSOR_HH
+#define EINA_JS_ACCESSOR_HH
+
+#include <memory>
+
+#include <eina_js_value.hh>
+#include <eina_js_compatibility.hh>
+#include <eina_js_get_value.hh>
+#include <eina_js_get_value_from_c.hh>
+
+#include <iostream>
+
+namespace efl { namespace eina { namespace js {
+
+template <typename T, typename A>
+js::compatibility_return_type accessor_get(js::compatibility_callback_info_type info)
+{
+ v8::Isolate* isolate = info.GetIsolate();
+ if (info.Length() != 1 || !info[0]->IsNumber())
+ return js::compatibility_return();
+
+ auto idx = js::get_value_from_javascript
+ (info[0], isolate, "", js::value_tag<std::size_t>());
+
+ std::string class_name;
+ if (info.Data()->IsString())
+ {
+ v8::String::Utf8Value str(info.Data());
+ class_name = *str;
+ }
+
+ void *ptr = compatibility_get_pointer_internal_field(info.Holder(), 0);
+
+ return compatibility_return
+ (::efl::eina::js::get_value_from_c
+ (js::wrap_value<T>(container_unwrap((*static_cast<A*>(ptr))[idx]), js::value_tag<T>{})
+ , isolate, class_name.c_str()), info);
+};
+
+/* Creates a copy from \p a accessor and exports it to be manipulated by the JS
+ code */
+template <typename T, typename W>
+inline v8::Local<v8::Object> export_accessor(::efl::eina::accessor<W> &a, v8::Isolate *isolate, const char* class_name)
+{
+ typedef ::efl::eina::accessor<W> accessor_type;
+
+ static efl::eina::js::global_ref<v8::ObjectTemplate> obj_tpl
+ (isolate,
+ [&]()
+ {
+ auto obj_tpl = compatibility_new<v8::ObjectTemplate>(isolate);
+ (*obj_tpl)->SetInternalFieldCount(1);
+
+ // TODO: (*obj_tpl)->SetIndexedPropertyHandler(&accessor_get<accessor_type>);
+
+ (*obj_tpl)->Set(js::compatibility_new<v8::String>(isolate, "get")
+ , js::compatibility_new<v8::FunctionTemplate>(isolate
+ , &accessor_get<T, accessor_type>
+ , js::compatibility_new<v8::String>(isolate, class_name)));
+ return obj_tpl;
+ }());
+
+ auto instance = obj_tpl.handle()->NewInstance();
+ compatibility_set_pointer_internal_field(instance, 0, &a);
+ return instance;
+}
+
+/* Extracts and returns a copy from the internal accessor object from the JS
+ object */
+template <typename T>
+::efl::eina::accessor<T>& import_accessor(v8::Handle<v8::Object> o)
+{
+ typedef ::efl::eina::accessor<T> accessor_type;
+
+ void* ptr = compatibility_get_pointer_internal_field(o, 0);
+
+ return *static_cast<accessor_type*>(ptr);
+}
+
+/* Registers the function to destroy the accessor objects to the JS code */
+void register_destroy_accessor(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+} } } // namespace efl::js
+
+#endif /* EINA_JS_ACCESSOR_HH */
diff --git a/src/bindings/eina_js/eina_js_array.hh b/src/bindings/eina_js/eina_js_array.hh
new file mode 100644
index 0000000000..9cdd142e7c
--- /dev/null
+++ b/src/bindings/eina_js/eina_js_array.hh
@@ -0,0 +1,119 @@
+#ifndef EINA_JS_ARRAY_HH
+#define EINA_JS_ARRAY_HH
+
+#include <iostream>
+
+#include <iterator>
+
+#include <eina_js_container.hh>
+
+namespace efl { namespace eina { namespace js {
+
+template <typename T, typename K, typename W>
+struct eina_array : eina_container_common<efl::eina::array
+ <W
+ , typename std::conditional
+ <std::is_base_of<efl::eo::concrete, W>::value
+ , efl::eina::eo_clone_allocator
+ , efl::eina::malloc_clone_allocator
+ >::type>, T, K>
+{
+ typedef eina_container_common<efl::eina::array<W
+ , typename std::conditional
+ <std::is_base_of<efl::eo::concrete, W>::value
+ , efl::eina::eo_clone_allocator
+ , efl::eina::malloc_clone_allocator
+ >::type>, T, K> base_type;
+ using base_type::base_type;
+ typedef typename base_type::container_type container_type;
+
+ eina_container_base* concat(eina_container_base const& other) const
+ {
+ return detail::concat(*this, other);
+ }
+ eina_container_base* slice(std::int64_t i, std::int64_t j) const
+ {
+ return detail::slice(*this, i, j);
+ }
+ v8::Local<v8::Value> set(v8::Isolate* isolate, std::size_t index, v8::Local<v8::Value> v)
+ {
+ return detail::set<T,W>(isolate, *this, index, v);
+ }
+ int push(v8::Isolate* isolate, v8::Local<v8::Value> v)
+ {
+ return detail::push<T,W>(isolate, *this, v);
+ }
+ v8::Local<v8::Value> pop(v8::Isolate* isolate)
+ {
+ return detail::pop<T,W,K>(isolate, *this);
+ }
+ js::container_type get_container_type() const { return array_container_type; }
+};
+
+template <typename T, typename K, typename W>
+struct range_eina_array : eina_container_common<efl::eina::range_array<W>, T, K>
+{
+ typedef eina_container_common<efl::eina::range_array<W>, T, K> base_type;
+ using base_type::base_type;
+ typedef typename base_type::container_type container_type;
+ typedef typename std::conditional
+ <std::is_base_of<efl::eo::concrete, W>::value
+ , efl::eina::eo_clone_allocator
+ , efl::eina::malloc_clone_allocator
+ >::type clone_allocator_type;
+
+ eina_container_base* concat(eina_container_base const& other) const
+ {
+ range_eina_array<T, K, W> const& rhs = static_cast<range_eina_array<T, K, W>const&>(other);
+ efl::eina::array<W, clone_allocator_type>
+ array(this->_container.begin(), this->_container.end());
+ array.insert(array.end(), rhs._container.begin(), rhs._container.end());
+ return new eina_array<T, K, W>(array.release_native_handle());
+ }
+ eina_container_base* slice(std::int64_t i, std::int64_t j) const
+ {
+ efl::eina::array<W, clone_allocator_type>
+ array(std::next(this->_container.begin(), i), std::next(this->_container.begin(), j));
+ return new eina_array<T, K, W>(array.release_native_handle());
+ }
+ js::container_type get_container_type() const { return array_container_type; }
+};
+
+// Problematic types.
+template <>
+struct eina_array<_Elm_Calendar_Mark*, js::nonclass_cls_name_getter, _Elm_Calendar_Mark>
+ : empty_container_base
+{ eina_array(Eina_Array const*){} };
+template <>
+struct eina_array<Elm_Gen_Item*, js::nonclass_cls_name_getter, Elm_Gen_Item>
+ : empty_container_base
+{ eina_array(Eina_Array const*){} };
+template <>
+struct eina_array<_Evas_Textblock_Rectangle*, js::nonclass_cls_name_getter, _Evas_Textblock_Rectangle>
+ : empty_container_base
+{ eina_array(Eina_Array const*){} };
+template <>
+struct eina_array<_Elm_Map_Overlay*, js::nonclass_cls_name_getter, _Elm_Map_Overlay>
+ : empty_container_base
+{ eina_array(Eina_Array const*){} };
+
+template <>
+struct range_eina_array<_Elm_Calendar_Mark*, js::nonclass_cls_name_getter, _Elm_Calendar_Mark>
+ : empty_container_base
+{ range_eina_array(Eina_Array const*){} };
+template <>
+struct range_eina_array<Elm_Gen_Item*, js::nonclass_cls_name_getter, Elm_Gen_Item>
+ : empty_container_base
+{ range_eina_array(Eina_Array const*){} };
+template <>
+struct range_eina_array<_Evas_Textblock_Rectangle*, js::nonclass_cls_name_getter, _Evas_Textblock_Rectangle>
+ : empty_container_base
+{ range_eina_array(Eina_Array const*){} };
+template <>
+struct range_eina_array<_Elm_Map_Overlay*, js::nonclass_cls_name_getter, _Elm_Map_Overlay>
+ : empty_container_base
+{ range_eina_array(Eina_Array const*){} };
+
+} } }
+
+#endif
diff --git a/src/bindings/eina_js/eina_js_compatibility.cc b/src/bindings/eina_js/eina_js_compatibility.cc
new file mode 100644
index 0000000000..a1d992f59e
--- /dev/null
+++ b/src/bindings/eina_js/eina_js_compatibility.cc
@@ -0,0 +1,12 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <Eina.hh>
+#include <Eina_Js.hh>
+
+namespace efl { namespace eina { namespace js {
+
+std::map<std::string, v8::Local<v8::Function>> constructors_map_;
+
+} } }
diff --git a/src/bindings/eina_js/eina_js_compatibility.hh b/src/bindings/eina_js/eina_js_compatibility.hh
new file mode 100644
index 0000000000..9ef0cb814e
--- /dev/null
+++ b/src/bindings/eina_js/eina_js_compatibility.hh
@@ -0,0 +1,918 @@
+#ifndef EFL_EINA_JS_COMPATIBILITY_HH
+#define EFL_EINA_JS_COMPATIBILITY_HH
+
+#include <type_traits>
+#include <utility>
+#include <map>
+#include <string>
+#include <cstdlib>
+
+
+#ifdef HAVE_NODE_V8_H
+#include <node/v8.h>
+#elif defined(HAVE_NODEJS_DEPS_V8_V8_H)
+#include <nodejs/deps/v8/v8.h>
+#elif defined(HAVE_NODEJS_DEPS_V8_INCLUDE_V8_H)
+#include <nodejs/deps/v8/include/v8.h>
+#elif defined(HAVE_NODEJS_SRC_V8_H)
+#include <nodejs/src/v8.h>
+#elif defined(HAVE_V8_H)
+#include <v8.h>
+#else
+#error We must have at least one v8 header to include
+#endif
+
+namespace v8 {
+
+template <typename T>
+struct FunctionCallbackInfo;
+template <typename T>
+struct PropertyCallbackInfo;
+template <typename T>
+#ifdef HAVE_V8_GLOBAL
+struct Global;
+#else
+struct UniquePersistent;
+#endif
+
+class AccessorInfo;
+
+class Arguments;
+
+}
+
+namespace efl { namespace eina { namespace js {
+
+template <typename T>
+struct value_tag
+{
+ typedef T type;
+};
+
+template <typename T, typename... U>
+struct complex_tag
+{
+ T value;
+ typedef std::tuple<U...> inner_types;
+};
+
+template <typename T>
+struct make_tag_traits
+{
+ typedef typename std::remove_reference<T>::type a1;
+ typedef typename std::conditional
+ <std::is_pointer<T>::value
+ , typename std::remove_cv<T>::type
+ , T>::type type;
+};
+
+template <typename T, typename... U>
+using make_complex_tag = complex_tag<typename make_tag_traits<T>::type
+ , typename make_tag_traits<U>::type...>;
+
+template <typename T>
+struct struct_tag
+{
+ T value;
+};
+
+template <typename T>
+using make_struct_tag = struct_tag<typename make_tag_traits<T>::type>;
+
+template <typename T>
+struct struct_ptr_tag
+{
+ T value;
+};
+
+template <typename T>
+using make_struct_ptr_tag = struct_ptr_tag<typename make_tag_traits<T>::type>;
+
+template <typename T, typename... Ts>
+struct remove_tag
+{
+ typedef T type;
+};
+
+template <typename T, typename... U>
+struct remove_tag<complex_tag<T, U...>>
+{
+ typedef typename eina::js::remove_tag<T, U...>::type type;
+};
+
+template <typename T>
+struct remove_tag<struct_tag<T>>
+{
+ typedef typename eina::js::remove_tag<T>::type type;
+};
+
+template <typename T>
+struct remove_tag<struct_ptr_tag<T>>
+{
+ typedef typename eina::js::remove_tag<T>::type type;
+};
+
+template <typename T>
+struct is_handable_by_value
+{
+ static constexpr bool value = !std::is_class<T>::value || std::is_same<T, ::efl::eo::concrete>::value;
+};
+
+template <typename... T>
+struct container_wrapper
+{
+ typedef typename eina::js::remove_tag<T...>::type _notag_type;
+ typedef typename std::conditional<
+ std::is_convertible<_notag_type, Eo const* const>::value
+ , typename std::conditional<
+ std::is_const<typename std::remove_pointer<_notag_type>::type>::value
+ , ::efl::eo::concrete const
+ , ::efl::eo::concrete
+ >::type
+ , _notag_type
+ >::type type;
+};
+
+template <typename T>
+T container_wrap(T&& v)
+{
+ return std::forward<T>(v);
+}
+
+inline ::efl::eo::concrete container_wrap(Eo* v)
+{
+ if(v)
+ eo_ref(v);
+ return ::efl::eo::concrete{v};
+}
+
+inline ::efl::eo::concrete container_wrap(Eo const* v)
+{
+ if (v)
+ eo_ref(v);
+ return ::efl::eo::concrete{const_cast<Eo*>(v)};
+}
+
+template <typename T>
+T& container_unwrap(T& v)
+{
+ return v;
+}
+
+inline Eo* container_unwrap(::efl::eo::concrete& v)
+{
+ return v._eo_ptr();
+}
+
+inline Eo* container_unwrap(::efl::eo::concrete const& v)
+{
+ return v._eo_ptr();
+}
+
+template <typename T>
+struct is_complex_tag : std::false_type {};
+
+template <typename... T>
+struct is_complex_tag<complex_tag<T...>> : std::true_type {};
+
+template <typename T>
+struct is_struct_tag : std::false_type {};
+
+template <typename T>
+struct is_struct_tag<struct_tag<T>> : std::true_type {};
+
+template <typename T>
+struct is_struct_ptr_tag : std::false_type {};
+
+template <typename T>
+struct is_struct_ptr_tag<struct_ptr_tag<T>> : std::true_type {};
+
+template <typename T>
+struct is_type_tag
+{
+ static constexpr bool value =
+ is_complex_tag<T>::value
+ || is_struct_tag<T>::value
+ || is_struct_ptr_tag<T>::value;
+};
+
+
+// Class name getters
+struct cls_name_getter_base {};
+struct cls_name_getter_generated_base : cls_name_getter_base {};
+/// Name getter for types that are not classes
+struct nonclass_cls_name_getter : cls_name_getter_base
+{
+ static char const* class_name() { return ""; }
+};
+
+// JS container base
+enum container_type
+{
+ list_container_type
+ , array_container_type
+ , container_type_size
+};
+
+struct eina_container_base
+{
+ virtual ~eina_container_base() {}
+
+ virtual std::size_t size() const = 0;
+ virtual eina_container_base* concat(eina_container_base const& rhs) const = 0;
+ virtual eina_container_base* slice(std::int64_t i, std::int64_t j) const = 0;
+ virtual int index_of(v8::Isolate* isolate, v8::Local<v8::Value> v) const = 0;
+ virtual int last_index_of(v8::Isolate* isolate, v8::Local<v8::Value> v) const = 0;
+ virtual v8::Local<v8::Value> get(v8::Isolate*, std::size_t) const = 0;
+ virtual v8::Local<v8::Value> set(v8::Isolate* isolate, std::size_t index, v8::Local<v8::Value> v) = 0;
+ virtual int push(v8::Isolate* isolate, v8::Local<v8::Value> v) = 0;
+ virtual v8::Local<v8::Value> pop(v8::Isolate* isolate) = 0;
+ virtual v8::Local<v8::String> to_string(v8::Isolate*) const = 0;
+ virtual v8::Local<v8::String> join(v8::Isolate*, v8::Local<v8::Value> separator) const = 0;
+ virtual container_type get_container_type() const = 0;
+ virtual void* get_container_native_handle() = 0;
+ virtual void const* get_container_native_handle() const = 0;
+};
+
+// Containers forward declarations
+
+// Array
+template <typename T, typename K = nonclass_cls_name_getter, typename W = typename container_wrapper<T>::type>
+struct eina_array;
+template <typename T, typename K = nonclass_cls_name_getter, typename W = typename container_wrapper<T>::type>
+struct range_eina_array;
+
+EAPI v8::Handle<v8::Function> get_array_instance_template();
+
+// List
+template <typename T, typename K = nonclass_cls_name_getter, typename W = typename container_wrapper<T>::type>
+struct eina_list;
+template <typename T, typename K = nonclass_cls_name_getter, typename W = typename container_wrapper<T>::type>
+struct range_eina_list;
+
+EAPI v8::Handle<v8::Function> get_list_instance_template();
+
+// Accessor
+template <typename T, typename W>
+v8::Local<v8::Object> export_accessor(::efl::eina::accessor<W>&, v8::Isolate*, const char*);
+
+template <typename T>
+::efl::eina::accessor<T>& import_accessor(v8::Handle<v8::Object>);
+
+// Wrap value functions
+template <typename R, typename T>
+typename std::remove_cv<typename std::remove_reference<R>::type>::type
+wrap_value(T v, value_tag<R>
+ , typename std::enable_if<!is_type_tag<typename std::remove_cv<R>::type>::value>::type* = 0)
+{
+ return v;
+}
+
+template <typename R, typename T>
+R wrap_value(T const& v, value_tag<eina::js::struct_tag<T>>)
+{
+ return R {v};
+}
+
+template <typename R, typename T>
+R wrap_value(T v, value_tag<eina::js::struct_ptr_tag<T>>)
+{
+ return R {v};
+}
+
+template <typename R, typename T, typename... U>
+R wrap_value(T v, value_tag<eina::js::complex_tag<T, U...>>)
+{
+ return R {v};
+}
+
+template <typename T = v8::External>
+struct _libv8_isolate_test
+{
+ using new_signature = v8::Local<T>(*)(v8::Isolate*, void*);
+ static const bool value = std::is_same<decltype(static_cast<new_signature>(&T::New)), new_signature>::value;
+};
+
+template <typename T = v8::FunctionTemplate, typename Enable = void>
+struct _libv8_callback_info_test;
+
+typedef v8::Handle<v8::Value>(*_libv8_invocation_callback)(v8::Arguments const&);
+
+template <typename T>
+struct _libv8_callback_info_test
+<T, typename std::enable_if
+ <!std::is_same<decltype( & T::SetCallHandler)
+ , void (T::*)(_libv8_invocation_callback, v8::Handle<v8::Value>)>::value>::type>
+ : std::true_type
+{
+};
+
+template <typename T>
+struct _libv8_callback_info_test
+<T, typename std::enable_if
+ <std::is_same<decltype( & T::SetCallHandler)
+ , void (T::*)(_libv8_invocation_callback, v8::Handle<v8::Value>)>::value>::type>
+ : std::false_type
+{
+};
+
+template <typename T = v8::ObjectTemplate, typename Enable = void>
+struct _libv8_property_callback_info_test
+ : std::true_type {};
+
+typedef v8::Handle<v8::Value>(*_libv8_getter_callback)(v8::Local<v8::String>, v8::AccessorInfo const&);
+typedef void(*_libv8_setter_callback)(v8::Local<v8::String>, v8::Local<v8::Value>, v8::AccessorInfo const&);
+
+template <typename T>
+struct _libv8_property_callback_info_test
+<T, typename std::enable_if
+ <std::is_same<decltype( & T::SetAccessor)
+ , void (T::*)
+ (v8::Handle<v8::String>
+ , _libv8_getter_callback
+ , _libv8_setter_callback
+ , v8::Handle<v8::Value>
+ , v8::AccessControl
+ , v8::PropertyAttribute
+ , v8::Handle<v8::AccessorSignature>
+ )>::value>::type>
+ : std::false_type
+{
+};
+
+static constexpr bool const v8_uses_isolate = _libv8_isolate_test<>::value;
+static constexpr bool const v8_uses_callback_info = _libv8_callback_info_test<>::value;
+static constexpr bool const v8_uses_property_callback_info = _libv8_property_callback_info_test<>::value;
+
+using compatibility_return_type = std::conditional<v8_uses_callback_info, void, v8::Handle<v8::Value> >::type;
+using compatibility_callback_info_type
+ = std::conditional<v8_uses_callback_info, v8::FunctionCallbackInfo<v8::Value> const&, v8::Arguments const&>
+ ::type;
+using compatibility_callback_info_pointer
+ = std::conditional<v8_uses_callback_info, v8::FunctionCallbackInfo<v8::Value> const*, v8::Arguments const*>
+ ::type;
+
+typedef compatibility_return_type(*compatibility_function_callback)(compatibility_callback_info_type);
+
+using compatibility_accessor_getter_return_type
+ = std::conditional<v8_uses_property_callback_info, void, v8::Handle<v8::Value> >::type;
+using compatibility_accessor_getter_callback_info_type
+ = std::conditional<v8_uses_property_callback_info
+ , v8::PropertyCallbackInfo<v8::Value> const&, v8::AccessorInfo const&>
+ ::type;
+
+using compatibility_accessor_setter_return_type
+ = void;
+using compatibility_accessor_setter_callback_info_type
+ = std::conditional<v8_uses_property_callback_info
+ , v8::PropertyCallbackInfo<void> const&, v8::AccessorInfo const&>
+ ::type;
+
+using compatibility_indexed_property_getset_return_type
+ = std::conditional<v8_uses_property_callback_info, void, v8::Handle<v8::Value> >::type;
+using compatibility_indexed_property_callback_info_type
+ = std::conditional<v8_uses_property_callback_info
+ , v8::PropertyCallbackInfo<v8::Value> const&, v8::AccessorInfo const&>
+ ::type;
+
+static_assert(v8_uses_property_callback_info == v8_uses_callback_info
+ && v8_uses_callback_info == v8_uses_isolate, "");
+
+template <typename T>
+struct compatibility_type_tag {};
+
+template <bool = v8_uses_isolate>
+struct compatibility_string;
+
+template <>
+struct compatibility_string<true> : v8::String
+{
+ template <typename... Args>
+ static v8::Local<v8::String> New(Args...args)
+ {
+ return NewFromUtf8(v8::Isolate::GetCurrent(), args...);
+ }
+};
+
+template <>
+struct compatibility_string<false> : v8::String
+{
+};
+
+template <typename...Args>
+auto compatibility_new_impl(v8::Isolate*, std::true_type, compatibility_type_tag<v8::String>
+ , Args...args) ->
+ decltype(compatibility_string<>::New(args...))
+{
+ return compatibility_string<>::New(args...);
+}
+
+template <typename...Args>
+auto compatibility_new_impl(v8::Isolate*, std::false_type, compatibility_type_tag<v8::String>
+ , Args...args) ->
+ decltype(compatibility_string<>::New(args...))
+{
+ return compatibility_string<>::New(args...);
+}
+
+template <typename...Args>
+auto compatibility_new_impl(std::nullptr_t, std::true_type, compatibility_type_tag<v8::String>
+ , Args...args) ->
+ decltype(compatibility_string<>::New(args...))
+{
+ return compatibility_string<>::New(args...);
+}
+
+template <typename...Args>
+auto compatibility_new_impl(std::nullptr_t, std::false_type, compatibility_type_tag<v8::String>
+ , Args...args) ->
+ decltype(compatibility_string<>::New(args...))
+{
+ return compatibility_string<>::New(args...);
+}
+
+template <typename T, typename...Args>
+auto compatibility_new_impl(v8::Isolate* isolate, std::true_type, compatibility_type_tag<T>
+ , Args...args) ->
+ decltype(T::New(isolate, args...))
+{
+ return T::New(isolate, args...);
+}
+
+template <typename T, typename...Args>
+auto compatibility_new_impl(v8::Isolate*, std::false_type, compatibility_type_tag<T>
+ , Args...args) ->
+ decltype(T::New(args...))
+{
+ return T::New(args...);
+}
+
+template <typename T, typename...Args>
+auto compatibility_new_impl(std::nullptr_t, std::true_type, compatibility_type_tag<T>
+ , Args...args) ->
+ decltype(T::New(v8::Isolate::GetCurrent(), args...))
+{
+ return T::New(v8::Isolate::GetCurrent(), args...);
+}
+
+template <typename T, typename...Args>
+auto compatibility_new_impl(std::nullptr_t, std::false_type, compatibility_type_tag<T>
+ , Args...args) ->
+ decltype(T::New(args...))
+{
+ return T::New(args...);
+}
+
+template <typename T, typename...Args>
+auto compatibility_new(v8::Isolate* isolate, Args...args) ->
+ decltype(js::compatibility_new_impl<>
+ (isolate, std::integral_constant<bool, v8_uses_isolate>()
+ , compatibility_type_tag<T>()
+ , args...))
+{
+ return js::compatibility_new_impl(isolate, std::integral_constant<bool, v8_uses_isolate>()
+ , compatibility_type_tag<T>()
+ , args...);
+}
+
+template <typename T, typename...Args>
+auto compatibility_new(std::nullptr_t, Args...args) ->
+ decltype(js::compatibility_new_impl<>(nullptr, std::integral_constant<bool, v8_uses_isolate>()
+ , compatibility_type_tag<T>()
+ , args...))
+{
+ return js::compatibility_new_impl<>(nullptr, std::integral_constant<bool, v8_uses_isolate>()
+ , compatibility_type_tag<T>()
+ , args...);
+}
+
+#ifdef HAVE_V8_CREATE_PARAMS
+namespace detail {
+class array_buffer_allocator : public v8::ArrayBuffer::Allocator
+{
+ public:
+ virtual void* Allocate(std::size_t length)
+ {
+ void* data = AllocateUninitialized(length);
+ return data ? std::memset(data, 0, length) : data;
+ }
+ virtual void* AllocateUninitialized(std::size_t length) { return std::malloc(length); }
+ virtual void Free(void* data, std::size_t) { std::free(data); }
+};
+}
+
+inline v8::Isolate* compatibility_isolate_new()
+{
+ static detail::array_buffer_allocator allocator;
+ v8::Isolate::CreateParams create_params;
+ create_params.array_buffer_allocator = &allocator;
+ return v8::Isolate::New(create_params);
+}
+
+#else
+
+inline v8::Isolate* compatibility_isolate_new()
+{
+ return v8::Isolate::New();
+}
+
+#endif
+
+template <typename T, typename U>
+inline void compatibility_return_impl(T object, U const& info, std::true_type)
+{
+ info.GetReturnValue().Set(object);
+}
+
+template <typename T>
+inline v8::Handle<v8::Value>
+compatibility_return_impl(T object, compatibility_callback_info_type, std::false_type)
+{
+ return object;
+}
+
+template <typename T>
+inline v8::Handle<v8::Value>
+compatibility_return_impl(T object, compatibility_accessor_getter_callback_info_type, std::false_type)
+{
+ return object;
+}
+
+template <typename T>
+compatibility_return_type
+compatibility_return(T object, compatibility_callback_info_type args)
+{
+ return compatibility_return_impl(object, args, std::integral_constant<bool, v8_uses_callback_info>());
+}
+
+template <typename T>
+compatibility_return_type
+compatibility_return(T object, compatibility_accessor_getter_callback_info_type args)
+{
+ return compatibility_return_impl(object, args, std::integral_constant<bool, v8_uses_property_callback_info>());
+}
+
+inline void compatibility_return_nil_impl(std::true_type) {}
+
+inline v8::Handle<v8::Value>
+compatibility_return_nil_impl(std::false_type)
+{
+ return v8::Handle<v8::Value>();
+}
+
+inline
+compatibility_return_type
+compatibility_return()
+{
+ return compatibility_return_nil_impl(std::integral_constant<bool, v8_uses_callback_info>());
+}
+
+struct _v8_isolate_throw_exception : v8::Isolate
+{
+ v8::Handle<v8::Value> ThrowException_impl(v8::Handle<v8::Value> v)
+ {
+ using namespace v8;
+ return ThrowException(v);
+ }
+};
+
+inline void
+compatibility_throw_impl(v8::Isolate* isolate, v8::Local<v8::Value> exception, std::true_type)
+{
+ static_cast<_v8_isolate_throw_exception*>(isolate)->ThrowException_impl(exception);
+}
+
+inline v8::Handle<v8::Value>
+compatibility_throw_impl(v8::Isolate* isolate, v8::Local<v8::Value> exception, std::false_type)
+{
+ return static_cast<_v8_isolate_throw_exception*>(isolate)->ThrowException_impl(exception);
+}
+
+inline std::conditional<v8_uses_isolate, void, v8::Handle<v8::Value> >::type
+compatibility_throw(v8::Isolate* isolate, v8::Local<v8::Value> exception)
+{
+ return compatibility_throw_impl(isolate, exception, std::integral_constant<bool, v8_uses_isolate>());
+}
+
+inline void
+compatibility_throw_impl(v8::Local<v8::Value> exception, std::true_type)
+{
+ static_cast<_v8_isolate_throw_exception*>(v8::Isolate::GetCurrent())->ThrowException_impl(exception);
+}
+
+inline v8::Handle<v8::Value>
+compatibility_throw_impl(v8::Local<v8::Value> exception, std::false_type)
+{
+ return static_cast<_v8_isolate_throw_exception*>(v8::Isolate::GetCurrent())->ThrowException_impl(exception);
+}
+
+inline std::conditional<v8_uses_isolate, void, v8::Handle<v8::Value> >::type
+compatibility_throw(v8::Local<v8::Value> exception)
+{
+ return compatibility_throw_impl(exception, std::integral_constant<bool, v8_uses_isolate>());
+}
+
+template <typename T, typename U>
+v8::Local<T> compatibility_cast(v8::Local<U> v);
+template <typename T, typename U>
+v8::Local<T> compatibility_cast(U* v);
+
+template <typename Tag>
+struct hack_private_member {
+ /* export it ... */
+ typedef typename Tag::type type;
+ static type ptr;
+};
+
+template <typename Tag>
+typename hack_private_member<Tag>::type hack_private_member<Tag>::ptr;
+
+template <typename Tag, typename Tag::type p>
+struct rob_private_member : hack_private_member<Tag> {
+ /* fill it ... */
+ struct filler {
+ filler() { hack_private_member<Tag>::ptr = p; }
+ };
+ static filler filler_obj;
+};
+
+template<typename Tag, typename Tag::type p>
+typename rob_private_member<Tag, p>::filler rob_private_member<Tag, p>::filler_obj;
+
+template <typename T>
+struct persistent_base_new { typedef T*(*type)(v8::Isolate*, T*); };
+
+template class rob_private_member<persistent_base_new<v8::Value>, &v8::PersistentBase<v8::Value>::New>;
+
+template <typename T>
+v8::Local<T> make_persistent(v8::Isolate* isolate, v8::Handle<T> v)
+{
+ v8::Value* p = hack_private_member<persistent_base_new<v8::Value>>::ptr
+ (isolate, *compatibility_cast<v8::Value>(v));
+ return compatibility_cast<T>(compatibility_cast<v8::Value>(p));
+}
+
+template <typename T, typename F>
+v8::Local<T> make_weak(v8::Isolate* isolate, v8::Handle<T> v, F&& f)
+{
+ v8::Value* p = hack_private_member<persistent_base_new<v8::Value>>::ptr
+ (isolate, *compatibility_cast<v8::Value>(v));
+ v8::PersistentBase<v8::Value>* persistent = static_cast<v8::PersistentBase<v8::Value>*>
+ (static_cast<void*>(&p));
+
+ auto callback = [](const v8::WeakCallbackInfo<typename std::remove_reference<F>::type>& data) -> void
+ {
+ typename std::remove_reference<F>::type* f = data.GetParameter();
+ (*f)();
+ delete f;
+ };
+
+ persistent->SetWeak(new typename std::remove_reference<F>::type(std::forward<F>(f)),
+ callback, v8::WeakCallbackType::kParameter);
+ return compatibility_cast<T>(compatibility_cast<v8::Value>(p));
+}
+
+template <typename T>
+struct global_ref
+{
+ global_ref() {}
+ global_ref(v8::Local<T> v)
+ : _value(make_persistent(nullptr, v))
+ {
+ }
+ global_ref(v8::Isolate* isolate, v8::Local<T> v)
+ : _value(make_persistent(isolate, v))
+ {
+ }
+
+ void dispose() const
+ {
+ v8::PersistentBase<T>* p = static_cast<v8::PersistentBase<T>*>(static_cast<void*>(&_value));
+ p->Reset();
+ }
+
+ v8::Handle<T> handle() const { return _value; }
+private:
+ mutable v8::Local<T> _value;
+};
+
+template <typename T = std::integral_constant<bool, v8_uses_isolate> >
+struct _v8_object_internal_field;
+
+template <>
+struct _v8_object_internal_field<std::true_type> : v8::Object
+{
+};
+
+inline void* GetPointerFromInternalField(int) { return nullptr; }
+inline void SetPointerInInternalField(int, void*) {}
+
+template <>
+struct _v8_object_internal_field<std::false_type> : v8::Object
+{
+ void* GetAlignedPointerFromInternalField(int index)
+ {
+ return GetPointerFromInternalField(index);
+ }
+ void SetAlignedPointerInInternalField(int index, void* p)
+ {
+ SetPointerInInternalField(index, p);
+ }
+};
+
+template <typename T = void*>
+inline T compatibility_get_pointer_internal_field(v8::Handle<v8::Object> object, std::size_t index)
+{
+ return reinterpret_cast<T>
+ (static_cast<_v8_object_internal_field<>*>(*object)->GetAlignedPointerFromInternalField(index));
+}
+
+template <typename T>
+inline void compatibility_set_pointer_internal_field(v8::Handle<v8::Object> object, std::size_t index
+ , T* pointer)
+{
+ static_cast<_v8_object_internal_field<>*>(*object)->SetAlignedPointerInInternalField(index, pointer);
+}
+
+template <typename T = void, bool = v8_uses_isolate>
+struct compatibility_handle_scope_impl;
+
+template <typename T>
+struct compatibility_handle_scope_impl<T, true> : v8::HandleScope
+{
+ compatibility_handle_scope_impl()
+ : HandleScope(v8::Isolate::GetCurrent())
+ {}
+ compatibility_handle_scope_impl(v8::Isolate* isolate)
+ : HandleScope((assert(isolate != nullptr), isolate))
+ {}
+};
+
+template <typename T>
+struct compatibility_handle_scope_impl<T, false> : v8::HandleScope
+{
+ compatibility_handle_scope_impl()
+ {}
+ compatibility_handle_scope_impl(v8::Isolate*)
+ {}
+};
+
+using compatibility_handle_scope = compatibility_handle_scope_impl<>;
+
+template <bool = v8_uses_isolate>
+struct _v8_initialize_icu;
+
+template <>
+struct _v8_initialize_icu<true> : v8::V8
+{
+};
+
+template <>
+struct _v8_initialize_icu<false> : v8::V8
+{
+ static bool InitializeICU(const char* = NULL)
+ {
+ return true;
+ }
+};
+
+inline void compatibility_initialize()
+{
+#ifdef HAVE_V8_CREATE_PARAMS
+ constexpr const char* argv[] = {""};
+ static_cast<_v8_initialize_icu<>*>(nullptr)->InitializeICU();
+ v8::V8::InitializeExternalStartupData(argv[0]);
+ v8::V8::Initialize();
+#else
+ v8::V8::Initialize();
+ static_cast<_v8_initialize_icu<>*>(nullptr)->InitializeICU();
+#endif
+}
+
+template <typename T, typename U>
+v8::Local<T> compatibility_cast(v8::Local<U> v)
+{
+ static_assert(sizeof(v8::Local<T>) == sizeof(v8::Local<U>), "");
+ v8::Local<T> l;
+ std::memcpy(&l, &v, sizeof(v8::Local<T>));
+ return l;
+}
+
+template <typename T, typename U>
+v8::Local<T> compatibility_cast(U* v)
+{
+ static_assert(sizeof(v8::Local<T>) == sizeof(U*), "");
+ v8::Local<T> l;
+ std::memcpy(&l, &v, sizeof(v8::Local<T>));
+ return l;
+}
+
+template <typename T = v8::Isolate, bool = v8_uses_isolate>
+struct _v8_get_current_context;
+
+template <typename T>
+struct _v8_get_current_context<T, false> : v8::Context
+{
+};
+
+template <typename T>
+struct _v8_get_current_context<T, true> : T
+{
+ static v8::Local<v8::Context> GetCurrent()
+ {
+ return T::GetCurrent()->GetCurrentContext();
+ }
+};
+
+template <typename T>
+inline v8::Local<v8::Value>
+new_v8_external_instance(v8::Handle<v8::Function>& ctor, T v, v8::Isolate* isolate)
+{
+ // TODO: ensure v8::External ownership ??? (memory leak in case NewInstance throws)
+ v8::Handle<v8::Value> a[] = {efl::eina::js::compatibility_new<v8::External>(isolate, v)};
+ return ctor->NewInstance(1, a);
+}
+
+inline
+compatibility_return_type cast_function(compatibility_callback_info_type args);
+
+inline v8::Local<v8::Value>
+new_v8_external_instance(v8::Handle<v8::Function>& ctor, Eo* v, v8::Isolate* isolate)
+{
+ // TODO: ensure v8::External ownership ??? (memory leak in case NewInstance throws)
+ v8::Handle<v8::Value> a[] = {efl::eina::js::compatibility_new<v8::External>(isolate, v)};
+ auto obj = ctor->NewInstance(1, a);
+ obj->Set(compatibility_new<v8::String>(isolate, "cast"),
+ compatibility_new<v8::FunctionTemplate>(isolate, &cast_function)->GetFunction());
+ return obj;
+}
+
+inline v8::Local<v8::Object> compatibility_global()
+{
+ return _v8_get_current_context<>::GetCurrent()->Global();
+}
+
+EAPI extern std::map<std::string, v8::Local<v8::Function>> constructors_map_;
+
+inline v8::Handle<v8::Function> get_class_constructor(std::string const& class_name)
+{
+ auto it = constructors_map_.find(class_name);
+ if (it == constructors_map_.end())
+ throw std::runtime_error("Class not found");
+ return it->second;
+}
+
+inline void register_class_constructor(std::string const& class_name,
+ v8::Handle<v8::Function> constructor_ptr)
+{
+ // TODO: check if already exist?
+ constructors_map_[class_name] = constructor_ptr;
+}
+
+template<class T = v8::StackTrace>
+typename std::enable_if<!v8_uses_isolate, v8::Local<T>>::type
+compatibility_current_stack_trace(v8::Isolate*, int frame_limit,
+ v8::StackTrace::StackTraceOptions options)
+{
+ return T::CurrentStackTrace(frame_limit, options);
+}
+
+template<class T = v8::StackTrace>
+typename std::enable_if<v8_uses_isolate, v8::Local<T>>::type
+compatibility_current_stack_trace(v8::Isolate *isolate, int frame_limit,
+ v8::StackTrace::StackTraceOptions options)
+{
+ return T::CurrentStackTrace(isolate, frame_limit, options);
+}
+
+inline
+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())
+ {
+ 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);
+ return compatibility_return
+ (new_v8_external_instance(ctor, ::eo_ref(eo), isolate), args);
+ }
+ else
+ {
+ eina::js::compatibility_throw
+ (isolate, v8::Exception::TypeError
+ (eina::js::compatibility_new<v8::String>(isolate, "Type expected is different. Expected String type")));
+ return compatibility_return();
+ }
+}
+
+} } }
+
+#endif
diff --git a/src/bindings/eina_js/eina_js_container.cc b/src/bindings/eina_js/eina_js_container.cc
new file mode 100644
index 0000000000..60c53e0e74
--- /dev/null
+++ b/src/bindings/eina_js/eina_js_container.cc
@@ -0,0 +1,495 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <Eina.hh>
+#include <Eina.h>
+#include <cstdlib>
+
+#include <Eo.h>
+
+#include <eina_integer_sequence.hh>
+#include <eina_tuple.hh>
+#include <eina_ptrlist.hh>
+
+#include <Eina_Js.hh>
+
+#include <tuple>
+
+#include <iostream>
+
+namespace efl { namespace eina { namespace js {
+
+template <typename T>
+struct tag { typedef T type; };
+
+namespace {
+
+global_ref<v8::ObjectTemplate> instance_persistents[container_type_size];
+global_ref<v8::Function> instance_templates[container_type_size];
+
+v8::Local<v8::Value> push(eina_container_base& self, v8::Isolate* isolate, v8::Local<v8::Value> value)
+{
+ return v8::Integer::New(isolate, self.push(isolate, value));
+}
+
+v8::Local<v8::Value> pop(eina_container_base& self, v8::Isolate* isolate, v8::Local<v8::Value>)
+{
+ return self.pop(isolate);
+}
+
+v8::Local<v8::Value> concat(eina_container_base& lhs, v8::Isolate* isolate, v8::Local<v8::Value> other)
+{
+ const char* error_message = 0;
+ if(other->IsObject())
+ {
+ v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(other);
+ v8::String::Utf8Value constructor_name (obj->GetConstructorName());
+ if(obj->GetConstructorName()->Equals(efl::eina::js::compatibility_new<v8::String>(isolate, "eina_list"))
+ || obj->GetConstructorName()->Equals(efl::eina::js::compatibility_new<v8::String>(isolate, "eina_array")))
+ {
+ eina_container_base& rhs = *static_cast<eina_container_base*>
+ (efl::eina::js::compatibility_get_pointer_internal_field(obj, 0));
+ 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))};
+ assert(!!*instance_templates[lhs.get_container_type()].handle());
+ v8::Local<v8::Object> result =
+ instance_templates[lhs.get_container_type()].handle()->NewInstance(1, a);
+ return result;
+ }
+ else
+ error_message = "Containers are not of the same type.";
+ }
+ else
+ error_message = "Object to be concatenated is not a container.";
+ }
+ else
+ error_message = "Concatenation argument is not an container";
+
+ eina::js::compatibility_throw
+ (isolate, v8::Exception::TypeError(eina::js::compatibility_new<v8::String>(isolate, error_message)));
+
+ return v8::Undefined(isolate);
+}
+
+v8::Local<v8::Value> slice(eina_container_base& self, v8::Isolate* isolate, v8::Local<v8::Value> begin
+ , v8::Local<v8::Value> end)
+{
+ std::size_t i, j;
+
+ if(begin->IsUint32() || begin->IsInt32())
+ i = begin->IntegerValue();
+ else if (begin->IsUndefined())
+ i = 0;
+ else
+ return v8::Undefined(isolate);
+
+ if(end->IsUint32() || end->IsInt32())
+ j = end->IntegerValue();
+ else if (end->IsUndefined())
+ j = self.size();
+ else
+ return v8::Undefined(isolate);
+
+ 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()].handle()
+ ->NewInstance(1, a);
+ return result;
+}
+
+compatibility_accessor_getter_return_type length
+ (v8::Local<v8::String>, compatibility_accessor_getter_callback_info_type info)
+{
+ v8::Local<v8::Object> self_obj = compatibility_cast<v8::Object>(info.This());
+ eina_container_base* self = static_cast<eina_container_base*>
+ (compatibility_get_pointer_internal_field(self_obj, 0));
+ return compatibility_return(js::get_value_from_c(self->size(), info.GetIsolate(), ""), info);
+}
+
+compatibility_indexed_property_getset_return_type index_get
+ (uint32_t index, compatibility_indexed_property_callback_info_type info)
+{
+ 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(self->get(info.GetIsolate(), index), info);
+}
+
+compatibility_indexed_property_getset_return_type index_set
+ (uint32_t index, v8::Local<v8::Value> value, compatibility_indexed_property_callback_info_type info)
+{
+ 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(self->set(info.GetIsolate(), index, value), info);
+}
+
+
+#define GENERATE_CONTAINER_CONSTRUCT_TYPE_IF(x) GENERATE_CONTAINER_CONSTRUCT_TYPE2_IF(x, x)
+#define GENERATE_CONTAINER_CONSTRUCT_TYPE2_IF(x, y) if (!strcmp(class_name, #x)) \
+ return new Container<y, nonclass_cls_name_getter, typename container_wrapper<y>::type>();
+
+template< template<typename, typename, typename> class Container>
+eina_container_base* construct_container(const char* class_name)
+{
+ GENERATE_CONTAINER_CONSTRUCT_TYPE_IF(int);
+ GENERATE_CONTAINER_CONSTRUCT_TYPE_IF(float);
+ GENERATE_CONTAINER_CONSTRUCT_TYPE2_IF(bool, Eina_Bool);
+ GENERATE_CONTAINER_CONSTRUCT_TYPE2_IF(string, char*);
+
+ return 0;
+}
+
+compatibility_return_type new_eina_list_internal(compatibility_callback_info_type args)
+{
+ if(args.IsConstructCall())
+ {
+ if(args.Length() == 0)
+ {
+ eina_container_base* p = new eina_list<int>;
+ compatibility_set_pointer_internal_field
+ (args.This(), 0, dynamic_cast<void*>(p));
+ }
+ else
+ {
+ if(args[0]->IsExternal())
+ {
+ eina_container_base* base = reinterpret_cast<eina_container_base*>
+ (v8::External::Cast(*args[0])->Value());
+ compatibility_set_pointer_internal_field
+ (args.This(), 0, dynamic_cast<void*>(base));
+ }
+ else
+ std::abort();
+ }
+ }
+ else
+ std::abort();
+ return compatibility_return();
+}
+
+compatibility_return_type new_eina_list(compatibility_callback_info_type args)
+{
+ if(args.IsConstructCall())
+ {
+ if(args.Length() == 0) // Default constructor, list of ints. Or should be list of Eo's?
+ {
+ eina_container_base* p = new eina_list<int>;
+ compatibility_set_pointer_internal_field
+ (args.This(), 0, dynamic_cast<void*>(p));
+ return compatibility_return();
+ }
+ else if (args.Length() == 1 && args[0]->IsString())
+ {
+ v8::String::Utf8Value string(args[0]);
+ eina_container_base* p = construct_container<efl::eina::js::eina_list>(*string);
+ if (!p) {
+ return eina::js::compatibility_throw
+ (args.GetIsolate(), v8::Exception::TypeError
+ (eina::js::compatibility_new<v8::String>(args.GetIsolate(), "Invalid type for container.")));
+ }
+ compatibility_set_pointer_internal_field
+ (args.This(), 0, dynamic_cast<void*>(p));
+ return compatibility_return();
+ }
+ }
+ return eina::js::compatibility_throw
+ (args.GetIsolate(), v8::Exception::TypeError
+ (eina::js::compatibility_new<v8::String>(args.GetIsolate(), "Wrong number of arguments for constructor call")));
+}
+
+compatibility_return_type new_eina_array_internal(compatibility_callback_info_type args)
+{
+ if(args.IsConstructCall())
+ {
+ if(args.Length() == 0)
+ {
+ eina_container_base* p = new eina_array<int>;
+ compatibility_set_pointer_internal_field
+ (args.This(), 0, dynamic_cast<void*>(p));
+ }
+ else
+ {
+ if(args[0]->IsExternal())
+ {
+ eina_container_base* base = reinterpret_cast<eina_container_base*>
+ (v8::External::Cast(*args[0])->Value());
+ compatibility_set_pointer_internal_field
+ (args.This(), 0, dynamic_cast<void*>(base));
+ }
+ else
+ std::abort();
+ }
+ }
+ else
+ std::abort();
+ return compatibility_return();
+}
+
+compatibility_return_type new_eina_array(compatibility_callback_info_type args)
+{
+ if(args.IsConstructCall())
+ {
+ if(args.Length() == 0)
+ {
+ eina_container_base* p = new eina_array<int>;
+ compatibility_set_pointer_internal_field
+ (args.This(), 0, dynamic_cast<void*>(p));
+ return compatibility_return();
+ }
+ else if (args.Length() == 1 && args[0]->IsString())
+ {
+ v8::String::Utf8Value string(args[0]);
+ eina_container_base* p = construct_container<efl::eina::js::eina_array>(*string);
+ if (!p) {
+ return eina::js::compatibility_throw
+ (args.GetIsolate(), v8::Exception::TypeError
+ (eina::js::compatibility_new<v8::String>(args.GetIsolate(), "Invalid type for container.")));
+ }
+ compatibility_set_pointer_internal_field
+ (args.This(), 0, dynamic_cast<void*>(p));
+ return compatibility_return();
+ }
+ }
+ return eina::js::compatibility_throw
+ (args.GetIsolate(), v8::Exception::TypeError
+ (eina::js::compatibility_new<v8::String>(args.GetIsolate(), "Wrong number of arguments for constructor call")));
+}
+
+template <typename F>
+struct function_params;
+
+template <typename R, typename... Sig>
+struct function_params<R(*)(Sig...)>
+{
+ typedef std::tuple<Sig...> type;
+};
+
+template <typename F>
+struct function_result;
+
+template <typename R, typename... Sig>
+struct function_result<R(*)(Sig...)>
+{
+ typedef R type;
+};
+
+template <typename T>
+struct is_persistent : std::false_type {};
+
+template <typename...A>
+struct is_persistent<v8::Persistent<A...> > : std::true_type {};
+
+template <std::size_t I, typename Sig>
+typename std::tuple_element<I, Sig>::type
+get_element(v8::Isolate* isolate
+ , compatibility_callback_info_type args
+ , typename std::enable_if
+ <is_persistent<typename std::tuple_element<I, Sig>::type>::value>::type* = 0)
+{
+ return typename std::tuple_element<I, Sig>::type(isolate, args[I]);
+}
+
+template <std::size_t I, typename Sig>
+typename std::tuple_element<I, Sig>::type
+get_element(v8::Isolate* /*isolate*/
+ , compatibility_callback_info_type args
+ , typename std::enable_if
+ <!is_persistent<typename std::tuple_element<I, Sig>::type>::value>::type* = 0)
+{
+ return args[I];
+}
+
+template <typename Sig, typename R, typename T, typename F, std::size_t... N>
+R call_impl(v8::Isolate* isolate
+ , compatibility_callback_info_type args
+ , T* self, F* f
+ , eina::index_sequence<N...>)
+{
+ assert(self != 0);
+ return (*f)(*self, isolate, js::get_element<N, Sig>(isolate, args)...);
+}
+
+template <typename Sig, typename T, typename F, typename R>
+compatibility_return_type call_generic_impl(compatibility_callback_info_type args, tag<R>)
+{
+ T* self = static_cast<T*>
+ (compatibility_get_pointer_internal_field<>(args.This(), 0));
+ F* f = reinterpret_cast<F*>(v8::External::Cast(*args.Data())->Value());
+ return compatibility_return
+ (js::get_value_from_c
+ (js::call_impl<Sig, R>(args.GetIsolate(), args, self, f
+ , eina::make_index_sequence<std::tuple_size<Sig>::value>())
+ , args.GetIsolate(), "")
+ , args);
+}
+
+template <typename Sig, typename T, typename F>
+compatibility_return_type call_generic_impl(compatibility_callback_info_type args, tag<void>)
+{
+ T* self = static_cast<T*>
+ (compatibility_get_pointer_internal_field(args.This(), 0));
+ F* f = reinterpret_cast<F*>(v8::External::Cast(*args.Data())->Value());
+ js::call_impl<Sig, void>(args.GetIsolate(), args, self, f
+ , eina::make_index_sequence<std::tuple_size<Sig>::value>());
+ return compatibility_return();
+}
+
+template <typename Sig, typename R, typename T, typename F>
+compatibility_return_type call_generic(compatibility_callback_info_type args)
+{
+ return efl::eina::js::call_generic_impl<Sig, T, F>(args, tag<R>());
+}
+
+template <typename Sig, typename T, typename F, typename R>
+compatibility_return_type call_function_impl(compatibility_callback_info_type args, tag<R>)
+{
+ T* self = static_cast<T*>
+ (compatibility_get_pointer_internal_field(args.This(), 0));
+ F f = reinterpret_cast<F>(v8::External::Cast(*args.Data())->Value());
+ return compatibility_return
+ (/*js::get_value_from_c*/
+ (js::call_impl<Sig, R>(args.GetIsolate(), args, self, f
+ , eina::make_index_sequence<std::tuple_size<Sig>::value>())
+ /*, args.GetIsolate(), ""*/)
+ , args);
+}
+
+template <typename Sig, typename T, typename F>
+compatibility_return_type call_function_impl(compatibility_callback_info_type args, tag<void>)
+{
+ T* self = static_cast<T*>
+ (compatibility_get_pointer_internal_field(args.This(), 0));
+ F f = reinterpret_cast<F>(v8::External::Cast(*args.Data())->Value());
+ js::call_impl<Sig, void>(args.GetIsolate(), args, self, f
+ , eina::make_index_sequence<std::tuple_size<Sig>::value>());
+ return compatibility_return();
+}
+
+template <typename Sig, typename R, typename T, typename F>
+compatibility_return_type call_function(compatibility_callback_info_type args)
+{
+ return efl::eina::js::call_function_impl<Sig, T, F>(args, tag<R>());
+}
+
+template <typename T, typename F>
+void register_(v8::Isolate* isolate, const char* name, F f, v8::Handle<v8::ObjectTemplate> template_
+ , typename std::enable_if<std::is_function<typename std::remove_pointer<F>::type>::value>::type* = 0)
+{
+ template_->Set(compatibility_new<v8::String>(isolate, name)
+ , compatibility_new<v8::FunctionTemplate>
+ (isolate, &efl::eina::js::call_function
+ <typename eina::_mpl::pop_front<typename function_params<F>::type, 2u>::type
+ , typename function_result<F>::type, T, F>
+ , compatibility_new<v8::External>
+ (isolate, reinterpret_cast<void*>(f))));
+}
+
+template <typename T, typename...Sig, typename F>
+void register_(v8::Isolate* isolate, const char* name, F&& f, v8::Handle<v8::ObjectTemplate> template_
+ , typename std::enable_if<!std::is_function<typename std::remove_pointer<F>::type>::value>::type* = 0)
+{
+ using result_type = decltype
+ (std::declval<F>()
+ (std::declval<T&>(), std::declval<v8::Isolate*>()
+ , std::declval<Sig>()...)
+ );
+ template_->Set(compatibility_new<v8::String>(isolate, name)
+ , compatibility_new<v8::FunctionTemplate>
+ (isolate
+ , &efl::eina::js::call_generic<std::tuple<Sig...>, result_type, T, F>
+ , compatibility_new<v8::External>
+ (isolate, new F(std::forward<F>(f)))));
+}
+
+v8::Local<v8::ObjectTemplate> register_template(v8::Isolate* isolate, v8::Handle<v8::FunctionTemplate> constructor)
+{
+ v8::Local<v8::ObjectTemplate> instance_t = constructor->InstanceTemplate();
+ instance_t->SetInternalFieldCount(1);
+
+ instance_t->SetIndexedPropertyHandler(& efl::eina::js::index_get, & efl::eina::js::index_set);
+
+ v8::Local<v8::ObjectTemplate> prototype = constructor->PrototypeTemplate();
+ prototype->SetAccessor(compatibility_new<v8::String>(isolate, "length"), &efl::eina::js::length);
+
+ using namespace std::placeholders;
+ js::register_<js::eina_container_base>
+ (isolate, "push", &js::push, prototype);
+ js::register_<js::eina_container_base>
+ (isolate, "pop", &js::pop, prototype);
+ js::register_<js::eina_container_base>
+ (isolate, "concat", &js::concat, prototype);
+ js::register_<js::eina_container_base>
+ (isolate, "slice", &js::slice, prototype);
+ js::register_<js::eina_container_base>
+ (isolate, "toString", std::bind(&js::eina_container_base::to_string, _1, _2), prototype);
+ js::register_<js::eina_container_base, v8::Local<v8::Value> >
+ (isolate, "join", std::bind(&js::eina_container_base::join, _1, _2, _3), prototype);
+ js::register_<js::eina_container_base, v8::Local<v8::Value> >
+ (isolate, "indexOf", std::bind(&js::eina_container_base::index_of, _1, _2, _3), prototype);
+ js::register_<js::eina_container_base, v8::Local<v8::Value> >
+ (isolate, "lastIndexOf", std::bind(&js::eina_container_base::last_index_of, _1, _2, _3), prototype);
+
+ return instance_t;
+}
+
+void register_class(v8::Isolate* isolate, container_type type, const char* class_name
+ , compatibility_function_callback callback)
+{
+ v8::Handle<v8::FunctionTemplate> constructor
+ = compatibility_new<v8::FunctionTemplate>(isolate, callback);
+ constructor->SetClassName(compatibility_new<v8::String>(isolate, class_name));
+
+ v8::Local<v8::ObjectTemplate> instance_t = efl::eina::js::register_template(isolate, constructor);
+
+ efl::eina::js::instance_persistents[type] = global_ref<v8::ObjectTemplate>{isolate, instance_t};
+ efl::eina::js::instance_templates[type] = global_ref<v8::Function>{isolate, constructor->GetFunction()};
+}
+void register_class(v8::Isolate* isolate, container_type, const char* class_name_
+ , const char* constructor_name_
+ , compatibility_function_callback callback
+ , v8::Handle<v8::Object> exports)
+{
+ v8::Handle<v8::FunctionTemplate> constructor
+ = compatibility_new<v8::FunctionTemplate>(isolate, callback);
+ auto class_name = compatibility_new<v8::String>(isolate, class_name_);
+ auto constructor_name = compatibility_new<v8::String>(isolate, constructor_name_);
+ constructor->SetClassName(class_name);
+
+ v8::Local<v8::ObjectTemplate> instance_t = efl::eina::js::register_template(isolate, constructor);
+ (void)instance_t;
+
+ exports->Set(constructor_name, constructor->GetFunction());
+}
+
+}
+
+EAPI v8::Handle<v8::Function> get_list_instance_template()
+{
+ return efl::eina::js::instance_templates[efl::eina::js::list_container_type].handle();
+}
+
+EAPI v8::Handle<v8::Function> get_array_instance_template()
+{
+ return efl::eina::js::instance_templates[efl::eina::js::array_container_type].handle();
+}
+
+} } }
+
+EAPI void eina_container_register(v8::Handle<v8::Object> exports, v8::Isolate* isolate)
+{
+ efl::eina::js::register_class(isolate, efl::eina::js::list_container_type
+ , "eina_list", &efl::eina::js::new_eina_list_internal);
+ efl::eina::js::register_class(isolate, efl::eina::js::list_container_type
+ , "eina_list", "List", &efl::eina::js::new_eina_list, exports);
+ efl::eina::js::register_class(isolate, efl::eina::js::array_container_type
+ , "eina_array", &efl::eina::js::new_eina_array_internal);
+ efl::eina::js::register_class(isolate, efl::eina::js::array_container_type
+ , "eina_array", "Array", &efl::eina::js::new_eina_array, exports);
+}
+
diff --git a/src/bindings/eina_js/eina_js_container.hh b/src/bindings/eina_js/eina_js_container.hh
new file mode 100644
index 0000000000..21343fd6da
--- /dev/null
+++ b/src/bindings/eina_js/eina_js_container.hh
@@ -0,0 +1,351 @@
+#ifndef EINA_JS_CONTAINER_HH
+#define EINA_JS_CONTAINER_HH
+
+#include <algorithm>
+
+#include <eina_js_compatibility.hh>
+#include <eina_js_get_value.hh>
+#include <eina_js_get_value_from_c.hh>
+
+struct _Elm_Calendar_Mark;
+struct Elm_Gen_Item;
+struct _Eina_Rectangle;
+struct _Evas_Textblock_Rectangle;
+struct _Elm_Map_Overlay;
+
+namespace efl { namespace eina { namespace js {
+
+namespace detail {
+
+template <typename T>
+eina_container_base* concat(T const& self, eina_container_base const& other)
+{
+ T const& rhs = static_cast<T const&>(other);
+ typedef typename T::container_type container_type;
+ container_type container(self._container.begin(), self._container.end());
+ container.insert(container.end(), rhs._container.begin(), rhs._container.end());
+ return new T(container.release_native_handle());
+}
+
+template <typename T>
+eina_container_base* slice(T const& self, std::int64_t i, std::int64_t j)
+{
+ typedef typename T::container_type container_type;
+ container_type container(std::next(self._container.begin(), i), std::next(self._container.begin(), j));
+ return new T(container.release_native_handle());
+}
+
+// T, W from the container instantiation
+template<typename T, typename W, typename C>
+int push(v8::Isolate* isolate, C& self, v8::Local<v8::Value> v)
+{
+ try
+ {
+ W value = container_wrap(get_value_from_javascript(v, isolate, "", value_tag<T>()));
+ self._container.push_back(value);
+ }
+ catch (std::logic_error const&)
+ {
+ return -1;
+ }
+ return self.size();
+}
+
+template<typename T, typename W, typename K, typename C>
+v8::Local<v8::Value> pop(v8::Isolate* isolate, C& self)
+{
+
+ if (self._container.empty())
+ return v8::Undefined(isolate);
+
+ auto value = eina::js::get_value_from_c(
+ eina::js::wrap_value<T>(eina::js::container_unwrap(self._container.back()), eina::js::value_tag<T>{})
+ , isolate
+ , K::class_name());
+ self._container.pop_back();
+ return value;
+}
+template<typename T, typename W, typename C>
+v8::Local<v8::Value> set(v8::Isolate* isolate, C& self, std::size_t index, v8::Local<v8::Value> v)
+ {
+ using notag_type = typename remove_tag<T>::type;
+ try
+ {
+ W value = container_wrap(get_value_from_javascript(v, isolate, "", value_tag<T>()));
+
+ if (index >= self.size())
+ {
+ std::size_t items_to_add = index - self.size() + 1;
+ for (int i = items_to_add; i; i--)
+ {
+ self._container.push_back(container_wrap(notag_type{}));
+ }
+ }
+
+ auto v2 = std::next(self._container.begin(), index);
+ *v2 = value;
+ }
+ catch (std::logic_error const&)
+ {
+ return v8::Undefined(isolate);
+ }
+
+ return v;
+ }
+
+}
+
+template <typename InputIterator, typename T>
+inline InputIterator find_element(InputIterator first, InputIterator last, T const& value, typename std::enable_if<is_handable_by_value<T>::value>::type* = 0)
+{
+ return std::find(first, last, value);
+}
+
+template <typename InputIterator, typename T>
+inline InputIterator find_element(InputIterator first, InputIterator last, T const& value, typename std::enable_if<!is_handable_by_value<T>::value>::type* = 0)
+{
+ return std::find_if(first, last, [&](T const& e){ return &e == &value; });
+}
+
+template <typename InputIterator>
+inline InputIterator find_element(InputIterator first, InputIterator last, char * value)
+{
+ return std::find_if(first, last, [=](char* e){ return strcmp(e, value) == 0; });
+}
+
+template <typename CharT, typename T>
+inline void stream_element(std::basic_ostream<CharT>& s, T const& value, typename std::enable_if<is_handable_by_value<T>::value>::type* = 0)
+{
+ s << value;
+}
+
+template <typename CharT, typename T>
+inline void stream_element(std::basic_ostream<CharT>& s, T const& value, typename std::enable_if<!is_handable_by_value<T>::value>::type* = 0)
+{
+ s << &value;
+}
+
+template <typename CharT>
+inline void stream_element(std::basic_ostream<CharT>& s, Eina_Bool value)
+{
+ s << (value ? "true" : "false");
+}
+
+template <typename C, typename T, typename K>
+struct eina_container_common;
+
+
+template <typename C, typename V, typename T, typename K, typename Enable = void>
+struct eina_container_type_specific
+ : eina_container_base
+{
+ v8::Local<v8::Value> get(v8::Isolate* isolate, std::size_t index) const
+ {
+ if(index >= this->size())
+ return v8::Undefined(isolate);
+ return eina::js::get_value_from_c(
+ eina::js::wrap_value<T>(eina::js::container_unwrap(*std::next(container_get().begin(), index)), eina::js::value_tag<T>{})
+ , isolate
+ , K::class_name());
+ }
+ int index_of(v8::Isolate* isolate, v8::Local<v8::Value> v) const
+ {
+ try
+ {
+ V value = container_wrap(get_value_from_javascript(
+ v, isolate, K::class_name(), eina::js::value_tag<T>{}, false));
+ typedef typename C::const_iterator iterator;
+ iterator first = container_get().cbegin()
+ , last = container_get().cend()
+ , found = find_element(first, last, value);
+ if(found == last)
+ return -1;
+ else
+ return std::distance(first, found);
+ }
+ catch (std::logic_error const&)
+ {
+ return -1;
+ }
+ }
+ int last_index_of(v8::Isolate* isolate, v8::Local<v8::Value> v) const
+ {
+ try
+ {
+ V value = container_wrap(get_value_from_javascript(
+ v, isolate, K::class_name(), eina::js::value_tag<T>{}, false));
+ auto last = container_get().crend()
+ , found = find_element(container_get().crbegin(), last, value);
+ if(found == last)
+ return -1;
+ else
+ return std::distance(container_get().cbegin(), found.base()) -1;
+ }
+ catch (std::logic_error const&)
+ {
+ return -1;
+ }
+ }
+ void* get_container_native_handle()
+ {
+ void const* h = container_get().native_handle();
+ return const_cast<void*>(h);
+ }
+ void const* get_container_native_handle() const
+ {
+ return container_get().native_handle();
+ }
+ C& container_get() { return static_cast<eina_container_common<C, T, K>&>(*this)._container; }
+ C const& container_get() const { return static_cast<eina_container_common<C, T, K>const&>(*this)._container; }
+};
+
+template <typename C, typename T, typename K>
+struct eina_container_common : eina_container_type_specific<C, typename C::value_type, T, K>
+{
+ eina_container_common() : _container() {}
+ eina_container_common(typename C::native_handle_type raw) : _container(raw) {}
+
+ std::size_t size() const { return _container.size(); }
+ v8::Local<v8::String> to_string(v8::Isolate* isolate) const
+ {
+ return join(isolate, compatibility_new<v8::String>(isolate, ","));
+ }
+
+ v8::Local<v8::String> join(v8::Isolate* isolate, v8::Local<v8::Value> separator_js) const
+ {
+ std::string separator = ",";
+ typedef typename container_type::const_iterator iterator;
+ std::stringstream s;
+
+ if (separator_js->IsString())
+ {
+ v8::String::Utf8Value str(separator_js);
+ if (*str)
+ {
+ separator = *str;
+ }
+ else
+ {
+ eina::js::compatibility_throw(
+ isolate, v8::Exception::TypeError(
+ eina::js::compatibility_new<v8::String>(isolate, "Invalid separator.")));
+ return compatibility_new<v8::String>(isolate, "");
+ }
+ }
+ else if (!separator_js->IsUndefined()) // Called join without arguments.
+ {
+ eina::js::compatibility_throw(
+ isolate, v8::Exception::TypeError(
+ eina::js::compatibility_new<v8::String>(isolate, "Separator must be a string.")));
+ return compatibility_new<v8::String>(isolate, "");
+ }
+
+ for(iterator first = _container.begin()
+ , last = _container.end()
+ , last_elem = std::next(last, -1); first != last; ++first)
+ {
+ stream_element(s, *first);
+ if(first != last_elem)
+ s << separator;
+ }
+ return compatibility_new<v8::String>(isolate, s.str().c_str());
+ }
+
+ // Default implementation of some methods
+ int push(v8::Isolate* isolate, v8::Local<v8::Value>)
+ {
+ eina::js::compatibility_throw
+ (isolate, v8::Exception::TypeError
+ (eina::js::compatibility_new<v8::String>(isolate, "Push method was not implemented.")));
+ return -1;
+ }
+ v8::Local<v8::Value> pop(v8::Isolate* isolate)
+ {
+ eina::js::compatibility_throw
+ (isolate, v8::Exception::TypeError
+ (eina::js::compatibility_new<v8::String>(isolate, "Pop method was not implemented.")));
+ return v8::Undefined(isolate);
+ }
+ v8::Local<v8::Value> set(v8::Isolate* isolate, std::size_t, v8::Local<v8::Value>)
+ {
+ eina::js::compatibility_throw
+ (isolate, v8::Exception::TypeError
+ (eina::js::compatibility_new<v8::String>(isolate, "Indexed attribution was not implemented.")));
+ return v8::Undefined(isolate);
+ }
+ C _container;
+ typedef C container_type;
+};
+
+
+// Specialization for problematic types
+struct empty_container_base
+ : eina_container_base
+{
+ empty_container_base() {}
+ virtual ~empty_container_base() {}
+
+ std::size_t size() const
+ {
+ return 0;
+ }
+ eina_container_base* concat(eina_container_base const& ) const
+ {
+ return new empty_container_base;
+ }
+ eina_container_base* slice(std::int64_t , std::int64_t ) const
+ {
+ return new empty_container_base;
+ }
+ int index_of(v8::Isolate*, v8::Local<v8::Value>) const
+ {
+ return -1;
+ }
+ int last_index_of(v8::Isolate*, v8::Local<v8::Value>) const
+ {
+ return -1;
+ }
+ v8::Local<v8::Value> get(v8::Isolate* isolate, std::size_t) const
+ {
+ return v8::Undefined(isolate);
+ }
+ v8::Local<v8::Value> set(v8::Isolate* isolate, std::size_t, v8::Local<v8::Value>)
+ {
+ return v8::Undefined(isolate);
+ }
+ int push(v8::Isolate*, v8::Local<v8::Value>)
+ {
+ return -1;
+ }
+ v8::Local<v8::Value> pop(v8::Isolate* isolate)
+ {
+ return v8::Undefined(isolate);
+ }
+ v8::Local<v8::String> to_string(v8::Isolate* isolate) const
+ {
+ return compatibility_new<v8::String>(isolate, "");
+ }
+ v8::Local<v8::String> join(v8::Isolate* isolate, v8::Local<v8::Value>) const
+ {
+ return compatibility_new<v8::String>(isolate, "");
+ }
+ container_type get_container_type() const
+ {
+ throw std::runtime_error("get_container_type of container with unmanagable type");
+ return container_type_size;
+ }
+ void* get_container_native_handle()
+ {
+ return nullptr;
+ }
+ void const* get_container_native_handle() const
+ {
+ return nullptr;
+ }
+};
+
+} } }
+
+EAPI void eina_container_register(v8::Handle<v8::Object> exports, v8::Isolate* isolate);
+
+#endif
diff --git a/src/bindings/eina_js/eina_js_error.cc b/src/bindings/eina_js/eina_js_error.cc
new file mode 100644
index 0000000000..89d69a1895
--- /dev/null
+++ b/src/bindings/eina_js/eina_js_error.cc
@@ -0,0 +1,24 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <Eina_Js.hh>
+
+namespace efl { namespace eina {namespace js {
+
+EAPI
+js::compatibility_return_type convert_error_to_javascript_exception(v8::Isolate *isolate)
+{
+ Eina_Error err = eina_error_get();
+ if (!err)
+ return compatibility_return();
+
+ v8::Local<v8::Object> je = eina::js::compatibility_new<v8::Object>(isolate);
+ je->Set(compatibility_new<v8::String>(isolate, "code"),
+ compatibility_new<v8::String>(isolate, "Eina_Error"));
+ je->Set(compatibility_new<v8::String>(isolate, "value"),
+ compatibility_new<v8::String>(isolate, eina_error_msg_get(err)));
+ return compatibility_throw(isolate, je);
+}
+
+} } } // namespace efl { namespace js {
diff --git a/src/bindings/eina_js/eina_js_error.hh b/src/bindings/eina_js/eina_js_error.hh
new file mode 100644
index 0000000000..49cef35161
--- /dev/null
+++ b/src/bindings/eina_js/eina_js_error.hh
@@ -0,0 +1,25 @@
+#ifndef EINA_JS_ERROR_HH
+#define EINA_JS_ERROR_HH
+
+#include <eina_js_compatibility.hh>
+
+namespace efl { namespace eina { namespace js {
+
+/**
+ * Converts the error value set through Eina's error tool to a JavaScript
+ * exception.
+ *
+ * The exception object will have a `code` string field with the `"Eina_Error"`
+ * string value and a `value` string field with the value extracted from
+ * `eina_error_msg_get`.
+ *
+ * It won't reset the error to NULL, so you can still access the error object,
+ * but if you keep calling this function without clearing the error, a new
+ * exception will be generated for each call after some error is reached. We,
+ * therefore, suggest you to call `eina_error_set(0)` afterwards.
+ */
+js::compatibility_return_type convert_error_to_javascript_exception(v8::Isolate *isolate);
+
+} } } // namespace efl::eina::js
+
+#endif /* EINA_JS_ERROR_HH */
diff --git a/src/bindings/eina_js/eina_js_get_value.hh b/src/bindings/eina_js/eina_js_get_value.hh
new file mode 100644
index 0000000000..637b48a9c8
--- /dev/null
+++ b/src/bindings/eina_js/eina_js_get_value.hh
@@ -0,0 +1,449 @@
+#ifndef EFL_EINA_JS_GET_VALUE_HH
+#define EFL_EINA_JS_GET_VALUE_HH
+
+#include <eina_js_compatibility.hh>
+
+#include <type_traits>
+#include <cstdlib>
+#include <iostream>
+#include <typeinfo>
+
+namespace efl { namespace eina { namespace js {
+
+template <typename T>
+inline int get_value_from_javascript
+ (v8::Local<v8::Value> v
+ , v8::Isolate* isolate
+ , const char*
+ , value_tag<T>
+ , bool throw_js_exception = true
+ , typename std::enable_if<(std::is_integral<T>::value && !std::is_same<T, Eina_Bool>::value)>::type* = 0)
+{
+ if(v->IsInt32())
+ return v->Int32Value();
+ else if(v->IsUint32())
+ return v->Uint32Value();
+ else
+ {
+ if (throw_js_exception)
+ eina::js::compatibility_throw
+ (isolate, v8::Exception::TypeError
+ (eina::js::compatibility_new<v8::String>(isolate, "Type expected is different. Expected Integral type")));
+
+ throw std::logic_error("");
+ }
+ return 0;
+}
+
+inline char* get_value_from_javascript
+ (v8::Local<v8::Value> v
+ , v8::Isolate* isolate
+ , const char*
+ , value_tag<char*>
+ , bool throw_js_exception = true)
+{
+ if(v->IsNull())
+ return nullptr;
+ else if(v->IsString())
+ {
+ v8::String::Utf8Value str(v->ToString());
+ char* string = strdup(*str); // TODO: leaks
+ return string;
+ }
+ else
+ {
+ if (throw_js_exception)
+ eina::js::compatibility_throw
+ (isolate, v8::Exception::TypeError
+ (eina::js::compatibility_new<v8::String>(isolate, "Type expected is different. Expected String type")));
+
+ throw std::logic_error("");
+ }
+ return 0;
+}
+
+inline const char* get_value_from_javascript
+ (v8::Local<v8::Value> v
+ , v8::Isolate* isolate
+ , const char* class_name
+ , value_tag<const char*>
+ , bool throw_js_exception = true)
+{
+ return get_value_from_javascript(v, isolate, class_name, value_tag<char*>(), throw_js_exception);
+}
+
+inline Eo* get_value_from_javascript
+ (v8::Local<v8::Value> v
+ , v8::Isolate* isolate
+ , const char*
+ , value_tag<Eo*>
+ , bool throw_js_exception = true)
+{
+ if(v->IsNull())
+ return nullptr;
+ else if(v->IsObject())
+ {
+ v8::Local<v8::Object> object = v->ToObject();
+ if(object->InternalFieldCount() == 1)
+ {
+ v8::Local<v8::Value> r = object->GetInternalField(0);
+ if(v8::External* external = v8::External::Cast(*r))
+ {
+ return static_cast<Eo*>(external->Value());
+ }
+ }
+ }
+ if (throw_js_exception)
+ eina::js::compatibility_throw
+ (isolate, v8::Exception::TypeError
+ (eina::js::compatibility_new<v8::String>(isolate, "Type expected is different. Expected Eolian object type")));
+ throw std::logic_error("");
+ return nullptr;
+}
+
+inline Eo* get_value_from_javascript
+ (v8::Local<v8::Value> v
+ , v8::Isolate* isolate
+ , const char* class_name
+ , value_tag<Eo* const>
+ , bool throw_js_exception = true)
+{
+ return get_value_from_javascript(v, isolate, class_name, value_tag<Eo*>(), throw_js_exception);
+}
+
+template <typename T>
+inline T get_value_from_javascript
+ (v8::Local<v8::Value> v
+ , v8::Isolate* isolate
+ , const char*
+ , value_tag<struct_ptr_tag<T>>
+ , bool throw_js_exception = true)
+{
+ if(v->IsNull())
+ return nullptr;
+ else if(v->IsObject())
+ {
+ v8::Local<v8::Object> object = v->ToObject();
+ if(object->InternalFieldCount() == 1)
+ {
+ return compatibility_get_pointer_internal_field<T>(object, 0);
+ }
+ }
+ if (throw_js_exception)
+ eina::js::compatibility_throw
+ (isolate, v8::Exception::TypeError
+ (eina::js::compatibility_new<v8::String>(isolate, "Type expected is different. Expected Eolian struct type")));
+ throw std::logic_error("");
+ return nullptr;
+}
+
+template <typename T>
+inline T get_value_from_javascript
+ (v8::Local<v8::Value> v
+ , v8::Isolate* isolate
+ , const char* class_name
+ , value_tag<struct_tag<T>>
+ , bool throw_js_exception = true)
+{
+ T* ptr = get_value_from_javascript(v, isolate, class_name, value_tag<struct_ptr_tag<T*>>(), throw_js_exception);
+ if (ptr)
+ return *ptr;
+
+ if (throw_js_exception)
+ eina::js::compatibility_throw
+ (isolate, v8::Exception::TypeError
+ (eina::js::compatibility_new<v8::String>(isolate, "Conversion of null pointer to by-value struct.")));
+ throw std::logic_error("");
+ return T{};
+}
+
+template <typename T>
+inline T get_value_from_javascript
+ (v8::Local<v8::Value> v
+ , v8::Isolate* isolate
+ , const char*
+ , value_tag<T>
+ , bool throw_js_exception = true
+ , typename std::enable_if<std::is_enum<T>::value>::type* = 0)
+{
+ if(v->IsInt32())
+ return static_cast<T>(v->Int32Value());
+ else if(v->IsUint32())
+ return static_cast<T>(v->Uint32Value());
+ else
+ {
+ if (throw_js_exception)
+ eina::js::compatibility_throw
+ (isolate, v8::Exception::TypeError
+ (eina::js::compatibility_new<v8::String>(isolate, "Type expected is different. Expected enumeration type")));
+
+ throw std::logic_error("");
+ }
+ return T();
+}
+
+inline Eina_Bool get_value_from_javascript
+ (v8::Local<v8::Value> v
+ , v8::Isolate* isolate
+ , const char*
+ , value_tag<Eina_Bool>
+ , bool throw_js_exception = true)
+{
+ if(v->IsBoolean() || v->IsBooleanObject())
+ {
+ return v->BooleanValue() ? EINA_TRUE : EINA_FALSE;
+ }
+ else
+ {
+ if (throw_js_exception)
+ eina::js::compatibility_throw
+ (isolate, v8::Exception::TypeError
+ (eina::js::compatibility_new<v8::String>(isolate, "Type expected is different. Expected Boolean type")));
+
+ throw std::logic_error("");
+ }
+ return 0;
+}
+
+template <typename T>
+inline double get_value_from_javascript
+ (v8::Local<v8::Value> v
+ , v8::Isolate* isolate
+ , const char*
+ , value_tag<T>
+ , bool throw_js_exception = true
+ , typename std::enable_if<std::is_floating_point<T>::value>::type* = 0)
+{
+ if(v->IsNumber())
+ {
+ return v->NumberValue();
+ }
+ else
+ {
+ if (throw_js_exception)
+ eina::js::compatibility_throw
+ (isolate, v8::Exception::TypeError
+ (eina::js::compatibility_new<v8::String>(isolate, "Type expected is different. Expected floating point type")));
+ throw std::logic_error("");
+ }
+ return 0.0;
+}
+
+template <typename T>
+inline T get_value_from_javascript
+ (v8::Local<v8::Value>, v8::Isolate* isolate, const char*, value_tag<T>
+ , bool throw_js_exception = true
+ , typename std::enable_if<
+ !std::is_floating_point<T>::value &&
+ !std::is_integral<T>::value &&
+ !std::is_enum<T>::value &&
+ !js::is_struct_tag<T>::value &&
+ !js::is_struct_ptr_tag<T>::value &&
+ !js::is_complex_tag<T>::value &&
+ !std::is_same<T, Eina_Accessor*>::value &&
+ !std::is_same<T, Eina_Array*>::value &&
+ !std::is_same<T, Eina_Iterator*>::value &&
+ !std::is_same<T, Eina_Hash*>::value &&
+ !std::is_same<T, Eina_List*>::value &&
+ !std::is_same<T, const Eina_Accessor*>::value &&
+ !std::is_same<T, const Eina_Array*>::value &&
+ !std::is_same<T, const Eina_Iterator*>::value &&
+ !std::is_same<T, const Eina_Hash*>::value &&
+ !std::is_same<T, const Eina_List*>::value
+ >::type* = 0)
+{
+ if (throw_js_exception)
+ eina::js::compatibility_throw
+ (isolate, v8::Exception::TypeError
+ (eina::js::compatibility_new<v8::String>(isolate, "Not implemented yet")));
+ throw std::logic_error("");
+}
+
+// TODO: Fix for const types
+template <typename T, typename K>
+inline Eina_Accessor* get_value_from_javascript(
+ v8::Local<v8::Value> v,
+ v8::Isolate* isolate,
+ const char*,
+ value_tag<complex_tag<Eina_Accessor *, T, K>>,
+ bool throw_js_exception = true)
+{
+ if(v->IsNull())
+ return nullptr;
+ else if(v->IsObject())
+ {
+ using wrapped_type = typename container_wrapper<T>::type;
+ v8::Local<v8::Object> object = v->ToObject();
+ auto& acc = import_accessor<wrapped_type>(object);
+ return acc.native_handle();
+ }
+ if (throw_js_exception)
+ eina::js::compatibility_throw
+ (isolate, v8::Exception::TypeError
+ (eina::js::compatibility_new<v8::String>(isolate, "Type expected is different. Expected Eolian accessor type")));
+ throw std::logic_error("");
+}
+
+template <typename...I>
+inline const Eina_Accessor* get_value_from_javascript(
+ v8::Local<v8::Value> v,
+ v8::Isolate* isolate,
+ const char* class_name,
+ value_tag<complex_tag<const Eina_Accessor *, I...>>,
+ bool throw_js_exception = true)
+{
+ return get_value_from_javascript(v, isolate, class_name, value_tag<complex_tag<Eina_Accessor *, I...>>{}, throw_js_exception);
+}
+
+template <typename...I>
+inline Eina_Array* get_value_from_javascript(
+ v8::Local<v8::Value> v,
+ v8::Isolate* isolate,
+ const char*,
+ value_tag<complex_tag<Eina_Array *, I...>>,
+ bool throw_js_exception = true)
+{
+ if(v->IsNull())
+ return nullptr;
+ else if(v->IsObject())
+ {
+ v8::Local<v8::Object> object = v->ToObject();
+ if(object->InternalFieldCount() == 1)
+ {
+ eina_container_base* cbase = compatibility_get_pointer_internal_field<eina_container_base*>(object, 0);
+ return static_cast<Eina_Array*>(cbase->get_container_native_handle());
+ }
+ }
+ if (throw_js_exception)
+ eina::js::compatibility_throw
+ (isolate, v8::Exception::TypeError
+ (eina::js::compatibility_new<v8::String>(isolate, "Type expected is different. Expected Eolian list type")));
+ throw std::logic_error("");
+ return nullptr;
+}
+
+template <typename...I>
+inline const Eina_Array* get_value_from_javascript(
+ v8::Local<v8::Value> v,
+ v8::Isolate* isolate,
+ const char* class_name,
+ value_tag<complex_tag<const Eina_Array *, I...>>,
+ bool throw_js_exception = true)
+{
+ return get_value_from_javascript(v, isolate, class_name, value_tag<complex_tag<Eina_Array *, I...>>{}, throw_js_exception);
+}
+
+template <typename...I>
+inline Eina_Iterator* get_value_from_javascript(
+ v8::Local<v8::Value>,
+ v8::Isolate* isolate,
+ const char*,
+ value_tag<complex_tag<Eina_Iterator *, I...>> tag,
+ bool throw_js_exception = true)
+{
+ if (throw_js_exception)
+ eina::js::compatibility_throw
+ (isolate, v8::Exception::TypeError
+ (eina::js::compatibility_new<v8::String>(isolate, "Not implemented yet")));
+ throw std::logic_error("");
+}
+
+template <typename...I>
+inline const Eina_Iterator* get_value_from_javascript(
+ v8::Local<v8::Value> v,
+ v8::Isolate* isolate,
+ const char* class_name,
+ value_tag<complex_tag<const Eina_Iterator *, I...>>,
+ bool throw_js_exception = true)
+{
+ return get_value_from_javascript(v, isolate, class_name, value_tag<complex_tag<Eina_Iterator *, I...>>{}, throw_js_exception);
+}
+
+template <typename T, typename...U>
+inline Eina_Hash* get_value_from_javascript(
+ v8::Local<v8::Value>,
+ v8::Isolate* isolate,
+ const char*,
+ value_tag<complex_tag<Eina_Hash *, T, U...>> tag,
+ bool throw_js_exception = true)
+{
+ if (throw_js_exception)
+ eina::js::compatibility_throw
+ (isolate, v8::Exception::TypeError
+ (eina::js::compatibility_new<v8::String>(isolate, "Not implemented yet")));
+ throw std::logic_error("");
+}
+
+template <typename T, typename...U>
+inline const Eina_Hash* get_value_from_javascript(
+ v8::Local<v8::Value> v,
+ v8::Isolate* isolate,
+ const char* class_name,
+ value_tag<complex_tag<const Eina_Hash *, T, U...>>,
+ bool throw_js_exception = true)
+{
+ return get_value_from_javascript(v, isolate, class_name, value_tag<complex_tag<Eina_Hash *, T, U...>>{}, throw_js_exception);
+}
+
+template <typename...I>
+inline Eina_List* get_value_from_javascript(
+ v8::Local<v8::Value> v,
+ v8::Isolate* isolate,
+ const char*,
+ value_tag<complex_tag<Eina_List *, I...>> /*tag*/,
+ bool throw_js_exception = true)
+{
+ if(v->IsNull())
+ return nullptr;
+ else if(v->IsObject())
+ {
+ v8::Local<v8::Object> object = v->ToObject();
+ if(object->InternalFieldCount() == 1)
+ {
+ eina_container_base* cbase = compatibility_get_pointer_internal_field<eina_container_base*>(object, 0);
+ return static_cast<Eina_List*>(cbase->get_container_native_handle());
+ }
+ }
+ if (throw_js_exception)
+ eina::js::compatibility_throw
+ (isolate, v8::Exception::TypeError
+ (eina::js::compatibility_new<v8::String>(isolate, "Type expected is different. Expected Eolian list type")));
+ throw std::logic_error("");
+ return nullptr;
+}
+
+template <typename...I>
+inline const Eina_List* get_value_from_javascript(
+ v8::Local<v8::Value> v,
+ v8::Isolate* isolate,
+ const char* class_name,
+ value_tag<complex_tag<const Eina_List *, I...>>,
+ bool throw_js_exception = true)
+{
+ return get_value_from_javascript(v, isolate, class_name, value_tag<complex_tag<Eina_List *, I...>>{}, throw_js_exception);
+}
+
+inline const void* get_value_from_javascript
+ (v8::Local<v8::Value>,
+ v8::Isolate*,
+ const char*,
+ value_tag<const void *>)
+{
+ return nullptr;
+}
+
+
+typedef void (*Evas_Smart_Cb)(void*, _Eo_Opaque*, void*);
+
+inline Evas_Smart_Cb get_value_from_javascript (
+ v8::Local<v8::Value>,
+ v8::Isolate*,
+ const char*,
+ value_tag<Evas_Smart_Cb>)
+{
+ return nullptr;
+}
+
+} } }
+
+#endif
diff --git a/src/bindings/eina_js/eina_js_get_value_from_c.hh b/src/bindings/eina_js/eina_js_get_value_from_c.hh
new file mode 100644
index 0000000000..655b1b1974
--- /dev/null
+++ b/src/bindings/eina_js/eina_js_get_value_from_c.hh
@@ -0,0 +1,261 @@
+#ifndef EFL_EINA_JS_GET_VALUE_FROM_C_HH
+#define EFL_EINA_JS_GET_VALUE_FROM_C_HH
+
+#include <eina_js_compatibility.hh>
+
+#include <type_traits>
+#include <cstdlib>
+#include <typeinfo>
+#include <memory>
+
+namespace efl { namespace eina { namespace js {
+
+template <typename T> struct print_tag {};
+
+template <typename T>
+inline v8::Local<v8::Value>
+get_value_from_c(T v, v8::Isolate* isolate, const char*
+ , typename std::enable_if<std::is_integral<typename std::remove_reference<T>::type>::value && !std::is_same<T, Eina_Bool>::value>::type* = 0)
+{
+ return eina::js::compatibility_new<v8::Integer>(isolate, v);
+}
+
+template <typename T>
+inline v8::Local<v8::Value>
+get_value_from_c(T v, v8::Isolate* isolate, const char*
+ , typename std::enable_if<std::is_enum<typename std::remove_reference<T>::type>::value>::type* = 0)
+{
+ return eina::js::compatibility_new<v8::Integer>(isolate, v);
+}
+
+template <typename T>
+inline v8::Local<v8::Value>
+get_value_from_c(T v, v8::Isolate* isolate, const char*
+ , typename std::enable_if<std::is_same<typename std::remove_reference<T>::type, Eina_Bool>::value>::type* = 0)
+{
+ return eina::js::compatibility_new<v8::Boolean>(isolate, v);
+}
+
+template <typename T>
+inline v8::Local<T>
+get_value_from_c(v8::Local<T> v, v8::Isolate*, const char*)
+{
+ return v;
+}
+
+template <typename T>
+inline v8::Local<v8::Value>
+get_value_from_c(T v, v8::Isolate* isolate, const char*
+ , typename std::enable_if<std::is_floating_point<typename std::remove_reference<T>::type>::value>::type* = 0)
+{
+ return eina::js::compatibility_new<v8::Number>(isolate, v);
+}
+
+inline v8::Local<v8::Value>
+get_value_from_c(const char* v, v8::Isolate* isolate, const char*)
+{
+ if (!v)
+ return v8::Null(isolate);
+
+ return eina::js::compatibility_new<v8::String>(isolate, v);
+}
+
+inline v8::Local<v8::Value>
+get_value_from_c(char* v, v8::Isolate* isolate, const char* class_name)
+{
+ return js::get_value_from_c(const_cast<const char*>(v), isolate, class_name);
+}
+
+inline v8::Local<v8::Value>
+get_value_from_c(void*, v8::Isolate*, const char*)
+{
+ // TODO: create Extern?
+ std::cerr << "aborting because we don't know the type void*" << std::endl;
+ std::abort();
+}
+
+inline v8::Local<v8::Value>
+get_value_from_c(const void*, v8::Isolate*, const char*)
+{
+ // TODO: create Extern?
+ std::cerr << "aborting because we don't know the type void*" << std::endl;
+ std::abort();
+}
+
+// For function pointer types
+template <typename T>
+inline v8::Local<v8::Value>
+get_value_from_c(T, v8::Isolate*, const char*
+ , typename std::enable_if
+ <std::is_pointer<typename std::remove_reference<T>::type>::value
+ && std::is_function<typename std::remove_pointer<typename std::remove_reference<T>::type>::type>::value
+ >::type* = 0)
+{
+ // TODO: create Extern?
+ std::cerr << "aborting because we don't know the type " << typeid(print_tag<T>).name() << std::endl;
+ std::abort();
+}
+
+// For all non-pointer types that are not handled
+template <typename T>
+inline v8::Local<v8::Value>
+get_value_from_c(T, v8::Isolate*, const char*
+ , typename std::enable_if
+ <!std::is_pointer<typename std::remove_reference<T>::type>::value
+ && !std::is_integral<typename std::remove_reference<T>::type>::value
+ && !std::is_floating_point<typename std::remove_reference<T>::type>::value
+ && !std::is_enum<typename std::remove_reference<T>::type>::value
+ && !std::is_same<typename std::remove_reference<T>::type, Eina_Bool>::value
+ && !js::is_struct_tag<typename std::remove_reference<T>::type>::value
+ && !js::is_struct_ptr_tag<typename std::remove_reference<T>::type>::value
+ && !js::is_complex_tag<typename std::remove_reference<T>::type>::value
+ >::type* = 0)
+{
+ std::cerr << "aborting because we don't know the type " << typeid(print_tag<T>).name() << std::endl;
+ std::abort();
+}
+
+// For all non-handled pointer types (which are not function pointers):
+// - we try to dereference it in the SFINAE
+// - if it matches we call get_value_from_c for the dereferenced type
+// - if it fails (probably because it is opaque) the void* or const void*
+// overload will take place (implicit conversion)
+template <typename T>
+inline auto
+get_value_from_c(T object, v8::Isolate* isolate, const char* class_name
+ , typename std::enable_if<
+ (std::is_pointer<typename std::remove_reference<T>::type>::value
+ && !std::is_function<typename std::remove_pointer<typename std::remove_reference<T>::type>::type>::value
+ )
+ && !(std::is_same<typename std::remove_reference<T>::type, char*>::value ||
+ std::is_same<typename std::remove_reference<T>::type, const char*>::value ||
+ std::is_same<typename std::remove_reference<T>::type, void*>::value ||
+ std::is_same<typename std::remove_reference<T>::type, const void*>::value ||
+ std::is_same<typename std::remove_reference<T>::type, Eo*>::value ||
+ std::is_same<typename std::remove_reference<T>::type, const Eo*>::value
+ )>::type* = 0) -> decltype(get_value_from_c(*object, isolate, class_name))
+{
+ std::cerr << "dereferencing " << typeid(print_tag<T>).name() << std::endl;
+ return get_value_from_c(*object, isolate, class_name);
+}
+
+inline v8::Local<v8::Value>
+get_value_from_c(Eo* v, v8::Isolate* isolate, const char* class_name)
+{
+ auto ctor = ::efl::eina::js::get_class_constructor(class_name);
+ return new_v8_external_instance(ctor, v, isolate);
+}
+
+inline v8::Local<v8::Value>
+get_value_from_c(const Eo* v, v8::Isolate* isolate, const char* class_name)
+{
+ // TODO: implement const objects?
+ auto ctor = ::efl::eina::js::get_class_constructor(class_name);
+ return new_v8_external_instance(ctor, const_cast<Eo*>(v), isolate);
+}
+
+template <typename T>
+inline v8::Local<v8::Value>
+get_value_from_c(struct_ptr_tag<T> v, v8::Isolate* isolate, const char* class_name)
+{
+ // TODO: implement const structs?
+ auto ctor = ::efl::eina::js::get_class_constructor(class_name);
+ return new_v8_external_instance(ctor, const_cast<typename std::remove_const<T>::type>(v.value), isolate);
+}
+
+template <typename T>
+inline v8::Local<v8::Value>
+get_value_from_c(struct_tag<T> v, v8::Isolate* isolate, const char* class_name)
+{
+ return get_value_from_c(struct_ptr_tag<T*>{new T(v.value)}, isolate, class_name);
+}
+
+template <typename T, typename K>
+inline v8::Local<v8::Value>
+get_value_from_c(efl::eina::js::complex_tag<Eina_Accessor *, T, K> v, v8::Isolate* isolate, const char*)
+{
+ using wrapped_type = typename container_wrapper<T>::type;
+ auto a = new ::efl::eina::accessor<wrapped_type>{v.value};
+ return export_accessor<T>(*a , isolate, K::class_name());
+}
+
+template <typename T, typename K>
+inline v8::Local<v8::Value>
+get_value_from_c(efl::eina::js::complex_tag<const Eina_Accessor *, T, K> v, v8::Isolate* isolate, const char* class_name)
+{
+ // TODO implement const accessor?
+ return get_value_from_c(efl::eina::js::complex_tag<Eina_Accessor*, T, K>{const_cast<Eina_Accessor*>(v.value)}, isolate, class_name);
+}
+
+template <typename T, typename K>
+inline v8::Local<v8::Value>
+get_value_from_c(efl::eina::js::complex_tag<Eina_Array *, T, K> v, v8::Isolate* isolate, const char*)
+{
+ // TODO: use unique_ptr for eina_array to avoid leak ?
+ auto o = new ::efl::eina::js::range_eina_array<T, K>(v.value);
+ auto ctor = get_array_instance_template();
+ return new_v8_external_instance(ctor, o, isolate);
+}
+
+template <typename T, typename K>
+inline v8::Local<v8::Value>
+get_value_from_c(efl::eina::js::complex_tag<const Eina_Array *, T, K> v, v8::Isolate* isolate, const char* class_name)
+{
+ // TODO: implement const array?
+ return get_value_from_c(efl::eina::js::complex_tag<Eina_Array *, T, K>{const_cast<Eina_Array*>(v.value)}, isolate, class_name);
+}
+
+template <typename T, typename K>
+inline v8::Local<v8::Value>
+get_value_from_c(efl::eina::js::complex_tag<Eina_Iterator *, T, K>, v8::Isolate*, const char*)
+{
+ std::cerr << "get_value_from_c for Eina_Iterator not implemented. Aborting..." << std::endl;
+ std::abort();
+}
+
+template <typename T, typename K>
+inline v8::Local<v8::Value>
+get_value_from_c(efl::eina::js::complex_tag<const Eina_Iterator *, T, K>, v8::Isolate*, const char*)
+{
+ std::cerr << "get_value_from_c for Eina_Iterator not implemented. Aborting..." << std::endl;
+ std::abort();
+}
+
+template <typename T, typename U, typename K>
+inline v8::Local<v8::Value>
+get_value_from_c(efl::eina::js::complex_tag<Eina_Hash *, T, U, K>, v8::Isolate*, const char*)
+{
+ std::cerr << "get_value_from_c for Eina_Hash not implemented. Aborting..." << std::endl;
+ std::abort();
+}
+
+template <typename T, typename U, typename K>
+inline v8::Local<v8::Value>
+get_value_from_c(efl::eina::js::complex_tag<const Eina_Hash *, T, U, K>, v8::Isolate*, const char*)
+{
+ std::cerr << "get_value_from_c for Eina_Hash not implemented. Aborting..." << std::endl;
+ std::abort();
+}
+
+template <typename T, typename K>
+inline v8::Local<v8::Value>
+get_value_from_c(efl::eina::js::complex_tag<Eina_List *, T, K> v, v8::Isolate* isolate, const char*)
+{
+ // TODO: ensure eina_list ownership ???
+ auto o = new ::efl::eina::js::range_eina_list<T, K>(v.value);
+ auto ctor = get_list_instance_template();
+ return new_v8_external_instance(ctor, o, isolate);
+}
+
+template <typename T, typename K>
+inline v8::Local<v8::Value>
+get_value_from_c(efl::eina::js::complex_tag<const Eina_List *, T, K> v, v8::Isolate* isolate, const char* class_name)
+{
+ // TODO: implement const list?
+ return get_value_from_c(efl::eina::js::complex_tag<Eina_List *, T, K>{const_cast<Eina_List*>(v.value)}, isolate, class_name);
+}
+
+
+} } }
+
+#endif
diff --git a/src/bindings/eina_js/eina_js_iterator.cc b/src/bindings/eina_js/eina_js_iterator.cc
new file mode 100644
index 0000000000..d2480b8be2
--- /dev/null
+++ b/src/bindings/eina_js/eina_js_iterator.cc
@@ -0,0 +1,32 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <Eina.hh>
+#include <Eina_Js.hh>
+
+namespace efl { namespace eina { namespace js {
+
+EAPI
+void register_destroy_iterator(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ typedef void (*deleter_t)(void*);
+
+ auto f = [](compatibility_callback_info_type info) -> compatibility_return_type
+ {
+ if (info.Length() != 1 || !info[0]->IsObject())
+ return compatibility_return();
+
+ v8::Handle<v8::Object> o = info[0]->ToObject();
+
+ deleter_t deleter = compatibility_get_pointer_internal_field<deleter_t>(o, 1);
+ deleter(compatibility_get_pointer_internal_field<>(o, 0));
+ return compatibility_return();
+ };
+
+ global->Set(name, compatibility_new<v8::FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+} } } // namespace efl { namespace js {
diff --git a/src/bindings/eina_js/eina_js_iterator.hh b/src/bindings/eina_js/eina_js_iterator.hh
new file mode 100644
index 0000000000..ed0066bf0b
--- /dev/null
+++ b/src/bindings/eina_js/eina_js_iterator.hh
@@ -0,0 +1,81 @@
+#ifndef EINA_JS_ITERATOR_HH
+#define EINA_JS_ITERATOR_HH
+
+#include <type_traits>
+
+#include <eina_js_value.hh>
+
+namespace efl { namespace eina { namespace js {
+
+/* Exports the \p iterator to be manipulated by the JS code. The iterator should
+ remain alive as long as there is JS code referencing it. The JS code is able
+ to destroy the iterator by itself if you register the appropriate function
+ through `register_destroy_iterator`.
+
+ The exported JS object models part the [iterator concept from ECMAScript
+ 6](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/The_Iterator_protocol).
+
+ The iterator will have the `next` function, but the returned object won't
+ have a `done` attribute, because the eina_iterator itself doesn't expose this
+ information.*/
+template<class T>
+v8::Local<v8::Object> export_iterator(::efl::eina::iterator<T> *i,
+ v8::Isolate *isolate)
+{
+ typedef ::efl::eina::iterator<T> value_type;
+ typedef value_type *ptr_type;
+ typedef void (*deleter_t)(void*);
+
+ auto obj_tpl = compatibility_new<v8::ObjectTemplate>(isolate);
+ obj_tpl->SetInternalFieldCount(2);
+
+ auto ret = obj_tpl->NewInstance();
+
+ auto next = [](js::compatibility_callback_info_type info) -> compatibility_return_type
+ {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ void *ptr = compatibility_get_pointer_internal_field(info.This(), 0);
+ auto &value = *static_cast<ptr_type>(ptr);
+ v8::Local<v8::Object> o = compatibility_new<v8::Object>(info.GetIsolate());
+ o->Set(compatibility_new<v8::String>(info.GetIsolate(), "value"),
+ value_cast<v8::Local<v8::Value>>(*value, info.GetIsolate()));
+ ++value;
+ return compatibility_return(o, info);
+ };
+
+ ret->Set(compatibility_new<v8::String>(isolate, "next"),
+ compatibility_new<v8::FunctionTemplate>(isolate, next)->GetFunction());
+
+ {
+ deleter_t deleter = [](void *i) {
+ delete static_cast<ptr_type>(i);
+ };
+ compatibility_set_pointer_internal_field(ret, 0, i);
+ compatibility_set_pointer_internal_field
+ (ret, 1, reinterpret_cast<void*>(deleter));
+ }
+
+ return ret;
+}
+
+/* Extracts and returns a copy from the internal iterator object from the JS
+ object. */
+template<class T>
+::efl::eina::iterator<T> *import_iterator(v8::Handle<v8::Object> o)
+ ;
+// {
+// typedef ::efl::eina::iterator<T> value_type;
+// typedef value_type *ptr_type;
+
+// return reinterpret_cast<ptr_type>(o->GetAlignedPointerFromInternalField(0));
+// }
+
+void register_destroy_iterator(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+} } } // namespace efl::js
+
+#endif /* EINA_JS_ITERATOR_HH */
diff --git a/src/bindings/eina_js/eina_js_list.hh b/src/bindings/eina_js/eina_js_list.hh
new file mode 100644
index 0000000000..6ab0521847
--- /dev/null
+++ b/src/bindings/eina_js/eina_js_list.hh
@@ -0,0 +1,132 @@
+#ifndef EINA_JS_LIST_HH
+#define EINA_JS_LIST_HH
+
+#include <iostream>
+
+#include <eina_js_container.hh>
+#include <eina_js_compatibility.hh>
+
+#include <iterator>
+
+namespace efl { namespace eina { namespace js {
+
+template <typename T, typename K, typename W>
+struct eina_list : eina_container_common<efl::eina::list
+ <W
+ , typename std::conditional
+ <std::is_base_of<efl::eo::concrete, W>::value
+ , efl::eina::eo_clone_allocator
+ , efl::eina::malloc_clone_allocator
+ >::type>, T, K>
+{
+ typedef eina_container_common<efl::eina::list<W
+ , typename std::conditional
+ <std::is_base_of<efl::eo::concrete, W>::value
+ , efl::eina::eo_clone_allocator
+ , efl::eina::malloc_clone_allocator
+ >::type>, T, K> base_type;
+ using base_type::base_type;
+ typedef typename base_type::container_type container_type;
+
+ eina_container_base* concat(eina_container_base const& other) const
+ {
+ return detail::concat(*this, other);
+ }
+ eina_container_base* slice(std::int64_t i, std::int64_t j) const
+ {
+ return detail::slice(*this, i, j);
+ }
+ v8::Local<v8::Value> set(v8::Isolate* isolate, std::size_t index, v8::Local<v8::Value> v)
+ {
+ return detail::set<T,W>(isolate, *this, index, v);
+ }
+ int push(v8::Isolate* isolate, v8::Local<v8::Value> v)
+ {
+ return detail::push<T,W>(isolate, *this, v);
+ }
+ v8::Local<v8::Value> pop(v8::Isolate* isolate)
+ {
+ return detail::pop<T,W,K>(isolate, *this);
+ }
+ js::container_type get_container_type() const { return list_container_type; }
+};
+
+template <typename T, typename K, typename W>
+struct range_eina_list : eina_container_common<typename efl::eina::range_list<W>, T, K>
+{
+ typedef eina_container_common<efl::eina::range_list<W>, T, K> base_type;
+ using base_type::base_type;
+ typedef typename base_type::container_type container_type;
+ typedef typename std::conditional
+ <std::is_base_of<efl::eo::concrete, W>::value
+ , efl::eina::eo_clone_allocator
+ , efl::eina::malloc_clone_allocator
+ >::type clone_allocator_type;
+
+ eina_container_base* concat(eina_container_base const& other) const
+ {
+ range_eina_list<T, K, W>const& rhs = static_cast<range_eina_list<T, K, W>const&>(other);
+ efl::eina::list<W, clone_allocator_type>
+ list(this->_container.begin(), this->_container.end());
+ list.insert(list.end(), rhs._container.begin(), rhs._container.end());
+ return new eina::js::eina_list<T, K, W>(list.release_native_handle());
+ }
+ eina_container_base* slice(std::int64_t i, std::int64_t j) const
+ {
+ efl::eina::list<W, clone_allocator_type>
+ list(std::next(this->_container.begin(), i), std::next(this->_container.begin(), j));
+ return new eina::js::eina_list<T, K, W>(list.release_native_handle());
+ }
+ v8::Local<v8::Value> set(v8::Isolate* isolate, std::size_t, v8::Local<v8::Value>)
+ {
+ return v8::Undefined(isolate);
+ }
+ int push(v8::Isolate*, v8::Local<v8::Value>)
+ {
+ return this->size();
+ }
+ v8::Local<v8::Value> pop(v8::Isolate* isolate)
+ {
+ return v8::Undefined(isolate);
+ }
+ js::container_type get_container_type() const { return list_container_type; }
+};
+
+// Problematic types.
+template <>
+struct eina_list<_Elm_Calendar_Mark*, js::nonclass_cls_name_getter, _Elm_Calendar_Mark>
+ : empty_container_base
+{ eina_list(Eina_List const*){} };
+template <>
+struct eina_list<Elm_Gen_Item*, js::nonclass_cls_name_getter, Elm_Gen_Item>
+ : empty_container_base
+{ eina_list(Eina_List const*){} };
+template <>
+struct eina_list<_Evas_Textblock_Rectangle*, js::nonclass_cls_name_getter, _Evas_Textblock_Rectangle>
+ : empty_container_base
+{ eina_list(Eina_List const*){} };
+template <>
+struct eina_list<_Elm_Map_Overlay*, js::nonclass_cls_name_getter, _Elm_Map_Overlay>
+ : empty_container_base
+{ eina_list(Eina_List const*){} };
+
+template <>
+struct range_eina_list<_Elm_Calendar_Mark*, js::nonclass_cls_name_getter, _Elm_Calendar_Mark>
+ : empty_container_base
+{ range_eina_list(Eina_List const*){} };
+template <>
+struct range_eina_list<Elm_Gen_Item*, js::nonclass_cls_name_getter, Elm_Gen_Item>
+ : empty_container_base
+{ range_eina_list(Eina_List const*){} };
+template <>
+struct range_eina_list<_Evas_Textblock_Rectangle*, js::nonclass_cls_name_getter, _Evas_Textblock_Rectangle>
+ : empty_container_base
+{ range_eina_list(Eina_List const*){} };
+template <>
+struct range_eina_list<_Elm_Map_Overlay*, js::nonclass_cls_name_getter, _Elm_Map_Overlay>
+ : empty_container_base
+{ range_eina_list(Eina_List const*){} };
+
+} } }
+
+#endif
diff --git a/src/bindings/eina_js/eina_js_log.cc b/src/bindings/eina_js/eina_js_log.cc
new file mode 100644
index 0000000000..415a827d1f
--- /dev/null
+++ b/src/bindings/eina_js/eina_js_log.cc
@@ -0,0 +1,742 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string>
+#include <map>
+#include <Eina_Js.hh>
+
+namespace efl { namespace eina { namespace js {
+
+v8::Local<v8::String> to_v8_string(v8::Isolate *isolate, const char *fmt,
+ va_list args)
+{
+ using v8::String;
+#if 0
+ /* TODO: unfortunately, the elegant and exception-safe version isn't
+ compiling (yet!) */
+ efl::eina::stringshare s(eina_stringshare_vprintf(fmt, args),
+ efl::eina::steal_stringshare_ref);
+ return compatibility_new<String>(isolate, s.data(), String::kNormalString,
+ s.size());
+#else
+ auto s = eina_stringshare_vprintf(fmt, args);
+ auto ret = compatibility_new<String>(isolate, s);
+ eina_stringshare_del(s);
+ return ret;
+#endif
+}
+
+static global_ref<v8::Value> js_eina_log_print_cb_data;
+static std::map<int, std::string> js_eina_log_color_map;
+
+static void js_eina_log_print_cb(const Eina_Log_Domain *d, Eina_Log_Level level,
+ const char *file, const char *fnc, int line,
+ const char *fmt, void */*data*/, va_list args)
+{
+ using v8::String;
+ using v8::Integer;
+ using v8::Isolate;
+
+ Isolate *const isolate = Isolate::GetCurrent();
+ constexpr unsigned argc = 7;
+
+ v8::Handle<v8::Value> argv[argc] = {
+ compatibility_new<String>(isolate, d->name ? d->name : ""),
+ compatibility_new<String>(isolate, d->color ? d->color : ""),
+ compatibility_new<Integer>(isolate, static_cast<int>(level)),
+ compatibility_new<String>(isolate, file),
+ compatibility_new<String>(isolate, fnc),
+ compatibility_new<Integer>(isolate, line),
+ to_v8_string(isolate, fmt, args)
+ };
+
+ auto o = js_eina_log_print_cb_data.handle();
+ v8::Function::Cast(*o)->Call(o->ToObject(), argc, argv);
+}
+
+static bool valid_level_conversion(int src, Eina_Log_Level &dst)
+{
+ if (src != EINA_LOG_LEVEL_CRITICAL && src != EINA_LOG_LEVEL_ERR
+ && src != EINA_LOG_LEVEL_WARN && src != EINA_LOG_LEVEL_INFO
+ && src != EINA_LOG_LEVEL_DBG)
+ return false;
+
+ dst = static_cast<Eina_Log_Level>(src);
+ return true;
+}
+
+EAPI
+void register_log_print(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Value;
+ using v8::String;
+ using v8::StackTrace;
+ using v8::FunctionTemplate;
+
+ auto print = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 3 || !args[0]->IsNumber() || !args[1]->IsNumber()
+ || !args[2]->IsString())
+ return compatibility_return();
+
+ Eina_Log_Level level;
+ if (!valid_level_conversion(args[1]->NumberValue(), level))
+ return compatibility_return();
+
+ auto frame = compatibility_current_stack_trace<>(args.GetIsolate(), 1,
+ StackTrace::kDetailed)->GetFrame(0);
+
+ eina_log_print(args[0]->NumberValue(), level,
+ *String::Utf8Value(frame->GetScriptNameOrSourceURL()),
+ *String::Utf8Value(frame->GetFunctionName()),
+ frame->GetLineNumber(), "%s",
+ *String::Utf8Value(args[2]));
+ return compatibility_return();
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, print)
+ ->GetFunction());
+}
+
+EAPI
+void register_log_domain_register(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Value;
+ using v8::Local;
+ using v8::String;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 2 || !args[0]->IsString() || !args[1]->IsString())
+ return compatibility_return();
+
+ // We duplicate the color string as eina takes a const char* but does take care of
+ // its lifetime, assuming a ever lasting string.
+ std::string color = *String::Utf8Value(args[1]);
+ int d = eina_log_domain_register(*String::Utf8Value(args[0]),
+ color.c_str());
+ js_eina_log_color_map[d] = color;
+
+ auto isolate = args.GetIsolate();
+ return compatibility_return(value_cast<Local<Value>>(d, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_log_domain_unregister(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Value;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsNumber())
+ return compatibility_return();
+
+ int domain = args[0]->NumberValue();
+ eina_log_domain_unregister(domain);
+ js_eina_log_color_map.erase(domain);
+ return compatibility_return();
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_log_domain_registered_level_get(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Value;
+ using v8::Local;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsNumber())
+ return compatibility_return();
+
+ int l = eina_log_domain_registered_level_get(args[0]->NumberValue());
+ auto isolate = args.GetIsolate();
+ return compatibility_return(value_cast<Local<Value>>(l, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_log_domain_registered_level_set(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Value;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 2 || !args[0]->IsNumber() || !args[1]->IsNumber())
+ return compatibility_return();
+
+ eina_log_domain_registered_level_set(args[0]->NumberValue(),
+ args[1]->NumberValue());
+ return compatibility_return();
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_log_print_cb_set(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Value;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsFunction())
+ return compatibility_return();
+
+ js_eina_log_print_cb_data
+ = global_ref<v8::Value>(args.GetIsolate(), args[0]);
+ eina_log_print_cb_set(js_eina_log_print_cb, NULL);
+ return compatibility_return();
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_log_level_set(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Value;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsNumber())
+ return compatibility_return();
+
+ eina_log_level_set(args[0]->NumberValue());
+ return compatibility_return();
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_log_level_get(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Value;
+ using v8::FunctionTemplate;
+ using v8::Integer;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 0)
+ return compatibility_return();
+
+ int l = eina_log_level_get();
+ auto ret = compatibility_new<Integer>(args.GetIsolate(), l);
+ return compatibility_return(ret, args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_log_level_check(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Value;
+ using v8::FunctionTemplate;
+ using v8::Boolean;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsNumber())
+ return compatibility_return();
+
+ bool b = eina_log_level_check(args[0]->NumberValue());
+ auto ret = compatibility_new<Boolean>(args.GetIsolate(), b);
+ return compatibility_return(ret, args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_log_color_disable_set(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Value;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsBoolean())
+ return compatibility_return();
+
+ eina_log_color_disable_set(args[0]->BooleanValue());
+ return compatibility_return();
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_log_color_disable_get(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Value;
+ using v8::Boolean;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 0)
+ return compatibility_return();
+
+ bool b = eina_log_color_disable_get();
+ auto ret = compatibility_new<Boolean>(args.GetIsolate(), b);
+ return compatibility_return(ret, args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_log_file_disable_set(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Value;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsBoolean())
+ return compatibility_return();
+
+ eina_log_file_disable_set(args[0]->BooleanValue());
+ return compatibility_return();
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_log_file_disable_get(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Value;
+ using v8::Boolean;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 0)
+ return compatibility_return();
+
+ bool b = eina_log_file_disable_get();
+ auto ret = compatibility_new<Boolean>(args.GetIsolate(), b);
+ return compatibility_return(ret, args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_log_function_disable_set(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Value;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsBoolean())
+ return compatibility_return();
+
+ eina_log_function_disable_set(args[0]->BooleanValue());
+ return compatibility_return();
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_log_function_disable_get(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Value;
+ using v8::Boolean;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 0)
+ return compatibility_return();
+
+ bool b = eina_log_function_disable_get();
+ auto ret = compatibility_new<Boolean>(args.GetIsolate(), b);
+ return compatibility_return(ret, args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_log_abort_on_critical_set(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Value;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsBoolean())
+ return compatibility_return();
+
+ eina_log_abort_on_critical_set(args[0]->BooleanValue());
+ return compatibility_return();
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_log_abort_on_critical_get(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Value;
+ using v8::Boolean;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 0)
+ return compatibility_return();
+
+ bool b = eina_log_abort_on_critical_get();
+ auto ret = compatibility_new<Boolean>(args.GetIsolate(), b);
+ return compatibility_return(ret, args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_log_abort_on_critical_level_set(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Value;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsNumber())
+ return compatibility_return();
+
+ eina_log_abort_on_critical_level_set(args[0]->NumberValue());
+ return compatibility_return();
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_log_abort_on_critical_level_get(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Value;
+ using v8::FunctionTemplate;
+ using v8::Integer;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 0)
+ return compatibility_return();
+
+ int l = eina_log_abort_on_critical_level_get();
+ auto ret = compatibility_new<Integer>(args.GetIsolate(), l);
+ return compatibility_return(ret, args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_log_domain_level_set(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Value;
+ using v8::FunctionTemplate;
+ using v8::String;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 2 || !args[0]->IsString() || !args[1]->IsNumber())
+ return compatibility_return();
+
+ eina_log_domain_level_set(*String::Utf8Value(args[0]),
+ args[1]->NumberValue());
+ return compatibility_return();
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_log_domain_level_get(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Value;
+ using v8::FunctionTemplate;
+ using v8::String;
+ using v8::Integer;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsString())
+ return compatibility_return();
+
+ int l = eina_log_domain_level_get(*String::Utf8Value(args[0]));
+ auto ret = compatibility_new<Integer>(args.GetIsolate(), l);
+ return compatibility_return(ret, args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_log_timing(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Value;
+ using v8::FunctionTemplate;
+ using v8::String;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 3 || !args[0]->IsNumber() || !args[1]->IsNumber()
+ || !args[2]->IsString()) {
+ return compatibility_return();
+ }
+
+ eina_log_timing(args[0]->NumberValue(),
+ static_cast<Eina_Log_State>(args[1]->NumberValue()),
+ *String::Utf8Value(args[2]));
+ return compatibility_return();
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+static void register_constant(v8::Isolate *isolate, v8::Handle<v8::Object> global, int value, const char* name)
+{
+ global->Set(compatibility_new<v8::String>(isolate, name), compatibility_new<v8::Integer>(isolate, value));
+}
+
+static void register_constant(v8::Isolate *isolate, v8::Handle<v8::Object> global, const char* value, const char* name)
+{
+ global->Set(compatibility_new<v8::String>(isolate, name), compatibility_new<v8::String>(isolate, value));
+}
+
+EAPI void register_log_constants(v8::Isolate *isolate, v8::Handle<v8::Object> global)
+{
+ register_constant(isolate, global, EINA_LOG_STATE_START, "LOG_STATE_START");
+ register_constant(isolate, global, EINA_LOG_STATE_START, "LOG_STATE_STOP");
+
+ register_constant(isolate, global, EINA_LOG_LEVEL_CRITICAL, "LOG_LEVEL_CRITICAL");
+ register_constant(isolate, global, EINA_LOG_LEVEL_ERR, "LOG_LEVEL_ERR");
+ register_constant(isolate, global, EINA_LOG_LEVEL_WARN, "LOG_LEVEL_WARN");
+ register_constant(isolate, global, EINA_LOG_LEVEL_INFO, "LOG_LEVEL_INFO");
+ register_constant(isolate, global, EINA_LOG_LEVEL_DBG, "LOG_LEVEL_DBG");
+ register_constant(isolate, global, EINA_LOG_LEVELS, "LOG_LEVELS");
+ register_constant(isolate, global, EINA_LOG_LEVEL_UNKNOWN, "LOG_LEVEL_UNKNOWN");
+
+ register_constant(isolate, global, EINA_LOG_DOMAIN_GLOBAL, "LOG_DOMAIN_GLOBAL");
+
+ register_constant(isolate, global, EINA_COLOR_LIGHTRED, "COLOR_LIGHTRED");
+ register_constant(isolate, global, EINA_COLOR_RED, "COLOR_RED");
+ register_constant(isolate, global, EINA_COLOR_LIGHTBLUE, "COLOR_LIGHTBLUE");
+ register_constant(isolate, global, EINA_COLOR_BLUE, "COLOR_BLUE");
+ register_constant(isolate, global, EINA_COLOR_GREEN, "COLOR_GREEN");
+ register_constant(isolate, global, EINA_COLOR_YELLOW, "COLOR_YELLOW");
+ register_constant(isolate, global, EINA_COLOR_ORANGE, "COLOR_ORANGE");
+ register_constant(isolate, global, EINA_COLOR_WHITE, "COLOR_WHITE");
+ register_constant(isolate, global, EINA_COLOR_LIGHTCYAN, "COLOR_LIGHTCYAN");
+ register_constant(isolate, global, EINA_COLOR_CYAN, "COLOR_CYAN");
+ register_constant(isolate, global, EINA_COLOR_RESET, "COLOR_RESET");
+ register_constant(isolate, global, EINA_COLOR_HIGH, "COLOR_HIGH");
+}
+
+
+#define REGISTER_LOG_HELPER(isolate, global, level, name) \
+{ \
+ using v8::String; \
+ using v8::FunctionTemplate;\
+ using v8::StackTrace;\
+\
+ auto wrapper = [](compatibility_callback_info_type args)\
+ -> compatibility_return_type {\
+ if (args.Length() != 1 || !args[0]->IsString()) {\
+ eina::js::compatibility_throw \
+ (args.GetIsolate(), v8::Exception::TypeError(\
+ eina::js::compatibility_new<v8::String>(args.GetIsolate(), "Message must be a string."))); \
+ return compatibility_return();\
+ } \
+\
+ auto frame = compatibility_current_stack_trace<>(args.GetIsolate(), 1,\
+ StackTrace::kDetailed)->GetFrame(0);\
+\
+ eina_log_print(EINA_LOG_DOMAIN_GLOBAL, level,\
+ *String::Utf8Value(frame->GetScriptNameOrSourceURL()),\
+ *String::Utf8Value(frame->GetFunctionName()),\
+ frame->GetLineNumber(), "%s",\
+ *String::Utf8Value(args[0]));\
+\
+ return compatibility_return();\
+ };\
+\
+ global->Set(compatibility_new<String>(isolate, name),\
+ compatibility_new<FunctionTemplate>(isolate, wrapper)->GetFunction());\
+}
+
+EAPI void register_log_helpers(v8::Isolate *isolate, v8::Handle<v8::Object> global)
+{
+ REGISTER_LOG_HELPER(isolate, global, EINA_LOG_LEVEL_CRITICAL, "logCritical");
+ REGISTER_LOG_HELPER(isolate, global, EINA_LOG_LEVEL_ERR, "logError");
+ REGISTER_LOG_HELPER(isolate, global, EINA_LOG_LEVEL_WARN, "logWarning");
+ REGISTER_LOG_HELPER(isolate, global, EINA_LOG_LEVEL_INFO, "logInfo");
+ REGISTER_LOG_HELPER(isolate, global, EINA_LOG_LEVEL_DBG, "logDebug");
+}
+
+} } } // namespace efl { namespace js {
+
+EAPI
+void eina_log_register(v8::Handle<v8::Object> exports, v8::Isolate* isolate)
+{
+ using efl::eina::js::compatibility_new;
+
+ efl::eina::js::register_log_domain_register(isolate, exports
+ , compatibility_new<v8::String>(isolate, "registerLogDomain"));
+ efl::eina::js::register_log_domain_unregister(isolate, exports
+ , compatibility_new<v8::String>(isolate, "unregisterLogDomain"));
+ efl::eina::js::register_log_domain_registered_level_set(isolate, exports
+ , compatibility_new<v8::String>(isolate, "setLogDomainRegisteredLevel"));
+ efl::eina::js::register_log_domain_registered_level_get(isolate, exports
+ , compatibility_new<v8::String>(isolate, "getLogDomainRegisteredLevel"));
+
+ efl::eina::js::register_log_print(isolate, exports
+ , compatibility_new<v8::String>(isolate, "logPrint"
+));
+ efl::eina::js::register_log_print_cb_set(isolate, exports
+ , compatibility_new<v8::String>(isolate, "setLogPrintCb"
+));
+
+ efl::eina::js::register_log_level_set(isolate, exports
+ , compatibility_new<v8::String>(isolate, "setLogLevel"
+));
+ efl::eina::js::register_log_level_get(isolate, exports
+ , compatibility_new<v8::String>(isolate, "getLogLevel"
+));
+ efl::eina::js::register_log_level_check(isolate, exports
+ , compatibility_new<v8::String>(isolate, "checkLogLevel"
+));
+
+ efl::eina::js::register_log_color_disable_set(isolate, exports
+ , compatibility_new<v8::String>(isolate, "setLogColorDisable"
+));
+ efl::eina::js::register_log_color_disable_get(isolate, exports
+ , compatibility_new<v8::String>(isolate, "getLogColorDisable"
+));
+
+ efl::eina::js::register_log_file_disable_set(isolate, exports
+ , compatibility_new<v8::String>(isolate, "setLogFileDisable"
+));
+ efl::eina::js::register_log_file_disable_get(isolate, exports
+ , compatibility_new<v8::String>(isolate, "getLogFileDisable"
+));
+
+ efl::eina::js::register_log_function_disable_set(isolate, exports
+ , compatibility_new<v8::String>(isolate, "setLogFunctionDisable"
+));
+ efl::eina::js::register_log_function_disable_get(isolate, exports
+ , compatibility_new<v8::String>(isolate, "getLogFunctionDisable"
+));
+
+ efl::eina::js::register_log_abort_on_critical_set(isolate, exports
+ , compatibility_new<v8::String>(isolate, "setLogAbortOnCritical"
+));
+ efl::eina::js::register_log_abort_on_critical_get(isolate, exports
+ , compatibility_new<v8::String>(isolate, "getLogAbortOnCritical"
+));
+ efl::eina::js::register_log_abort_on_critical_level_set(isolate, exports
+ , compatibility_new<v8::String>(isolate, "setLogAbortOnCriticalLevel"
+));
+ efl::eina::js::register_log_abort_on_critical_level_get(isolate, exports
+ , compatibility_new<v8::String>(isolate, "getLogAbortOnCriticalLevel"
+));
+
+ efl::eina::js::register_log_domain_level_set(isolate, exports
+ , compatibility_new<v8::String>(isolate, "setLogDomainLevel"
+));
+ efl::eina::js::register_log_domain_level_get(isolate, exports
+ , compatibility_new<v8::String>(isolate, "getLogDomainLevel"
+));
+
+ efl::eina::js::register_log_timing(isolate, exports
+ , compatibility_new<v8::String>(isolate, "logTiming"));
+
+ efl::eina::js::register_log_constants(isolate, exports);
+
+ efl::eina::js::register_log_helpers(isolate, exports);
+}
diff --git a/src/bindings/eina_js/eina_js_log.hh b/src/bindings/eina_js/eina_js_log.hh
new file mode 100644
index 0000000000..bed5a1bf9d
--- /dev/null
+++ b/src/bindings/eina_js/eina_js_log.hh
@@ -0,0 +1,133 @@
+#ifndef EINA_JS_LOG_HH
+#define EINA_JS_LOG_HH
+
+#include <type_traits>
+
+namespace efl { namespace eina { namespace js {
+
+using ::efl::eina::js::compatibility_new;
+using ::efl::eina::js::compatibility_return_type;
+using ::efl::eina::js::compatibility_callback_info_type;
+using ::efl::eina::js::compatibility_return;
+using ::efl::eina::js::compatibility_get_pointer_internal_field;
+using ::efl::eina::js::compatibility_set_pointer_internal_field;
+
+void register_log_level_critical(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_log_level_err(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_log_level_warn(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_log_level_info(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_log_level_dbg(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_log_domain_global(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_log_print(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_log_domain_register(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_log_domain_unregister(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_log_domain_registered_level_get(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_log_domain_registered_level_set(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_log_print_cb_set(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_log_level_set(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_log_level_get(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_log_level_check(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_log_color_disable_set(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_log_color_disable_get(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_log_file_disable_set(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_log_file_disable_get(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_log_function_disable_set(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_log_function_disable_get(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_log_abort_on_critical_set(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_log_abort_on_critical_get(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_log_abort_on_critical_level_set(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_log_abort_on_critical_level_get(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_log_domain_level_set(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_log_domain_level_get(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_log_state_start(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_log_state_stop(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_log_timing(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+} } } // namespace efl::js
+
+EAPI void eina_log_register(v8::Handle<v8::Object> exports, v8::Isolate* isolate);
+
+#endif /* EINA_JS_LOG_HH */
diff --git a/src/bindings/eina_js/eina_js_node.hh b/src/bindings/eina_js/eina_js_node.hh
new file mode 100644
index 0000000000..cfa4169d82
--- /dev/null
+++ b/src/bindings/eina_js/eina_js_node.hh
@@ -0,0 +1,14 @@
+
+#ifdef HAVE_NODE_NODE_H
+#include <node/node.h>
+#elif defined(HAVE_NODEJS_DEPS_NODE_NODE_H)
+#include <nodejs/deps/node/node.h>
+#elif defined(HAVE_NODEJS_DEPS_NODE_INCLUDE_NODE_H)
+#include <nodejs/deps/node/include/node.h>
+#elif defined(HAVE_NODEJS_SRC_NODE_H)
+#include <nodejs/src/node.h>
+#elif defined(HAVE_NODE_H)
+#include <node.h>
+#else
+#error We must have at least one node header to include
+#endif
diff --git a/src/bindings/eina_js/eina_js_value.cc b/src/bindings/eina_js/eina_js_value.cc
new file mode 100644
index 0000000000..5b5b822160
--- /dev/null
+++ b/src/bindings/eina_js/eina_js_value.cc
@@ -0,0 +1,132 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <Eina_Js.hh>
+
+namespace efl { namespace eina { namespace js {
+
+namespace {
+
+compatibility_return_type eina_value_set(compatibility_callback_info_type args)
+{
+ if (args.Length() != 1)
+ return compatibility_return();
+
+ void *ptr = js::compatibility_get_pointer_internal_field(args.Holder(), 0);
+ v8::Isolate *isolate = args.GetIsolate();
+ try {
+ *static_cast<value*>(ptr) = value_cast<value>(args[0]);
+ } catch(const std::bad_cast &e) {
+ v8::Local<v8::Object> je = compatibility_new<v8::Object>(isolate);
+ je->Set(compatibility_new<v8::String>(isolate, "code"),
+ compatibility_new<v8::String>(isolate, "std::bad_cast"));
+ return compatibility_throw(isolate, je);
+ } catch(const ::efl::eina::system_error &e) {
+ v8::Local<v8::Object> je = compatibility_new<v8::Object>(isolate);
+ je->Set(compatibility_new<v8::String>(isolate, "code"),
+ compatibility_new<v8::String>(isolate, "std::error_code"));
+ je->Set(compatibility_new<v8::String>(isolate, "category"),
+ compatibility_new<v8::String>(isolate, e.code().category().name()));
+ je->Set(compatibility_new<v8::String>(isolate, "value"),
+ compatibility_new<v8::Integer>(isolate, e.code().value()));
+ return compatibility_throw(isolate, je);
+ }
+ return compatibility_return();
+}
+
+compatibility_return_type eina_value_get(compatibility_callback_info_type args)
+{
+ void *ptr = compatibility_get_pointer_internal_field(args.Holder(), 0);
+ auto &value = *static_cast<eina::value*>(ptr);
+ return compatibility_return
+ (value_cast<v8::Local<v8::Value>>(value, args.GetIsolate()), args);
+}
+
+compatibility_return_type eina_value_constructor(compatibility_callback_info_type args)
+{
+ if (args.Length() != 1)
+ return compatibility_return();
+
+ v8::Isolate* isolate = args.GetIsolate();
+
+ try {
+ std::unique_ptr<value>
+ ptr(new value(value_cast<value>(args[0])));
+ compatibility_set_pointer_internal_field(args.This(), 0, ptr.get());
+ ptr.release();
+ } catch(const std::bad_cast &e) {
+ v8::Local<v8::Object> je = compatibility_new<v8::Object>(isolate);
+ je->Set(compatibility_new<v8::String>(isolate, "code"),
+ compatibility_new<v8::String>(isolate, "std::bad_cast"));
+ return compatibility_throw(isolate,je);
+ } catch(const ::efl::eina::system_error &e) {
+ v8::Local<v8::Object> je = compatibility_new<v8::Object>(isolate);
+ je->Set(compatibility_new<v8::String>(isolate, "code"),
+ compatibility_new<v8::String>(isolate, "std::error_code"));
+ je->Set(compatibility_new<v8::String>(isolate, "category"),
+ compatibility_new<v8::String>(isolate, e.code().category().name()));
+ je->Set(compatibility_new<v8::String>(isolate, "value"),
+ compatibility_new<v8::Integer>(isolate, e.code().value()));
+ return compatibility_throw(isolate, je);
+ }
+ // makeweak
+ // {
+ // typedef global_ref<v8::Object> persistent_t;
+ // typedef v8::WeakCallbackData<v8::Object, persistent_t> cb_type;
+
+ // auto on_gc = [](const cb_type &data) {
+ // typedef ::efl::eina::value value_type;
+ // typedef value_type *ptr_type;
+
+ // auto o = data.GetValue();
+ // delete static_cast<ptr_type>
+ // (compatibility_get_pointer_internal_field(o, 0));
+ // compatibility_set_pointer_internal_field<void*>(o, 0, nullptr);
+
+ // delete data.GetParameter();
+ // };
+
+ // auto persistent = new persistent_t(isolate, args.This());
+ // persistent->SetWeak<v8::Object>(persistent, on_gc);
+ // }
+}
+
+}
+
+EAPI
+void register_value(v8::Isolate *isolate, v8::Handle<v8::Object> 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;
+ using v8::FunctionCallbackInfo;
+
+ v8::Local<v8::FunctionTemplate> constructor = compatibility_new<v8::FunctionTemplate>(isolate, &eina_value_constructor);
+
+ v8::Local<v8::ObjectTemplate> instance = constructor->InstanceTemplate();
+ instance->SetInternalFieldCount(1);
+
+ auto prototype = constructor->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->GetFunction());
+}
+
+} } } // namespace efl { namespace js {
+
+EAPI
+void eina_value_register(v8::Handle<v8::Object> global, v8::Isolate* isolate)
+{
+ efl::eina::js::register_value(isolate, global
+ , efl::eina::js::compatibility_new<v8::String>(isolate, "value"));
+}
diff --git a/src/bindings/eina_js/eina_js_value.hh b/src/bindings/eina_js/eina_js_value.hh
new file mode 100644
index 0000000000..e6ebd30ca7
--- /dev/null
+++ b/src/bindings/eina_js/eina_js_value.hh
@@ -0,0 +1,142 @@
+#ifndef EINA_JS_VALUE_HH
+#define EINA_JS_VALUE_HH
+
+#include <type_traits>
+
+#include <eina_js_compatibility.hh>
+
+namespace efl { namespace eina { namespace js {
+
+namespace detail {
+
+template<class T, class = void>
+struct is_representable_as_v8_integer: std::false_type {};
+
+template<class T>
+struct is_representable_as_v8_integer
+<T,
+ typename std::enable_if<std::is_integral<T>::value
+ /* v8::Integer only stores 32-bit signed and unsigned
+ numbers. */
+ && (sizeof(T) <= sizeof(int32_t))>::type>
+: std::true_type {};
+
+template<class T>
+typename std::enable_if<is_representable_as_v8_integer<T>::value
+ && std::is_signed<T>::value,
+ v8::Local<v8::Value>>::type
+to_v8_number(const T &v, v8::Isolate *isolate)
+{
+ return compatibility_new<v8::Integer>(isolate, v);
+}
+
+template<class T>
+typename std::enable_if<is_representable_as_v8_integer<T>::value
+ && std::is_unsigned<T>::value,
+ v8::Local<v8::Value>>::type
+to_v8_number(const T &v, v8::Isolate *isolate)
+{
+ return compatibility_new<v8::Integer>(isolate, v);
+}
+
+template<class T>
+typename std::enable_if<(std::is_integral<T>::value
+ && !is_representable_as_v8_integer<T>::value)
+ || std::is_floating_point<T>::value,
+ v8::Local<v8::Value>>::type
+to_v8_number(const T &v, v8::Isolate *isolate)
+{
+ return compatibility_new<v8::Number>(isolate, v);
+}
+
+template<class T>
+typename std::enable_if<std::is_same<T, ::efl::eina::stringshare>::value
+ || std::is_same<T, std::string>::value,
+ v8::Local<v8::Value>>::type
+to_v8_string(const T &v, v8::Isolate *isolate)
+{
+ return compatibility_new<v8::String>(isolate, v.c_str());
+}
+
+} // namespace detail
+
+template<class T>
+typename std::enable_if<std::is_same<T, v8::Local<v8::Value>>::value, T>::type
+value_cast(const ::efl::eina::value &v, v8::Isolate *isolate)
+{
+ using detail::to_v8_number;
+ using detail::to_v8_string;
+ using ::efl::eina::get;
+
+ const auto &t = v.type_info();
+ if (t == EINA_VALUE_TYPE_UINT64) {
+ return to_v8_number(get<uint64_t>(v), isolate);
+ } else if (t == EINA_VALUE_TYPE_UCHAR) {
+ return to_v8_number(get<unsigned char>(v), isolate);
+ } else if (t == EINA_VALUE_TYPE_USHORT) {
+ return to_v8_number(get<unsigned short>(v), isolate);
+ } else if (t == EINA_VALUE_TYPE_UINT) {
+ return to_v8_number(get<unsigned int>(v), isolate);
+ } else if (t == EINA_VALUE_TYPE_ULONG) {
+ return to_v8_number(get<unsigned long>(v), isolate);
+ } else if (t == EINA_VALUE_TYPE_CHAR) {
+ return to_v8_number(get<char>(v), isolate);
+ } else if (t == EINA_VALUE_TYPE_SHORT) {
+ return to_v8_number(get<short>(v), isolate);
+ } else if (t == EINA_VALUE_TYPE_INT) {
+ return to_v8_number(get<int>(v), isolate);
+ } else if (t == EINA_VALUE_TYPE_LONG) {
+ return to_v8_number(get<long>(v), isolate);
+ } else if (t == EINA_VALUE_TYPE_FLOAT) {
+ return to_v8_number(get<float>(v), isolate);
+ } else if (t == EINA_VALUE_TYPE_DOUBLE) {
+ return to_v8_number(get<double>(v), isolate);
+ } else if (t == EINA_VALUE_TYPE_STRINGSHARE) {
+ return to_v8_string(get<::efl::eina::stringshare>(v), isolate);
+ } else if (t == EINA_VALUE_TYPE_STRING) {
+ return to_v8_string(get<std::string>(v), isolate);
+ }
+
+ throw std::bad_cast{};
+}
+
+template<class T>
+typename std::enable_if<std::is_same<T, ::efl::eina::value>::value, T>::type
+value_cast(const v8::Handle<v8::Value> &v)
+{
+ using ::efl::eina::value;
+
+ if (v->IsBoolean()) {
+ return value(int{v->BooleanValue()});
+ } else if (v->IsInt32()) {
+ return value(v->Int32Value());
+ } else if (v->IsUint32()) {
+ return value(v->Uint32Value());
+ } else if (v->IsNumber()) {
+ return value(v->NumberValue());
+ } else if (v->IsString()) {
+ v8::String::Utf8Value data(v);
+ return value(std::string(*data, data.length()));
+ }
+
+ throw std::bad_cast{};
+}
+
+/*
+ # JS binding
+
+ - There is the `value()` constructor, which accepts a primitive value as input
+ argument and might throw.
+ - The returned object has a `get()` method, which can be used to get the
+ wrapped value as a JavaScript value.
+ - The returned object has a `set()` method, which can be used to change the
+ wrapped value.
+ */
+void register_value(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+} } } // namespace efl::js
+
+EAPI void eina_value_register(v8::Handle<v8::Object> global, v8::Isolate* isolate);
+
+#endif /* EINA_JS_VALUE_HH */
diff --git a/src/bindings/eio_js/Eio_Js.hh b/src/bindings/eio_js/Eio_Js.hh
new file mode 100644
index 0000000000..e379229870
--- /dev/null
+++ b/src/bindings/eio_js/Eio_Js.hh
@@ -0,0 +1,44 @@
+#ifndef EIO_JS_INIT_HH
+#define EIO_JS_INIT_HH
+
+#include <Eio.h>
+#include <Ecore.h>
+
+#include <Eina.hh>
+
+#include <Eina_Js.hh>
+
+#ifdef EAPI
+# undef EAPI
+#endif
+
+#ifdef _WIN32
+# ifdef EFL_EIO_JS_BUILD
+# ifdef DLL_EXPORT
+# define EAPI __declspec(dllexport)
+# else
+# define EAPI
+# endif /* ! DLL_EXPORT */
+# else
+# define EAPI __declspec(dllimport)
+# endif /* ! EFL_EIO_JS_BUILD */
+#else
+# ifdef __GNUC__
+# if __GNUC__ >= 4
+# define EAPI __attribute__ ((visibility("default")))
+# else
+# define EAPI
+# endif
+# else
+# define EAPI
+# endif
+#endif /* ! _WIN32 */
+
+namespace efl { namespace eio { namespace js {
+
+EAPI
+void register_eio(v8::Isolate* isolate, v8::Handle<v8::Object> exports);
+
+} } } // namespace efl { namespace eio { namespace js {
+
+#endif /* EIO_JS_INIT_HH */
diff --git a/src/bindings/eio_js/eio_js.cc b/src/bindings/eio_js/eio_js.cc
new file mode 100644
index 0000000000..8441247e63
--- /dev/null
+++ b/src/bindings/eio_js/eio_js.cc
@@ -0,0 +1,1756 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <Eio_Js.hh>
+
+namespace efl { namespace eio { namespace js {
+
+using ::efl::eina::js::compatibility_new;
+using ::efl::eina::js::compatibility_return_type;
+using ::efl::eina::js::compatibility_callback_info_type;
+using ::efl::eina::js::compatibility_return;
+using ::efl::eina::js::compatibility_get_pointer_internal_field;
+using ::efl::eina::js::compatibility_set_pointer_internal_field;
+
+namespace {
+
+Eio_File* extract_eio_file(v8::Local<v8::Object> object)
+{
+ return compatibility_get_pointer_internal_field<Eio_File*>(object, 0);
+}
+
+v8::Local<v8::Object> wrap_eio_file(Eio_File *file, v8::Isolate *isolate)
+{
+ using v8::String;
+ using v8::Boolean;
+ using v8::ObjectTemplate;
+ using v8::FunctionTemplate;
+
+ auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
+ obj_tpl->SetInternalFieldCount(1);
+ auto ret = obj_tpl->NewInstance();
+
+ auto cancel = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = info.GetIsolate();
+
+ auto ret = eio_file_cancel(extract_eio_file(info.This()));
+ return compatibility_return(compatibility_new<Boolean>(isolate, ret),
+ info);
+ };
+
+ auto check = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = info.GetIsolate();
+
+ auto ret = eio_file_check(extract_eio_file(info.This()));
+ return compatibility_return(compatibility_new<Boolean>(isolate, ret),
+ info);
+ };
+
+ ret->Set(compatibility_new<String>(isolate, "cancel"),
+ compatibility_new<FunctionTemplate>(isolate, cancel)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "check"),
+ compatibility_new<FunctionTemplate>(isolate, check)
+ ->GetFunction());
+
+ compatibility_set_pointer_internal_field(ret, 0, file);
+
+ return ret;
+}
+
+static Eina_File* extract_eina_file(v8::Local<v8::Object> object)
+{
+ return compatibility_get_pointer_internal_field<Eina_File*>(object, 0);
+}
+
+static v8::Local<v8::Object> wrap_eina_file(Eina_File *file,
+ v8::Isolate *isolate)
+{
+ using v8::String;
+ using v8::ObjectTemplate;
+ using v8::Object;
+ using v8::FunctionTemplate;
+ using v8::WeakCallbackData;
+
+ auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
+ obj_tpl->SetInternalFieldCount(1);
+ auto ret = obj_tpl->NewInstance();
+
+ /* TODO:
+
+ Eina_File only handle files open in read-only mode. Althought there
+ aren't many useful functions exposed to a JavaScript binding, the exposed
+ `file->fd` can be used to expose a few read operations found in
+ `<cstdio>`.
+ */
+
+ auto close = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto o = info.This();
+
+ auto file = extract_eina_file(o);
+ if (!file)
+ return compatibility_return();
+
+ eina_file_close(file);
+ compatibility_set_pointer_internal_field<void*>(o, 0, nullptr);
+ return compatibility_return();
+ };
+
+ ret->Set(compatibility_new<String>(isolate, "close"),
+ compatibility_new<FunctionTemplate>(isolate, close)
+ ->GetFunction());
+
+ compatibility_set_pointer_internal_field(ret, 0, file);
+
+ auto on_gc = [ret]() {
+ auto file = extract_eina_file(ret);
+
+ if (file) {
+ eina_file_close(file);
+ compatibility_set_pointer_internal_field<void*>(ret, 0, nullptr);
+ }
+ };
+
+ efl::eina::js::make_weak(isolate, ret, on_gc);
+
+ return ret;
+}
+
+static Eio_Monitor* extract_monitor(v8::Local<v8::Object> object)
+{
+ return compatibility_get_pointer_internal_field<Eio_Monitor*>(object, 0);
+}
+
+static v8::Local<v8::Object> wrap_monitor(Eio_Monitor *monitor,
+ v8::Isolate *isolate)
+{
+ using v8::String;
+ using v8::ObjectTemplate;
+ using v8::FunctionTemplate;
+
+ auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
+ obj_tpl->SetInternalFieldCount(1);
+ auto ret = obj_tpl->NewInstance();
+
+ auto del = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ eio_monitor_del(extract_monitor(info.This()));
+ return compatibility_return();
+ };
+
+ auto path_get = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto ret = eio_monitor_path_get(extract_monitor(info.This()));
+ return compatibility_return(compatibility_new<String>(info.GetIsolate(),
+ ret),
+ info);
+ };
+
+ ret->Set(compatibility_new<String>(isolate, "del"),
+ compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "path_get"),
+ compatibility_new<FunctionTemplate>(isolate, path_get)
+ ->GetFunction());
+
+ compatibility_set_pointer_internal_field(ret, 0, monitor);
+
+ return ret;
+}
+
+static Ecore_Event_Handler *extract_event_handler(v8::Local<v8::Object> object)
+{
+ return compatibility_get_pointer_internal_field<Ecore_Event_Handler*>
+ (object, 0);
+}
+
+static v8::Local<v8::Object> wrap_event_handler(Ecore_Event_Handler *handler,
+ v8::Isolate *isolate)
+{
+ using v8::String;
+ using v8::ObjectTemplate;
+ using v8::FunctionTemplate;
+ using v8::Value;
+
+ auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
+ obj_tpl->SetInternalFieldCount(1);
+ auto ret = obj_tpl->NewInstance();
+
+ auto del = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto p = ecore_event_handler_del(extract_event_handler(info.This()));
+
+ auto per = static_cast<efl::eina::js::global_ref<Value>*>(p);
+ per->dispose();
+ delete per;
+ return compatibility_return();
+ };
+
+ ret->Set(compatibility_new<String>(isolate, "del"),
+ compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
+
+ compatibility_set_pointer_internal_field(ret, 0, handler);
+
+ return ret;
+}
+
+static
+v8::Local<v8::Object> wrap_eina_file_direct_info(const Eina_File_Direct_Info*
+ info,
+ v8::Isolate *isolate)
+{
+ using v8::Object;
+ using v8::String;
+ using v8::Integer;
+
+ auto wrapped_info = compatibility_new<Object>(isolate);
+
+ wrapped_info->Set(compatibility_new<String>(isolate, "path_length"),
+ compatibility_new<Integer>(isolate, info->path_length));
+ wrapped_info->Set(compatibility_new<String>(isolate, "mame_length"),
+ compatibility_new<Integer>(isolate, info->name_length));
+ wrapped_info->Set(compatibility_new<String>(isolate, "name_start"),
+ compatibility_new<Integer>(isolate, info->name_start));
+ wrapped_info->Set(compatibility_new<String>(isolate, "type"),
+ compatibility_new<Integer>(isolate, info->type));
+ wrapped_info->Set(compatibility_new<String>(isolate, "path"),
+ compatibility_new<String>(isolate, info->path));
+
+ return wrapped_info;
+}
+
+EAPI
+void register_init(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::FunctionTemplate;
+
+ auto init = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = eio_init();
+ return compatibility_return(compatibility_new<Integer>(isolate, ret),
+ args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, init)
+ ->GetFunction());
+}
+
+EAPI
+void register_shutdown(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::FunctionTemplate;
+
+ auto shutdown = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = eio_shutdown();
+ return compatibility_return(compatibility_new<Integer>(isolate, ret),
+ args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, shutdown)
+ ->GetFunction());
+}
+
+EAPI
+void register_op_file_copy(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name, compatibility_new<Integer>(isolate, EIO_FILE_COPY));
+}
+
+EAPI
+void register_op_file_move(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name, compatibility_new<Integer>(isolate, EIO_FILE_MOVE));
+}
+
+EAPI
+void register_op_dir_copy(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name, compatibility_new<Integer>(isolate, EIO_DIR_COPY));
+}
+
+EAPI
+void register_op_dir_move(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name, compatibility_new<Integer>(isolate, EIO_DIR_MOVE));
+}
+
+EAPI
+void register_op_unlink(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name, compatibility_new<Integer>(isolate, EIO_UNLINK));
+}
+
+EAPI
+void register_op_file_getpwnam(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name, compatibility_new<Integer>(isolate, EIO_FILE_GETPWNAM));
+}
+
+EAPI
+void register_op_file_getgrnam(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name, compatibility_new<Integer>(isolate, EIO_FILE_GETGRNAM));
+}
+
+EAPI
+void register_file_open(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::Value;
+ using v8::String;
+ using v8::FunctionTemplate;
+ using v8::Function;
+ using v8::Handle;
+ using std::unique_ptr;
+
+ typedef efl::eina::js::global_ref<Value> persistent_t;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 4 || !args[0]->IsString() || !args[1]->IsBoolean()
+ || !args[2]->IsFunction() || !args[3]->IsFunction())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+
+ auto cb_data = unique_ptr<persistent_t[]>(new persistent_t[2]);
+ cb_data[0] = persistent_t(isolate, args[2]);
+ cb_data[1] = persistent_t(isolate, args[3]);
+
+ auto open_cb = [](void *data, Eio_File *handler, Eina_File *file) {
+ auto persistent = reinterpret_cast<persistent_t*>(data);
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args[2] = {
+ wrap_eio_file(handler, isolate),
+ wrap_eina_file(file, isolate)
+ };
+
+ Function::Cast(*o)->Call(o->ToObject(), 2, args);
+
+ delete[] persistent;
+ };
+ auto error_cb = [](void *data, Eio_File *handler, int error) {
+ auto persistent = reinterpret_cast<persistent_t*>(data) + 1;
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args[2] = {
+ wrap_eio_file(handler, isolate),
+ compatibility_new<Integer>(isolate, error)
+ };
+
+ Function::Cast(*o)->Call(o->ToObject(), 2, args);
+
+ delete[] (persistent - 1);
+ };
+
+ auto ret = eio_file_open(*String::Utf8Value(args[0]),
+ args[1]->BooleanValue(), open_cb, error_cb,
+ cb_data.release());
+
+ return compatibility_return(wrap_eio_file(ret, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_monitor_file_created(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate, EIO_MONITOR_FILE_CREATED));
+}
+
+EAPI
+void register_monitor_file_deleted(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate, EIO_MONITOR_FILE_DELETED));
+}
+
+EAPI
+void register_monitor_file_modified(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate, EIO_MONITOR_FILE_MODIFIED));
+}
+
+EAPI
+void register_monitor_file_closed(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate, EIO_MONITOR_FILE_CLOSED));
+}
+
+EAPI
+void register_monitor_directory_created(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate,
+ EIO_MONITOR_DIRECTORY_CREATED));
+}
+
+EAPI
+void register_monitor_directory_deleted(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate,
+ EIO_MONITOR_DIRECTORY_DELETED));
+}
+
+EAPI
+void register_monitor_directory_modified(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate,
+ EIO_MONITOR_DIRECTORY_MODIFIED));
+}
+
+EAPI
+void register_monitor_directory_closed(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate,
+ EIO_MONITOR_DIRECTORY_CLOSED));
+}
+
+EAPI
+void register_monitor_self_rename(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate, EIO_MONITOR_SELF_RENAME));
+}
+
+EAPI
+void register_monitor_self_deleted(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate, EIO_MONITOR_SELF_DELETED));
+}
+
+EAPI
+void register_monitor_error(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate, EIO_MONITOR_ERROR));
+}
+
+EAPI
+void register_monitor_add(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::String;
+ using v8::Integer;
+ using v8::FunctionTemplate;
+ using v8::Handle;
+ using v8::Value;
+ using v8::Function;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsString())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = eio_monitor_add(*String::Utf8Value(args[0]));
+ return compatibility_return(wrap_monitor(ret, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+template<int &wanted_event>
+static
+void register_monitor_event_handler_add(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::String;
+ using v8::Value;
+ using v8::Object;
+ using v8::Function;
+ using v8::Handle;
+ using v8::Local;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsFunction())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+
+ auto p = new efl::eina::js::global_ref<Value>(isolate, args[0]);
+
+ auto cb = [](void *d, int type, void *event) -> Eina_Bool {
+ auto p = reinterpret_cast<efl::eina::js::global_ref<Value>*>(d);
+ auto e = reinterpret_cast<Eio_Monitor_Event*>(event);
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ auto o = p->handle();
+ auto wrapped_event = compatibility_new<Object>(isolate);
+
+ wrapped_event->Set(compatibility_new<String>(isolate, "monitor"),
+ wrap_monitor(e->monitor, isolate));
+ wrapped_event->Set(compatibility_new<String>(isolate, "filename"),
+ compatibility_new<String>(isolate, e->filename));
+
+ Handle<Value> args[2]{
+ compatibility_new<Integer>(isolate, type),
+ wrapped_event
+ };
+
+ auto ret = Function::Cast(*o)->Call(o->ToObject(), 2, args);
+ auto bret = ret->IsBoolean() && ret->BooleanValue();
+
+ return bret ? EINA_TRUE : EINA_FALSE;
+ };
+
+ auto ret = ecore_event_handler_add(wanted_event, cb, p);
+ return compatibility_return(wrap_event_handler(ret, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void
+register_event_monitor_file_created_handler_add(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ return register_monitor_event_handler_add<EIO_MONITOR_FILE_CREATED>
+ (isolate, global, name);
+}
+
+EAPI
+void
+register_event_monitor_file_deleted_handler_add(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ return register_monitor_event_handler_add<EIO_MONITOR_FILE_DELETED>
+ (isolate, global, name);
+}
+
+EAPI
+void
+register_event_monitor_file_modified_handler_add(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ return register_monitor_event_handler_add<EIO_MONITOR_FILE_MODIFIED>
+ (isolate, global, name);
+}
+
+EAPI
+void
+register_event_monitor_file_closed_handler_add(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ return register_monitor_event_handler_add<EIO_MONITOR_FILE_CLOSED>
+ (isolate, global, name);
+}
+
+EAPI
+void register_event_monitor_directory_created_handler_add
+(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ return register_monitor_event_handler_add<EIO_MONITOR_DIRECTORY_CREATED>
+ (isolate, global, name);
+}
+
+EAPI
+void register_event_monitor_directory_deleted_handler_add
+(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ return register_monitor_event_handler_add<EIO_MONITOR_DIRECTORY_DELETED>
+ (isolate, global, name);
+}
+
+EAPI
+void register_event_monitor_directory_modified_handler_add
+(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ return register_monitor_event_handler_add<EIO_MONITOR_DIRECTORY_MODIFIED>
+ (isolate, global, name);
+}
+
+EAPI
+void register_event_monitor_directory_closed_handler_add
+(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ return register_monitor_event_handler_add<EIO_MONITOR_DIRECTORY_CLOSED>
+ (isolate, global, name);
+}
+
+EAPI
+void
+register_event_monitor_self_rename_handler_add(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ return register_monitor_event_handler_add<EIO_MONITOR_SELF_RENAME>
+ (isolate, global, name);
+}
+
+EAPI
+void
+register_event_monitor_self_deleted_handler_add(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ return register_monitor_event_handler_add<EIO_MONITOR_SELF_DELETED>
+ (isolate, global, name);
+}
+
+EAPI
+void
+register_event_monitor_error_handler_add(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ return register_monitor_event_handler_add<EIO_MONITOR_ERROR>
+ (isolate, global, name);
+}
+
+EAPI
+void register_file_ls(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::String;
+ using v8::Integer;
+ using v8::FunctionTemplate;
+ using v8::Handle;
+ using v8::Value;
+ using v8::Function;
+ using std::unique_ptr;
+
+ typedef efl::eina::js::global_ref<Value> persistent_t;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 5 || !args[0]->IsString() || !args[1]->IsFunction()
+ || !args[2]->IsFunction() || !args[3]->IsFunction()
+ || !args[4]->IsFunction()) {
+ return compatibility_return();
+ }
+
+ auto isolate = args.GetIsolate();
+
+ auto cb_data = unique_ptr<persistent_t[]>(new persistent_t[4]);
+ cb_data[0] = persistent_t(isolate, args[1]);
+ cb_data[1] = persistent_t(isolate, args[2]);
+ cb_data[2] = persistent_t(isolate, args[3]);
+ cb_data[3] = persistent_t(isolate, args[4]);
+
+ auto filter_cb = [](void *data, Eio_File *handler, const char *file)
+ -> Eina_Bool {
+ auto persistent = reinterpret_cast<persistent_t*>(data);
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args[2] = {
+ wrap_eio_file(handler, isolate),
+ compatibility_new<String>(isolate, file)
+ };
+
+ auto ret = Function::Cast(*o)->Call(o->ToObject(), 2, args);
+ auto bret = ret->IsBoolean() && ret->BooleanValue();
+ return bret ? EINA_TRUE : EINA_FALSE;
+ };
+ auto main_cb = [](void *data, Eio_File *handler, const char *file) {
+ auto persistent = reinterpret_cast<persistent_t*>(data) + 1;
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args[2] = {
+ wrap_eio_file(handler, isolate),
+ compatibility_new<String>(isolate, file)
+ };
+
+ Function::Cast(*o)->Call(o->ToObject(), 2, args);
+ };
+ auto done_cb = [](void *data, Eio_File *handler) {
+ auto persistent = reinterpret_cast<persistent_t*>(data) + 2;
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args = wrap_eio_file(handler, isolate);
+
+ Function::Cast(*o)->Call(o->ToObject(), 1, &args);
+
+ delete[] (persistent - 2);
+ };
+ auto error_cb = [](void *data, Eio_File *handler, int error) {
+ auto persistent = reinterpret_cast<persistent_t*>(data) + 3;
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args[2] = {
+ wrap_eio_file(handler, isolate),
+ compatibility_new<Integer>(isolate, error)
+ };
+
+ Function::Cast(*o)->Call(o->ToObject(), 2, args);
+
+ delete[] (persistent - 3);
+ };
+
+ auto ret = eio_file_ls(*String::Utf8Value(args[0]), filter_cb, main_cb,
+ done_cb, error_cb, cb_data.release());
+ return compatibility_return(wrap_eio_file(ret, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_file_chmod(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::String;
+ using v8::Integer;
+ using v8::FunctionTemplate;
+ using v8::Handle;
+ using v8::Value;
+ using v8::Function;
+ using std::unique_ptr;
+
+ typedef efl::eina::js::global_ref<Value> persistent_t;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 4 || !args[0]->IsString() || !args[1]->IsNumber()
+ || !args[2]->IsFunction() || !args[3]->IsFunction()) {
+ return compatibility_return();
+ }
+
+ auto isolate = args.GetIsolate();
+
+ auto cb_data = unique_ptr<persistent_t[]>(new persistent_t[2]);
+ cb_data[0] = persistent_t(isolate, args[2]);
+ cb_data[1] = persistent_t(isolate, args[3]);
+ auto done_cb = [](void *data, Eio_File *handler) {
+ auto persistent = reinterpret_cast<persistent_t*>(data);
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args = wrap_eio_file(handler, isolate);
+
+ Function::Cast(*o)->Call(o->ToObject(), 1, &args);
+
+ delete[] persistent;
+ };
+ auto error_cb = [](void *data, Eio_File *handler, int error) {
+ auto persistent = reinterpret_cast<persistent_t*>(data) + 1;
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args[2] = {
+ wrap_eio_file(handler, isolate),
+ compatibility_new<Integer>(isolate, error)
+ };
+
+ Function::Cast(*o)->Call(o->ToObject(), 2, args);
+
+ delete[] (persistent - 1);
+ };
+
+ auto ret = eio_file_chmod(*String::Utf8Value(args[0]),
+ args[1]->IntegerValue(), done_cb, error_cb,
+ cb_data.release());
+ return compatibility_return(wrap_eio_file(ret, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_file_chown(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::String;
+ using v8::Integer;
+ using v8::FunctionTemplate;
+ using v8::Handle;
+ using v8::Value;
+ using v8::Function;
+ using std::unique_ptr;
+
+ typedef efl::eina::js::global_ref<Value> persistent_t;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 5 || !args[0]->IsString() || !args[1]->IsString()
+ || !args[2]->IsString() || !args[3]->IsFunction()
+ || !args[4]->IsFunction()) {
+ return compatibility_return();
+ }
+
+ auto isolate = args.GetIsolate();
+
+ auto cb_data = unique_ptr<persistent_t[]>(new persistent_t[2]);
+ cb_data[0] = persistent_t(isolate, args[3]);
+ cb_data[1] = persistent_t(isolate, args[4]);
+ auto done_cb = [](void *data, Eio_File *handler) {
+ auto persistent = reinterpret_cast<persistent_t*>(data);
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args = wrap_eio_file(handler, isolate);
+
+ Function::Cast(*o)->Call(o->ToObject(), 1, &args);
+
+ delete[] persistent;
+ };
+ auto error_cb = [](void *data, Eio_File *handler, int error) {
+ auto persistent = reinterpret_cast<persistent_t*>(data) + 1;
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args[2] = {
+ wrap_eio_file(handler, isolate),
+ compatibility_new<Integer>(isolate, error)
+ };
+
+ Function::Cast(*o)->Call(o->ToObject(), 2, args);
+
+ delete[] (persistent - 1);
+ };
+
+ auto ret = eio_file_chown(*String::Utf8Value(args[0]),
+ *String::Utf8Value(args[1]),
+ *String::Utf8Value(args[2]), done_cb,
+ error_cb,
+ cb_data.release());
+ return compatibility_return(wrap_eio_file(ret, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_file_unlink(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::String;
+ using v8::Integer;
+ using v8::FunctionTemplate;
+ using v8::Handle;
+ using v8::Value;
+ using v8::Function;
+ using std::unique_ptr;
+
+ typedef efl::eina::js::global_ref<Value> persistent_t;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 3 || !args[0]->IsString() || !args[1]->IsFunction()
+ || !args[2]->IsFunction()) {
+ return compatibility_return();
+ }
+
+ auto isolate = args.GetIsolate();
+
+ auto cb_data = unique_ptr<persistent_t[]>(new persistent_t[2]);
+ cb_data[0] = persistent_t(isolate, args[1]);
+ cb_data[1] = persistent_t(isolate, args[2]);
+ auto done_cb = [](void *data, Eio_File *handler) {
+ auto persistent = reinterpret_cast<persistent_t*>(data);
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args = wrap_eio_file(handler, isolate);
+
+ Function::Cast(*o)->Call(o->ToObject(), 1, &args);
+
+ delete[] persistent;
+ };
+ auto error_cb = [](void *data, Eio_File *handler, int error) {
+ auto persistent = reinterpret_cast<persistent_t*>(data) + 1;
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args[2] = {
+ wrap_eio_file(handler, isolate),
+ compatibility_new<Integer>(isolate, error)
+ };
+
+ Function::Cast(*o)->Call(o->ToObject(), 2, args);
+
+ delete[] (persistent - 1);
+ };
+
+ auto ret = eio_file_unlink(*String::Utf8Value(args[0]), done_cb,
+ error_cb, cb_data.release());
+ return compatibility_return(wrap_eio_file(ret, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_file_mkdir(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::String;
+ using v8::Integer;
+ using v8::FunctionTemplate;
+ using v8::Handle;
+ using v8::Value;
+ using v8::Function;
+ using std::unique_ptr;
+
+ typedef efl::eina::js::global_ref<Value> persistent_t;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 4 || !args[0]->IsString() || !args[1]->IsNumber()
+ || !args[2]->IsString() || !args[3]->IsFunction()) {
+ return compatibility_return();
+ }
+
+ auto isolate = args.GetIsolate();
+
+ auto cb_data = unique_ptr<persistent_t[]>(new persistent_t[2]);
+ cb_data[0] = persistent_t(isolate, args[2]);
+ cb_data[1] = persistent_t(isolate, args[3]);
+ auto done_cb = [](void *data, Eio_File *handler) {
+ auto persistent = reinterpret_cast<persistent_t*>(data);
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args = wrap_eio_file(handler, isolate);
+
+ Function::Cast(*o)->Call(o->ToObject(), 1, &args);
+
+ delete[] persistent;
+ };
+ auto error_cb = [](void *data, Eio_File *handler, int error) {
+ auto persistent = reinterpret_cast<persistent_t*>(data) + 1;
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args[2] = {
+ wrap_eio_file(handler, isolate),
+ compatibility_new<Integer>(isolate, error)
+ };
+
+ Function::Cast(*o)->Call(o->ToObject(), 2, args);
+
+ delete[] (persistent - 1);
+ };
+
+ auto ret = eio_file_mkdir(*String::Utf8Value(args[0]),
+ args[1]->IntegerValue(), done_cb, error_cb,
+ cb_data.release());
+ return compatibility_return(wrap_eio_file(ret, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_file_move(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::String;
+ using v8::Integer;
+ using v8::Number;
+ using v8::Object;
+ using v8::FunctionTemplate;
+ using v8::Handle;
+ using v8::Value;
+ using v8::Function;
+ using std::unique_ptr;
+
+ typedef efl::eina::js::global_ref<Value> persistent_t;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 5 || !args[0]->IsString() || !args[1]->IsString()
+ || !args[2]->IsFunction() || !args[3]->IsFunction()
+ || !args[4]->IsFunction()) {
+ return compatibility_return();
+ }
+
+ auto isolate = args.GetIsolate();
+
+ auto cb_data = unique_ptr<persistent_t[]>(new persistent_t[3]);
+ cb_data[0] = persistent_t(isolate, args[2]);
+ cb_data[1] = persistent_t(isolate, args[3]);
+ cb_data[2] = persistent_t(isolate, args[4]);
+ auto progress_cb = [](void *data, Eio_File *handler,
+ const Eio_Progress *info) {
+ auto persistent = reinterpret_cast<persistent_t*>(data);
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ auto wrapped_info = compatibility_new<Object>(isolate);
+
+ wrapped_info->Set(compatibility_new<String>(isolate, "op"),
+ compatibility_new<Integer>(isolate, info->op));
+ wrapped_info->Set(compatibility_new<String>(isolate, "current"),
+ compatibility_new<Integer>(isolate,
+ info->current));
+ wrapped_info->Set(compatibility_new<String>(isolate, "max"),
+ compatibility_new<Integer>(isolate, info->max));
+ wrapped_info->Set(compatibility_new<String>(isolate, "percent"),
+ compatibility_new<Number>(isolate,
+ info->percent));
+ wrapped_info->Set(compatibility_new<String>(isolate, "source"),
+ compatibility_new<String>(isolate, info->source));
+ wrapped_info->Set(compatibility_new<String>(isolate, "dest"),
+ compatibility_new<String>(isolate, info->dest));
+
+ Handle<Value> args[2] = {
+ wrap_eio_file(handler, isolate),
+ wrapped_info
+ };
+
+ Function::Cast(*o)->Call(o->ToObject(), 2, args);
+ };
+ auto done_cb = [](void *data, Eio_File *handler) {
+ auto persistent = reinterpret_cast<persistent_t*>(data) + 1;
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args = wrap_eio_file(handler, isolate);
+
+ Function::Cast(*o)->Call(o->ToObject(), 1, &args);
+
+ delete[] (persistent - 1);
+ };
+ auto error_cb = [](void *data, Eio_File *handler, int error) {
+ auto persistent = reinterpret_cast<persistent_t*>(data) + 2;
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args[2] = {
+ wrap_eio_file(handler, isolate),
+ compatibility_new<Integer>(isolate, error)
+ };
+
+ Function::Cast(*o)->Call(o->ToObject(), 2, args);
+
+ delete[] (persistent - 2);
+ };
+
+ auto ret = eio_file_move(*String::Utf8Value(args[0]),
+ *String::Utf8Value(args[1]),
+ progress_cb, done_cb, error_cb,
+ cb_data.release());
+ return compatibility_return(wrap_eio_file(ret, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_file_copy(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::String;
+ using v8::Integer;
+ using v8::Number;
+ using v8::Object;
+ using v8::FunctionTemplate;
+ using v8::Handle;
+ using v8::Value;
+ using v8::Function;
+ using std::unique_ptr;
+
+ typedef efl::eina::js::global_ref<Value> persistent_t;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 5 || !args[0]->IsString() || !args[1]->IsString()
+ || !args[2]->IsFunction() || !args[3]->IsFunction()
+ || !args[4]->IsFunction()) {
+ return compatibility_return();
+ }
+
+ auto isolate = args.GetIsolate();
+
+ auto cb_data = unique_ptr<persistent_t[]>(new persistent_t[3]);
+ cb_data[0] = persistent_t(isolate, args[2]);
+ cb_data[1] = persistent_t(isolate, args[3]);
+ cb_data[2] = persistent_t(isolate, args[4]);
+ auto progress_cb = [](void *data, Eio_File *handler,
+ const Eio_Progress *info) {
+ auto persistent = reinterpret_cast<persistent_t*>(data);
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ auto wrapped_info = compatibility_new<Object>(isolate);
+
+ wrapped_info->Set(compatibility_new<String>(isolate, "op"),
+ compatibility_new<Integer>(isolate, info->op));
+ wrapped_info->Set(compatibility_new<String>(isolate, "current"),
+ compatibility_new<Integer>(isolate,
+ info->current));
+ wrapped_info->Set(compatibility_new<String>(isolate, "max"),
+ compatibility_new<Integer>(isolate, info->max));
+ wrapped_info->Set(compatibility_new<String>(isolate, "percent"),
+ compatibility_new<Number>(isolate,
+ info->percent));
+ wrapped_info->Set(compatibility_new<String>(isolate, "source"),
+ compatibility_new<String>(isolate, info->source));
+ wrapped_info->Set(compatibility_new<String>(isolate, "dest"),
+ compatibility_new<String>(isolate, info->dest));
+
+ Handle<Value> args[2] = {
+ wrap_eio_file(handler, isolate),
+ wrapped_info
+ };
+
+ Function::Cast(*o)->Call(o->ToObject(), 2, args);
+ };
+ auto done_cb = [](void *data, Eio_File *handler) {
+ auto persistent = reinterpret_cast<persistent_t*>(data) + 1;
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args = wrap_eio_file(handler, isolate);
+
+ Function::Cast(*o)->Call(o->ToObject(), 1, &args);
+
+ delete[] (persistent - 1);
+ };
+ auto error_cb = [](void *data, Eio_File *handler, int error) {
+ auto persistent = reinterpret_cast<persistent_t*>(data) + 2;
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args[2] = {
+ wrap_eio_file(handler, isolate),
+ compatibility_new<Integer>(isolate, error)
+ };
+
+ Function::Cast(*o)->Call(o->ToObject(), 2, args);
+
+ delete[] (persistent - 2);
+ };
+
+ auto ret = eio_file_copy(*String::Utf8Value(args[0]),
+ *String::Utf8Value(args[1]),
+ progress_cb, done_cb, error_cb,
+ cb_data.release());
+ return compatibility_return(wrap_eio_file(ret, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_dir_move(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::String;
+ using v8::Integer;
+ using v8::Number;
+ using v8::Object;
+ using v8::FunctionTemplate;
+ using v8::Handle;
+ using v8::Value;
+ using v8::Function;
+ using std::unique_ptr;
+
+ typedef efl::eina::js::global_ref<Value> persistent_t;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 6 || !args[0]->IsString() || !args[1]->IsString()
+ || !args[2]->IsFunction() || !args[3]->IsFunction()
+ || !args[4]->IsFunction() || !args[5]->IsFunction()) {
+ return compatibility_return();
+ }
+
+ auto isolate = args.GetIsolate();
+
+ auto cb_data = unique_ptr<persistent_t[]>(new persistent_t[4]);
+ cb_data[0] = persistent_t(isolate, args[2]);
+ cb_data[1] = persistent_t(isolate, args[3]);
+ cb_data[2] = persistent_t(isolate, args[4]);
+ cb_data[3] = persistent_t(isolate, args[5]);
+ auto filter_cb = [](void *data, Eio_File *handler,
+ const Eina_File_Direct_Info *info) -> Eina_Bool {
+ auto persistent = reinterpret_cast<persistent_t*>(data);
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args[2] = {
+ wrap_eio_file(handler, isolate),
+ wrap_eina_file_direct_info(info, isolate)
+ };
+
+ auto ret = Function::Cast(*o)->Call(o->ToObject(), 2, args);
+ auto bret = ret->IsBoolean() && ret->BooleanValue();
+ return bret ? EINA_TRUE : EINA_FALSE;
+ };
+ auto progress_cb = [](void *data, Eio_File *handler,
+ const Eio_Progress *info) {
+ auto persistent = reinterpret_cast<persistent_t*>(data) + 1;
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ auto wrapped_info = compatibility_new<Object>(isolate);
+
+ wrapped_info->Set(compatibility_new<String>(isolate, "op"),
+ compatibility_new<Integer>(isolate, info->op));
+ wrapped_info->Set(compatibility_new<String>(isolate, "current"),
+ compatibility_new<Integer>(isolate,
+ info->current));
+ wrapped_info->Set(compatibility_new<String>(isolate, "max"),
+ compatibility_new<Integer>(isolate, info->max));
+ wrapped_info->Set(compatibility_new<String>(isolate, "percent"),
+ compatibility_new<Number>(isolate,
+ info->percent));
+ wrapped_info->Set(compatibility_new<String>(isolate, "source"),
+ compatibility_new<String>(isolate, info->source));
+ wrapped_info->Set(compatibility_new<String>(isolate, "dest"),
+ compatibility_new<String>(isolate, info->dest));
+
+ Handle<Value> args[2] = {
+ wrap_eio_file(handler, isolate),
+ wrapped_info
+ };
+
+ Function::Cast(*o)->Call(o->ToObject(), 2, args);
+ };
+ auto done_cb = [](void *data, Eio_File *handler) {
+ auto persistent = reinterpret_cast<persistent_t*>(data) + 2;
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args = wrap_eio_file(handler, isolate);
+
+ Function::Cast(*o)->Call(o->ToObject(), 1, &args);
+
+ delete[] (persistent - 2);
+ };
+ auto error_cb = [](void *data, Eio_File *handler, int error) {
+ auto persistent = reinterpret_cast<persistent_t*>(data) + 3;
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args[2] = {
+ wrap_eio_file(handler, isolate),
+ compatibility_new<Integer>(isolate, error)
+ };
+
+ Function::Cast(*o)->Call(o->ToObject(), 2, args);
+
+ delete[] (persistent - 3);
+ };
+
+ auto ret = eio_dir_move(*String::Utf8Value(args[0]),
+ *String::Utf8Value(args[1]), filter_cb,
+ progress_cb, done_cb, error_cb,
+ cb_data.release());
+ return compatibility_return(wrap_eio_file(ret, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_dir_copy(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::String;
+ using v8::Integer;
+ using v8::Number;
+ using v8::Object;
+ using v8::FunctionTemplate;
+ using v8::Handle;
+ using v8::Value;
+ using v8::Function;
+ using std::unique_ptr;
+
+ typedef efl::eina::js::global_ref<Value> persistent_t;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 6 || !args[0]->IsString() || !args[1]->IsString()
+ || !args[2]->IsFunction() || !args[3]->IsFunction()
+ || !args[4]->IsFunction() || !args[5]->IsFunction()) {
+ return compatibility_return();
+ }
+
+ auto isolate = args.GetIsolate();
+
+ auto cb_data = unique_ptr<persistent_t[]>(new persistent_t[4]);
+ cb_data[0] = persistent_t(isolate, args[2]);
+ cb_data[1] = persistent_t(isolate, args[3]);
+ cb_data[2] = persistent_t(isolate, args[4]);
+ cb_data[3] = persistent_t(isolate, args[5]);
+ auto filter_cb = [](void *data, Eio_File *handler,
+ const Eina_File_Direct_Info *info) -> Eina_Bool {
+ auto persistent = reinterpret_cast<persistent_t*>(data);
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args[2] = {
+ wrap_eio_file(handler, isolate),
+ wrap_eina_file_direct_info(info, isolate)
+ };
+
+ auto ret = Function::Cast(*o)->Call(o->ToObject(), 2, args);
+ auto bret = ret->IsBoolean() && ret->BooleanValue();
+ return bret ? EINA_TRUE : EINA_FALSE;
+ };
+ auto progress_cb = [](void *data, Eio_File *handler,
+ const Eio_Progress *info) {
+ auto persistent = reinterpret_cast<persistent_t*>(data) + 1;
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ auto wrapped_info = compatibility_new<Object>(isolate);
+
+ wrapped_info->Set(compatibility_new<String>(isolate, "op"),
+ compatibility_new<Integer>(isolate, info->op));
+ wrapped_info->Set(compatibility_new<String>(isolate, "current"),
+ compatibility_new<Integer>(isolate,
+ info->current));
+ wrapped_info->Set(compatibility_new<String>(isolate, "max"),
+ compatibility_new<Integer>(isolate, info->max));
+ wrapped_info->Set(compatibility_new<String>(isolate, "percent"),
+ compatibility_new<Number>(isolate,
+ info->percent));
+ wrapped_info->Set(compatibility_new<String>(isolate, "source"),
+ compatibility_new<String>(isolate, info->source));
+ wrapped_info->Set(compatibility_new<String>(isolate, "dest"),
+ compatibility_new<String>(isolate, info->dest));
+
+ Handle<Value> args[2] = {
+ wrap_eio_file(handler, isolate),
+ wrapped_info
+ };
+
+ Function::Cast(*o)->Call(o->ToObject(), 2, args);
+ };
+ auto done_cb = [](void *data, Eio_File *handler) {
+ auto persistent = reinterpret_cast<persistent_t*>(data) + 2;
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args = wrap_eio_file(handler, isolate);
+
+ Function::Cast(*o)->Call(o->ToObject(), 1, &args);
+
+ delete[] (persistent - 2);
+ };
+ auto error_cb = [](void *data, Eio_File *handler, int error) {
+ auto persistent = reinterpret_cast<persistent_t*>(data) + 3;
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args[2] = {
+ wrap_eio_file(handler, isolate),
+ compatibility_new<Integer>(isolate, error)
+ };
+
+ Function::Cast(*o)->Call(o->ToObject(), 2, args);
+
+ delete[] (persistent - 3);
+ };
+
+ auto ret = eio_dir_copy(*String::Utf8Value(args[0]),
+ *String::Utf8Value(args[1]), filter_cb,
+ progress_cb, done_cb, error_cb,
+ cb_data.release());
+ return compatibility_return(wrap_eio_file(ret, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_dir_unlink(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::String;
+ using v8::Integer;
+ using v8::Number;
+ using v8::Object;
+ using v8::FunctionTemplate;
+ using v8::Handle;
+ using v8::Value;
+ using v8::Function;
+ using std::unique_ptr;
+
+ typedef efl::eina::js::global_ref<Value> persistent_t;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 5 || !args[0]->IsString() || !args[1]->IsFunction()
+ || !args[2]->IsFunction() || !args[3]->IsFunction()
+ || !args[4]->IsFunction()) {
+ return compatibility_return();
+ }
+
+ auto isolate = args.GetIsolate();
+
+ auto cb_data = unique_ptr<persistent_t[]>(new persistent_t[4]);
+ cb_data[0] = persistent_t(isolate, args[1]);
+ cb_data[1] = persistent_t(isolate, args[2]);
+ cb_data[2] = persistent_t(isolate, args[3]);
+ cb_data[3] = persistent_t(isolate, args[4]);
+ auto filter_cb = [](void *data, Eio_File *handler,
+ const Eina_File_Direct_Info *info) -> Eina_Bool {
+ auto persistent = reinterpret_cast<persistent_t*>(data);
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args[2] = {
+ wrap_eio_file(handler, isolate),
+ wrap_eina_file_direct_info(info, isolate)
+ };
+
+ auto ret = Function::Cast(*o)->Call(o->ToObject(), 2, args);
+ auto bret = ret->IsBoolean() && ret->BooleanValue();
+ return bret ? EINA_TRUE : EINA_FALSE;
+ };
+ auto progress_cb = [](void *data, Eio_File *handler,
+ const Eio_Progress *info) {
+ auto persistent = reinterpret_cast<persistent_t*>(data) + 1;
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ auto wrapped_info = compatibility_new<Object>(isolate);
+
+ wrapped_info->Set(compatibility_new<String>(isolate, "op"),
+ compatibility_new<Integer>(isolate, info->op));
+ wrapped_info->Set(compatibility_new<String>(isolate, "current"),
+ compatibility_new<Integer>(isolate,
+ info->current));
+ wrapped_info->Set(compatibility_new<String>(isolate, "max"),
+ compatibility_new<Integer>(isolate, info->max));
+ wrapped_info->Set(compatibility_new<String>(isolate, "percent"),
+ compatibility_new<Number>(isolate,
+ info->percent));
+ wrapped_info->Set(compatibility_new<String>(isolate, "source"),
+ compatibility_new<String>(isolate, info->source));
+ wrapped_info->Set(compatibility_new<String>(isolate, "dest"),
+ compatibility_new<String>(isolate, info->dest));
+
+ Handle<Value> args[2] = {
+ wrap_eio_file(handler, isolate),
+ wrapped_info
+ };
+
+ Function::Cast(*o)->Call(o->ToObject(), 2, args);
+ };
+ auto done_cb = [](void *data, Eio_File *handler) {
+ auto persistent = reinterpret_cast<persistent_t*>(data) + 2;
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args = wrap_eio_file(handler, isolate);
+
+ Function::Cast(*o)->Call(o->ToObject(), 1, &args);
+
+ delete[] (persistent - 2);
+ };
+ auto error_cb = [](void *data, Eio_File *handler, int error) {
+ auto persistent = reinterpret_cast<persistent_t*>(data) + 3;
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args[2] = {
+ wrap_eio_file(handler, isolate),
+ compatibility_new<Integer>(isolate, error)
+ };
+
+ Function::Cast(*o)->Call(o->ToObject(), 2, args);
+
+ delete[] (persistent - 3);
+ };
+
+ auto ret = eio_dir_unlink(*String::Utf8Value(args[0]), filter_cb,
+ progress_cb, done_cb, error_cb,
+ cb_data.release());
+ return compatibility_return(wrap_eio_file(ret, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+}
+
+EAPI
+void register_eio(v8::Isolate* isolate, v8::Handle<v8::Object> exports)
+{
+ using v8::String;
+ register_init(isolate, exports,
+ compatibility_new<String>(isolate, "eio_init"));
+ register_shutdown(isolate, exports,
+ compatibility_new<String>(isolate, "eio_shutdown"));
+ register_op_file_copy(isolate, exports,
+ compatibility_new<String>(isolate, "EIO_FILE_COPY"));
+ register_op_file_move(isolate, exports,
+ compatibility_new<String>(isolate, "EIO_FILE_MOVE"));
+ register_op_dir_copy(isolate, exports,
+ compatibility_new<String>(isolate, "EIO_DIR_COPY"));
+ register_op_dir_move(isolate, exports,
+ compatibility_new<String>(isolate, "EIO_DIR_MOVE"));
+ register_op_unlink(isolate, exports,
+ compatibility_new<String>(isolate, "EIO_LINK"));
+ register_op_file_getpwnam(isolate, exports,
+ compatibility_new<String>(isolate,
+ "EIO_FILE_GETPWNAM"));
+ register_op_file_getgrnam(isolate, exports,
+ compatibility_new<String>(isolate,
+ "EIO_FILE_GETGRNAM"));
+ register_file_open(isolate, exports,
+ compatibility_new<String>(isolate, "eio_file_open"));
+ register_monitor_file_created(isolate, exports,
+ compatibility_new<String>(isolate,
+ "EIO_MONITOR_FILE"
+ "_CREATED"));
+ register_monitor_file_deleted(isolate, exports,
+ compatibility_new<String>(isolate,
+ "EIO_MONITOR_FILE"
+ "_DELETED"));
+ register_monitor_file_modified(isolate, exports,
+ compatibility_new<String>(isolate,
+ "EIO_MONITOR_FILE"
+ "_MODIFIED"));
+ register_monitor_file_closed(isolate, exports,
+ compatibility_new<String>(isolate,
+ "EIO_MONITOR_FILE"
+ "_CLOSED"));
+ register_monitor_directory_created(isolate, exports,
+ compatibility_new<String>
+ (isolate,
+ "EIO_MONITOR_DIRECTORY_CREATED"));
+ register_monitor_directory_deleted(isolate, exports,
+ compatibility_new<String>
+ (isolate,
+ "EIO_MONITOR_DIRECTORY_DELETED"));
+ register_monitor_directory_modified(isolate, exports,
+ compatibility_new<String>
+ (isolate,
+ "EIO_MONITOR_DIRECTORY_MODIFIED"));
+ register_monitor_directory_closed(isolate, exports,
+ compatibility_new<String>
+ (isolate, "EIO_MONITOR_DIRECTORY_CLOSED"));
+ register_monitor_self_rename(isolate, exports,
+ compatibility_new<String>
+ (isolate, "EIO_MONITOR_SELF_RENAME"));
+ register_monitor_self_deleted(isolate, exports,
+ compatibility_new<String>
+ (isolate, "EIO_MONITOR_SELF_DELETED"));
+ register_monitor_error(isolate, exports,
+ compatibility_new<String>(isolate,
+ "EIO_MONITOR_ERROR"));
+ register_monitor_add(isolate, exports,
+ compatibility_new<String>(isolate, "eio_monitor_add"));
+ register_event_monitor_file_created_handler_add
+ (isolate, exports,
+ compatibility_new<String>(isolate,
+ "eio_event_monitor_file_created_handler_add"));
+ register_event_monitor_file_deleted_handler_add
+ (isolate, exports,
+ compatibility_new<String>(isolate,
+ "eio_event_monitor_file_deleted_handler_add"));
+ register_event_monitor_file_modified_handler_add
+ (isolate, exports,
+ compatibility_new<String>
+ (isolate, "eio_event_monitor_file_modified_handler_add"));
+ register_event_monitor_file_closed_handler_add
+ (isolate, exports,
+ compatibility_new<String>(isolate,
+ "eio_event_monitor_file_closed_handler_add"));
+ register_event_monitor_directory_created_handler_add
+ (isolate, exports,
+ compatibility_new<String>
+ (isolate, "eio_event_monitor_directory_created_handler_add"));
+ register_event_monitor_directory_deleted_handler_add
+ (isolate, exports,
+ compatibility_new<String>
+ (isolate, "eio_event_monitor_directory_deleted_handler_add"));
+ register_event_monitor_directory_modified_handler_add
+ (isolate, exports,
+ compatibility_new<String>
+ (isolate, "eio_event_monitor_directory_modified_handler_add"));
+ register_event_monitor_directory_closed_handler_add
+ (isolate, exports,
+ compatibility_new<String>
+ (isolate, "eio_event_monitor_directory_closed_handler_add"));
+ register_event_monitor_self_rename_handler_add
+ (isolate, exports,
+ compatibility_new<String>(isolate,
+ "eio_event_monitor_self_rename_handler_add"));
+ register_event_monitor_self_deleted_handler_add
+ (isolate, exports,
+ compatibility_new<String>(isolate,
+ "eio_event_monitor_self_deleted_handler_add"));
+ register_event_monitor_error_handler_add
+ (isolate, exports,
+ compatibility_new<String>(isolate,
+ "eio_event_monitor_error_handler_add"));
+ register_file_ls(isolate, exports,
+ compatibility_new<String>(isolate, "eio_file_ls"));
+ register_file_chmod(isolate, exports,
+ compatibility_new<String>(isolate, "eio_file_chmod"));
+ register_file_chown(isolate, exports,
+ compatibility_new<String>(isolate, "eio_file_chown"));
+ register_file_unlink(isolate, exports,
+ compatibility_new<String>(isolate, "eio_file_unlink"));
+ register_file_mkdir(isolate, exports,
+ compatibility_new<String>(isolate, "eio_file_mkdir"));
+ register_file_move(isolate, exports,
+ compatibility_new<String>(isolate, "eio_file_move"));
+ register_file_copy(isolate, exports,
+ compatibility_new<String>(isolate, "eio_file_copy"));
+ register_dir_move(isolate, exports,
+ compatibility_new<String>(isolate, "eio_dir_move"));
+ register_dir_copy(isolate, exports,
+ compatibility_new<String>(isolate, "eio_dir_copy"));
+ register_dir_unlink(isolate, exports,
+ compatibility_new<String>(isolate, "eio_dir_unlink"));
+}
+
+} } } // namespace efl { namespace eio { namespace js {
diff --git a/src/bindings/eldbus_cxx/eldbus_freedesktop.hh b/src/bindings/eldbus_cxx/eldbus_freedesktop.hh
index e44b9b228d..4af8c58e30 100644
--- a/src/bindings/eldbus_cxx/eldbus_freedesktop.hh
+++ b/src/bindings/eldbus_cxx/eldbus_freedesktop.hh
@@ -11,7 +11,6 @@ namespace efl { namespace eldbus { namespace _detail {
template <typename Callback, typename... Ins>
void _callback_wrapper(void* data, Eldbus_Message const* message, Eldbus_Pending* pending)
{
- std::cout << "_callback_wrapper" << std::endl;
Callback* callback(static_cast<Callback*>(data));
const char* errname, *errmsg;
diff --git a/src/bindings/eldbus_js/Eldbus_Js.hh b/src/bindings/eldbus_js/Eldbus_Js.hh
new file mode 100644
index 0000000000..00da9ca924
--- /dev/null
+++ b/src/bindings/eldbus_js/Eldbus_Js.hh
@@ -0,0 +1,48 @@
+
+#ifndef EFL_ELDBUS_JS_HH
+#define EFL_ELDBUS_JS_HH
+
+#include <Eina.hh>
+#include <Eina_Js.hh>
+
+#include <Eldbus.h>
+
+#ifdef EAPI
+# undef EAPI
+#endif
+
+#ifdef _WIN32
+# ifdef EFL_EINA_JS_BUILD
+# ifdef DLL_EXPORT
+# define EAPI __declspec(dllexport)
+# else
+# define EAPI
+# endif /* ! DLL_EXPORT */
+# else
+# define EAPI __declspec(dllimport)
+# endif /* ! EFL_ECORE_BUILD */
+#else
+# ifdef __GNUC__
+# if __GNUC__ >= 4
+# define EAPI __attribute__ ((visibility("default")))
+# else
+# define EAPI
+# endif
+# else
+# define EAPI
+# endif
+#endif /* ! _WIN32 */
+
+namespace efl { namespace eldbus { namespace js {
+
+EAPI void register_eldbus_connection(v8::Isolate* isolate, v8::Handle<v8::Object> exports);
+EAPI void register_eldbus_core(v8::Isolate* isolate, v8::Handle<v8::Object> exports);
+EAPI void register_eldbus_message(v8::Isolate* isolate, v8::Handle<v8::Object> exports);
+EAPI void register_eldbus_object_mapper(v8::Isolate* isolate, v8::Handle<v8::Object> exports);
+EAPI void register_eldbus(v8::Isolate* isolate, v8::Handle<v8::Object> exports);
+
+} } }
+
+#include <eldbus_js_util.hh>
+
+#endif
diff --git a/src/bindings/eldbus_js/eldbus_js_connection.cc b/src/bindings/eldbus_js/eldbus_js_connection.cc
new file mode 100644
index 0000000000..c02dc8c600
--- /dev/null
+++ b/src/bindings/eldbus_js/eldbus_js_connection.cc
@@ -0,0 +1,543 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <Eldbus_Js.hh>
+
+namespace efl { namespace eldbus { namespace js {
+
+namespace {
+
+v8::Local<v8::Object> wrap_event_callback(Eldbus_Connection *conn,
+ Eldbus_Connection_Event_Type type,
+ Eldbus_Connection_Event_Cb cb,
+ void *cb_data, v8::Isolate *isolate)
+{
+ using v8::String;
+ using v8::Integer;
+ using v8::Value;
+ using v8::Object;
+ using v8::ObjectTemplate;
+ using v8::FunctionTemplate;
+
+ auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
+ obj_tpl->SetInternalFieldCount(3);
+ auto ret = obj_tpl->NewInstance();
+
+ ret->Set(compatibility_new<String>(isolate, "_type"),
+ compatibility_new<Integer>(isolate, type));
+
+ compatibility_set_pointer_internal_field(ret, 0, conn);
+ compatibility_set_pointer_internal_field(ret, 1, (void*)(cb));
+ compatibility_set_pointer_internal_field(ret, 2, cb_data);
+
+ auto del = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ auto o = info.This();
+ auto isolate = info.GetIsolate();
+
+ auto conn
+ = (compatibility_get_pointer_internal_field<Eldbus_Connection*>
+ (o, 0));
+ auto cb
+ = (compatibility_get_pointer_internal_field
+ <Eldbus_Connection_Event_Cb>(o, 1));
+ auto cb_data
+ = (compatibility_get_pointer_internal_field
+ <efl::eina::js::global_ref<Value>*>(o, 2));
+ auto type
+ = (static_cast<Eldbus_Connection_Event_Type>
+ (o->Get(compatibility_new<String>(isolate, "_type"))
+ ->IntegerValue()));
+
+ eldbus_connection_event_callback_del(conn, type, cb, cb_data);
+
+ delete cb_data;
+ return compatibility_return();
+ };
+
+ ret->Set(compatibility_new<String>(isolate, "del"),
+ compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
+
+ return ret;
+}
+
+Eldbus_Connection* extract_eldbus_connection(v8::Local<v8::Object> o)
+{
+ return compatibility_get_pointer_internal_field<Eldbus_Connection*>(o, 0);
+}
+
+void register_timeout_infinite(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name, compatibility_new<Integer>(isolate,
+ ELDBUS_TIMEOUT_INFINITE));
+}
+
+void register_connection_type_unknown(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate,
+ ELDBUS_CONNECTION_TYPE_UNKNOWN));
+}
+
+void register_connection_type_session(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate,
+ ELDBUS_CONNECTION_TYPE_SESSION));
+}
+
+void register_connection_type_system(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate,
+ ELDBUS_CONNECTION_TYPE_SYSTEM));
+}
+
+void register_connection_type_starter(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate,
+ ELDBUS_CONNECTION_TYPE_STARTER));
+}
+
+void register_connection_type_address(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate,
+ ELDBUS_CONNECTION_TYPE_ADDRESS));
+}
+
+void register_connection_type_last(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate,
+ ELDBUS_CONNECTION_TYPE_LAST));
+}
+
+void register_connection_event_del(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name, compatibility_new<Integer>(isolate,
+ ELDBUS_CONNECTION_EVENT_DEL));
+}
+
+void register_connection_event_disconnected(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>
+ (isolate, ELDBUS_CONNECTION_EVENT_DISCONNECTED));
+}
+
+void register_connection_event_last(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name, compatibility_new<Integer>(isolate,
+ ELDBUS_CONNECTION_EVENT_LAST));
+}
+
+void register_connection_get(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::String;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsNumber())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ Eldbus_Connection_Type type;
+
+ switch (args[0]->IntegerValue()) {
+ case ELDBUS_CONNECTION_TYPE_UNKNOWN:
+ type = ELDBUS_CONNECTION_TYPE_UNKNOWN;
+ break;
+ case ELDBUS_CONNECTION_TYPE_SESSION:
+ type = ELDBUS_CONNECTION_TYPE_SESSION;
+ break;
+ case ELDBUS_CONNECTION_TYPE_SYSTEM:
+ type = ELDBUS_CONNECTION_TYPE_SYSTEM;
+ break;
+ case ELDBUS_CONNECTION_TYPE_STARTER:
+ type = ELDBUS_CONNECTION_TYPE_STARTER;
+ break;
+ case ELDBUS_CONNECTION_TYPE_ADDRESS:
+ type = ELDBUS_CONNECTION_TYPE_ADDRESS;
+ break;
+ case ELDBUS_CONNECTION_TYPE_LAST:
+ type = ELDBUS_CONNECTION_TYPE_LAST;
+ break;
+ default:
+ return compatibility_return();
+ }
+ auto ret = eldbus_connection_get(type);
+ return compatibility_return(wrap_eldbus_connection(ret, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_private_connection_get(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::String;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsNumber())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ Eldbus_Connection_Type type;
+
+ switch (args[0]->IntegerValue()) {
+ case ELDBUS_CONNECTION_TYPE_UNKNOWN:
+ type = ELDBUS_CONNECTION_TYPE_UNKNOWN;
+ break;
+ case ELDBUS_CONNECTION_TYPE_SESSION:
+ type = ELDBUS_CONNECTION_TYPE_SESSION;
+ break;
+ case ELDBUS_CONNECTION_TYPE_SYSTEM:
+ type = ELDBUS_CONNECTION_TYPE_SYSTEM;
+ break;
+ case ELDBUS_CONNECTION_TYPE_STARTER:
+ type = ELDBUS_CONNECTION_TYPE_STARTER;
+ break;
+ case ELDBUS_CONNECTION_TYPE_ADDRESS:
+ type = ELDBUS_CONNECTION_TYPE_ADDRESS;
+ break;
+ case ELDBUS_CONNECTION_TYPE_LAST:
+ type = ELDBUS_CONNECTION_TYPE_LAST;
+ break;
+ default:
+ return compatibility_return();
+ }
+ auto ret = eldbus_private_connection_get(type);
+ return compatibility_return(wrap_eldbus_connection(ret, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_address_connection_get(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+
+{
+ using v8::String;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsString())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+
+ auto ret = eldbus_address_connection_get(*String::Utf8Value(args[0]));
+ return compatibility_return(wrap_eldbus_connection(ret, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_private_address_connection_get(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+
+{
+ using v8::String;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsString())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+
+ String::Utf8Value address(args[0]);
+
+ auto ret = eldbus_private_address_connection_get(*address);
+ return compatibility_return(wrap_eldbus_connection(ret, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+}
+
+v8::Local<v8::Object> wrap_eldbus_connection(Eldbus_Connection *conn,
+ v8::Isolate *isolate)
+{
+ using v8::String;
+ using v8::Boolean;
+ using v8::Value;
+ using v8::Handle;
+ using v8::ObjectTemplate;
+ using v8::Function;
+ using v8::FunctionTemplate;
+ using std::unique_ptr;
+
+ typedef efl::eina::js::global_ref<Value> persistent_t;
+
+ auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
+ obj_tpl->SetInternalFieldCount(1);
+ auto ret = obj_tpl->NewInstance();
+
+ auto event_callback_add = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 2 || !info[0]->IsNumber()
+ || !info[1]->IsFunction()) {
+ return compatibility_return();
+ }
+
+ auto isolate = info.GetIsolate();
+ auto conn = extract_eldbus_connection(info.This());
+ Eldbus_Connection_Event_Type type;
+
+ switch (info[0]->IntegerValue()) {
+ case ELDBUS_CONNECTION_EVENT_DEL:
+ type = ELDBUS_CONNECTION_EVENT_DEL;
+ break;
+ case ELDBUS_CONNECTION_EVENT_DISCONNECTED:
+ type = ELDBUS_CONNECTION_EVENT_DISCONNECTED;
+ break;
+ case ELDBUS_CONNECTION_EVENT_LAST:
+ type = ELDBUS_CONNECTION_EVENT_LAST;
+ break;
+ default:
+ return compatibility_return();
+ }
+
+ unique_ptr<persistent_t> cb_data{new persistent_t{isolate, info[1]}};
+
+ auto cb = [](void *data, Eldbus_Connection *conn,
+ void */*event_info*/) {
+ auto persistent = reinterpret_cast<persistent_t*>(data);
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args{wrap_eldbus_connection(conn, isolate)};
+
+ Function::Cast(*o)->Call(o->ToObject(), 1, &args);
+ };
+
+ eldbus_connection_event_callback_add(conn, type, cb, cb_data.get());
+ auto ret = wrap_event_callback(conn, type, cb, cb_data.release(),
+ isolate);
+ return compatibility_return(ret, info);
+ };
+
+ auto send = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 3 || !info[0]->IsObject() || !info[1]->IsFunction()
+ || !info[2]->IsNumber()) {
+ return compatibility_return();
+ }
+
+ auto isolate = info.GetIsolate();
+ auto conn = extract_eldbus_connection(info.This());
+ auto msg
+ = (compatibility_get_pointer_internal_field<Eldbus_Message*>
+ (info[0]->ToObject(), 0));
+
+ unique_ptr<persistent_t> cb_data{new persistent_t{isolate, info[1]}};
+
+ auto cb = [](void *data, const Eldbus_Message *msg,
+ Eldbus_Pending *pending) {
+ auto persistent = reinterpret_cast<persistent_t*>(data);
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args[2] = {
+ wrap_const_eldbus_msg(msg, isolate),
+ wrap_eldbus_pending(pending, persistent, isolate)
+ };
+
+ Function::Cast(*o)->Call(o->ToObject(), 2, args);
+
+ delete persistent;
+ };
+
+ auto ret = eldbus_connection_send(conn, msg, cb, cb_data.get(),
+ info[2]->NumberValue());
+ return compatibility_return(wrap_eldbus_pending(ret, cb_data.release(),
+ isolate),
+ info);
+ };
+
+ auto unique_name_get = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = info.GetIsolate();
+ auto conn = extract_eldbus_connection(info.This());
+
+ auto ret = eldbus_connection_unique_name_get(conn);
+ return compatibility_return(compatibility_new<String>(isolate, ret),
+ info);
+ };
+
+ auto object_get = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 2 || !info[0]->IsString() || !info[1]->IsString())
+ return compatibility_return();
+
+ auto isolate = info.GetIsolate();
+ auto conn = extract_eldbus_connection(info.This());
+
+ auto ret = eldbus_object_get(conn, *String::Utf8Value(info[0]),
+ *String::Utf8Value(info[1]));
+ return compatibility_return(wrap_eldbus_object(ret, isolate), info);
+ };
+
+ auto signal_handler_add = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 5 || !info[0]->IsString() || !info[1]->IsString()
+ || !info[2]->IsString() || !info[3]->IsString()
+ || !info[4]->IsFunction()) {
+ return compatibility_return();
+ }
+
+ auto isolate = info.GetIsolate();
+ auto conn = extract_eldbus_connection(info.This());
+
+ unique_ptr<persistent_t> cb_data{new persistent_t{isolate, info[4]}};
+
+ auto cb = [](void *data, const Eldbus_Message *msg) {
+ auto persistent = reinterpret_cast<persistent_t*>(data);
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args{wrap_const_eldbus_msg(msg, isolate)};
+
+ Function::Cast(*o)->Call(o->ToObject(), 1, &args);
+ };
+
+ auto ret = eldbus_signal_handler_add(conn, *String::Utf8Value(info[0]),
+ *String::Utf8Value(info[1]),
+ *String::Utf8Value(info[2]),
+ *String::Utf8Value(info[3]),
+ cb, cb_data.get());
+ auto wrapped_ret = wrap_eldbus_signal_handler(ret, cb_data.release(),
+ isolate);
+ return compatibility_return(wrapped_ret, info);
+ };
+
+ ret->Set(compatibility_new<String>(isolate, "event_callback_add"),
+ compatibility_new<FunctionTemplate>(isolate, event_callback_add)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "send"),
+ compatibility_new<FunctionTemplate>(isolate, send)->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "unique_name_get"),
+ compatibility_new<FunctionTemplate>(isolate, unique_name_get)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "object_get"),
+ compatibility_new<FunctionTemplate>(isolate, object_get)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "signal_handler_add"),
+ compatibility_new<FunctionTemplate>(isolate, signal_handler_add)
+ ->GetFunction());
+
+ compatibility_set_pointer_internal_field(ret, 0, conn);
+
+ return ret;
+}
+
+EAPI
+void register_eldbus_connection(v8::Isolate* isolate, v8::Handle<v8::Object> exports)
+{
+ using v8::String;
+ register_timeout_infinite(isolate, exports,
+ compatibility_new<String>
+ (isolate, "ELDBUS_TIMEOUT_INFINITE"));
+ register_connection_type_unknown(isolate, exports,
+ compatibility_new<String>
+ (isolate, "ELDBUS_CONNECTION_TYPE_UNKNOWN"));
+ register_connection_type_session(isolate, exports,
+ compatibility_new<String>
+ (isolate, "ELDBUS_CONNECTION_TYPE_SESSION"));
+ register_connection_type_system(isolate, exports,
+ compatibility_new<String>
+ (isolate, "ELDBUS_CONNECTION_TYPE_SYSTEM"));
+ register_connection_type_starter(isolate, exports,
+ compatibility_new<String>
+ (isolate, "ELDBUS_CONNECTION_TYPE_STARTER"));
+ register_connection_type_address(isolate, exports,
+ compatibility_new<String>
+ (isolate, "ELDBUS_CONNECTION_TYPE_ADDRESS"));
+ register_connection_type_last(isolate, exports,
+ compatibility_new<String>
+ (isolate, "ELDBUS_CONNECTION_TYPE_LAST"));
+ register_connection_event_del(isolate, exports,
+ compatibility_new<String>
+ (isolate, "ELDBUS_CONNECTION_EVENT_DEL"));
+ register_connection_event_disconnected(isolate, exports,
+ compatibility_new<String>
+ (isolate,
+ "ELDBUS_CONNECTION_EVENT"
+ "_DISCONNECTED"));
+ register_connection_event_last(isolate, exports,
+ compatibility_new<String>
+ (isolate, "ELDBUS_CONNECTION_EVENT_LAST"));
+
+ register_connection_get(isolate, exports,
+ compatibility_new<String>
+ (isolate, "connection_get"));
+
+ register_private_connection_get(isolate, exports,
+ compatibility_new<String>
+ (isolate, "private_connection_get"));
+
+ register_address_connection_get(isolate, exports,
+ compatibility_new<String>
+ (isolate, "address_connection_get"));
+
+ register_private_address_connection_get(isolate, exports,
+ compatibility_new<String>
+ (isolate, "private_address_connection_get"));
+}
+
+} } } // namespace efl { namespace eldbus { namespace js {
diff --git a/src/bindings/eldbus_js/eldbus_js_core.cc b/src/bindings/eldbus_js/eldbus_js_core.cc
new file mode 100644
index 0000000000..e9a8c3344d
--- /dev/null
+++ b/src/bindings/eldbus_js/eldbus_js_core.cc
@@ -0,0 +1,183 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <Eldbus_Js.hh>
+
+namespace efl { namespace eldbus { namespace js {
+
+namespace {
+
+void register_init(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::FunctionTemplate;
+
+ auto init = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = eldbus_init();
+ return compatibility_return(compatibility_new<Integer>(isolate, ret),
+ args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, init)
+ ->GetFunction());
+}
+
+void register_shutdown(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::FunctionTemplate;
+
+ auto shutdown = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = eldbus_shutdown();
+ return compatibility_return(compatibility_new<Integer>(isolate, ret),
+ args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, shutdown)
+ ->GetFunction());
+}
+
+void register_fdo_bus(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::String;
+ global->Set(name, compatibility_new<String>(isolate, ELDBUS_FDO_BUS));
+}
+
+void register_fdo_path(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::String;
+ global->Set(name, compatibility_new<String>(isolate, ELDBUS_FDO_PATH));
+}
+
+void register_fdo_interface(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::String;
+ global->Set(name, compatibility_new<String>(isolate, ELDBUS_FDO_INTERFACE));
+}
+
+void register_fdo_interface_properties(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::String;
+ global->Set(name,
+ compatibility_new<String>(isolate,
+ ELDBUS_FDO_INTERFACE_PROPERTIES));
+}
+
+void register_fdo_interface_object_manager(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::String;
+ global->Set(name,
+ compatibility_new<String>(isolate,
+ ELDBUS_FDO_INTERFACE_OBJECT_MANAGER));
+}
+
+void register_fdo_interface_introspectable(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::String;
+ global->Set(name,
+ compatibility_new<String>(isolate,
+ ELDBUS_FDO_INTERFACE_INTROSPECTABLE));
+}
+
+void register_fdo_inteface_peer(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::String;
+ global->Set(name,
+ compatibility_new<String>(isolate, ELDBUS_FDO_INTEFACE_PEER));
+}
+
+void register_error_pending_canceled(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::String;
+ global->Set(name,
+ compatibility_new<String>(isolate,
+ ELDBUS_ERROR_PENDING_CANCELED));
+}
+
+void register_error_pending_timeout(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::String;
+ global->Set(name,
+ compatibility_new<String>(isolate,
+ ELDBUS_ERROR_PENDING_TIMEOUT));
+}
+
+}
+
+EAPI
+void register_eldbus_core(v8::Isolate* isolate, v8::Handle<v8::Object> exports)
+{
+ using v8::String;
+ register_init(isolate, exports,
+ compatibility_new<String>(isolate, "eldbus_init"));
+ register_shutdown(isolate, exports,
+ compatibility_new<String>(isolate, "eldbus_shutdown"));
+ register_fdo_bus(isolate, exports,
+ compatibility_new<String>(isolate, "ELDBUS_FDO_BUS"));
+ register_fdo_path(isolate, exports,
+ compatibility_new<String>(isolate, "ELDBUS_FDO_PATH"));
+ register_fdo_interface(isolate, exports,
+ compatibility_new<String>(isolate,
+ "ELDBUS_FDO_INTERFACE"));
+ register_fdo_interface_properties(isolate, exports,
+ compatibility_new<String>
+ (isolate,
+ "ELDBUS_FDO_INTERFACE_PROPERTIES"));
+ register_fdo_interface_object_manager(isolate, exports,
+ compatibility_new<String>
+ (isolate, "ELDBUS_FDO_INTERFACE_OBJECT_MANAGER"));
+
+ register_fdo_interface_introspectable
+ (isolate, exports,
+ compatibility_new<String>(isolate,
+ "ELDBUS_FDO_INTERFACE_INTROSPECTABLE"));
+ register_fdo_inteface_peer(isolate, exports,
+ compatibility_new<String>
+ (isolate, "ELDBUS_FDO_INTEFACE_PEER"));
+ register_error_pending_canceled
+ (isolate, exports,
+ compatibility_new<String>(isolate, "ELDBUS_ERROR_PENDING_CANCELED"));
+ register_error_pending_timeout
+ (isolate, exports,
+ compatibility_new<String>(isolate, "ELDBUS_ERROR_PENDING_TIMEOUT"));
+}
+
+EAPI void register_eldbus(v8::Isolate* isolate, v8::Handle<v8::Object> exports)
+{
+ register_eldbus_connection(isolate, exports);
+ register_eldbus_core(isolate, exports);
+ register_eldbus_message(isolate, exports);
+ register_eldbus_object_mapper(isolate, exports);
+}
+
+} } } // namespace efl { namespace eldbus { namespace js {
diff --git a/src/bindings/eldbus_js/eldbus_js_message.cc b/src/bindings/eldbus_js/eldbus_js_message.cc
new file mode 100644
index 0000000000..f9cfa40b76
--- /dev/null
+++ b/src/bindings/eldbus_js/eldbus_js_message.cc
@@ -0,0 +1,103 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <Eldbus_Js.hh>
+
+namespace efl { namespace eldbus { namespace js {
+
+namespace {
+
+void register_message_method_call_new(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::String;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 4 || !args[0]->IsString() || !args[1]->IsString()
+ || !args[2]->IsString() || !args[3]->IsString()) {
+ return compatibility_return();
+ }
+
+ auto isolate = args.GetIsolate();
+ auto ret = eldbus_message_method_call_new(*String::Utf8Value(args[0]),
+ *String::Utf8Value(args[1]),
+ *String::Utf8Value(args[2]),
+ *String::Utf8Value(args[3]));
+ return compatibility_return(wrap_eldbus_msg(ret, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_message_error_new(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::String;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 3 || !args[0]->IsObject() || !args[1]->IsString()
+ || !args[2]->IsString()) {
+ return compatibility_return();
+ }
+
+ auto isolate = args.GetIsolate();
+ auto ret = eldbus_message_error_new(extract_eldbus_msg(args[0]
+ ->ToObject()),
+ *String::Utf8Value(args[1]),
+ *String::Utf8Value(args[2]));
+ return compatibility_return(wrap_eldbus_msg(ret, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+void register_message_method_return_new(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::String;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsObject())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto eldbus_msg = extract_eldbus_msg(args[0]->ToObject());
+ auto ret = eldbus_message_method_return_new(eldbus_msg);
+ return compatibility_return(wrap_eldbus_msg(ret, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+}
+
+EAPI
+void register_eldbus_message(v8::Isolate* isolate, v8::Handle<v8::Object> exports)
+{
+ register_message_method_call_new
+ (isolate, exports, compatibility_new<v8::String>
+ (isolate, "message_method_call_new"));
+
+ register_message_error_new
+ (isolate, exports, compatibility_new<v8::String>
+ (isolate, "message_error_new"));
+
+ register_message_method_return_new
+ (isolate, exports, compatibility_new<v8::String>
+ (isolate, "message_method_return_new"));
+}
+
+} } } // namespace efl { namespace eldbus { namespace js {
diff --git a/src/bindings/eldbus_js/eldbus_js_object_mapper.cc b/src/bindings/eldbus_js/eldbus_js_object_mapper.cc
new file mode 100644
index 0000000000..955ce80948
--- /dev/null
+++ b/src/bindings/eldbus_js/eldbus_js_object_mapper.cc
@@ -0,0 +1,100 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <Eldbus_Js.hh>
+
+namespace efl { namespace eldbus { namespace js {
+
+namespace {
+
+void register_object_event_iface_added(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate,
+ ELDBUS_OBJECT_EVENT_IFACE_ADDED));
+}
+
+void register_object_event_iface_removed(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate,
+ ELDBUS_OBJECT_EVENT_IFACE_REMOVED));
+}
+
+void register_object_event_property_changed(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>
+ (isolate, ELDBUS_OBJECT_EVENT_PROPERTY_CHANGED));
+}
+
+void register_object_event_property_removed(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>
+ (isolate, ELDBUS_OBJECT_EVENT_PROPERTY_REMOVED));
+}
+
+void register_object_event_del(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate, ELDBUS_OBJECT_EVENT_DEL));
+}
+
+void register_object_event_last(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate, ELDBUS_OBJECT_EVENT_LAST));
+}
+
+}
+
+EAPI
+void register_eldbus_object_mapper(v8::Isolate* isolate, v8::Handle<v8::Object> exports)
+{
+ register_object_event_iface_added
+ (isolate, exports, compatibility_new<v8::String>
+ (isolate, "object_event_iface_added"));
+
+ register_object_event_iface_removed
+ (isolate, exports, compatibility_new<v8::String>
+ (isolate, "object_event_iface_removed"));
+
+ register_object_event_property_changed
+ (isolate, exports, compatibility_new<v8::String>
+ (isolate, "object_event_property_changed"));
+
+ register_object_event_property_removed
+ (isolate, exports, compatibility_new<v8::String>
+ (isolate, "object_event_property_removed"));
+
+ register_object_event_del
+ (isolate, exports, compatibility_new<v8::String>
+ (isolate, "object_event_del"));
+
+ register_object_event_last
+ (isolate, exports, compatibility_new<v8::String>
+ (isolate, "object_event_last"));
+}
+
+
+} } } // namespace efl { namespace eldbus { namespace js {
diff --git a/src/bindings/eldbus_js/eldbus_js_util.hh b/src/bindings/eldbus_js/eldbus_js_util.hh
new file mode 100644
index 0000000000..c5af5752be
--- /dev/null
+++ b/src/bindings/eldbus_js/eldbus_js_util.hh
@@ -0,0 +1,836 @@
+#ifndef ELDBUS_JS_UTIL_HH
+#define ELDBUS_JS_UTIL_HH
+
+namespace efl { namespace eldbus { namespace js {
+
+using eina::js::compatibility_get_pointer_internal_field;
+using eina::js::compatibility_set_pointer_internal_field;
+using eina::js::compatibility_new;
+using eina::js::compatibility_callback_info_type;
+using eina::js::compatibility_return_type;
+using eina::js::compatibility_return;
+
+v8::Local<v8::Object> wrap_eldbus_connection(Eldbus_Connection *conn,
+ v8::Isolate *isolate);
+
+inline
+const Eldbus_Message *extract_const_eldbus_msg(v8::Local<v8::Object> o)
+{
+ return compatibility_get_pointer_internal_field<Eldbus_Message*>(o, 0);
+}
+
+inline
+v8::Local<v8::Object> wrap_const_eldbus_msg(const Eldbus_Message *msg,
+ v8::Isolate *isolate)
+{
+ using v8::String;
+ using v8::Object;
+ using v8::Boolean;
+ using v8::ObjectTemplate;
+ using v8::FunctionTemplate;
+
+ auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
+ obj_tpl->SetInternalFieldCount(1);
+ auto ret = obj_tpl->NewInstance();
+
+ auto path_get = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = info.GetIsolate();
+ auto msg = extract_const_eldbus_msg(info.This());
+
+ auto ret = eldbus_message_path_get(msg);
+ return compatibility_return(compatibility_new<String>(isolate, ret),
+ info);
+ };
+
+ auto interface_get = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = info.GetIsolate();
+ auto msg = extract_const_eldbus_msg(info.This());
+
+ auto ret = eldbus_message_interface_get(msg);
+ return compatibility_return(compatibility_new<String>(isolate, ret),
+ info);
+ };
+
+ auto member_get = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = info.GetIsolate();
+ auto msg = extract_const_eldbus_msg(info.This());
+
+ auto ret = eldbus_message_member_get(msg);
+ return compatibility_return(compatibility_new<String>(isolate, ret),
+ info);
+ };
+
+ auto destination_get = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = info.GetIsolate();
+ auto msg = extract_const_eldbus_msg(info.This());
+
+ auto ret = eldbus_message_destination_get(msg);
+ return compatibility_return(compatibility_new<String>(isolate, ret),
+ info);
+ };
+
+ auto sender_get = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = info.GetIsolate();
+ auto msg = extract_const_eldbus_msg(info.This());
+
+ auto ret = eldbus_message_sender_get(msg);
+ return compatibility_return(compatibility_new<String>(isolate, ret),
+ info);
+ };
+
+ auto signature_get = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = info.GetIsolate();
+ auto msg = extract_const_eldbus_msg(info.This());
+
+ auto ret = eldbus_message_signature_get(msg);
+ return compatibility_return(compatibility_new<String>(isolate, ret),
+ info);
+ };
+
+ auto error_get = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = info.GetIsolate();
+ auto msg = extract_const_eldbus_msg(info.This());
+ const char *name = NULL;
+ const char *text = NULL;
+ auto ret = compatibility_new<Object>(isolate);
+
+ auto bret = eldbus_message_error_get(msg, &name, &text);
+ ret->Set(compatibility_new<String>(isolate, "ok"),
+ compatibility_new<Boolean>(isolate, bret));
+
+ if (bret) {
+ ret->Set(compatibility_new<String>(isolate, "name"),
+ compatibility_new<String>(isolate, name));
+ ret->Set(compatibility_new<String>(isolate, "text"),
+ compatibility_new<String>(isolate, text));
+ }
+
+ return compatibility_return(ret, info);
+ };
+
+ ret->Set(compatibility_new<String>(isolate, "path_get"),
+ compatibility_new<FunctionTemplate>(isolate, path_get)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "interface_get"),
+ compatibility_new<FunctionTemplate>(isolate, interface_get)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "member_get"),
+ compatibility_new<FunctionTemplate>(isolate, member_get)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "destination_get"),
+ compatibility_new<FunctionTemplate>(isolate, destination_get)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "sender_get"),
+ compatibility_new<FunctionTemplate>(isolate, sender_get)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "signature_get"),
+ compatibility_new<FunctionTemplate>(isolate, signature_get)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "error_get"),
+ compatibility_new<FunctionTemplate>(isolate, error_get)
+ ->GetFunction());
+
+ compatibility_set_pointer_internal_field(ret, 0,
+ const_cast<Eldbus_Message*>(msg));
+
+ return ret;
+}
+
+inline Eldbus_Message *extract_eldbus_msg(v8::Local<v8::Object> o)
+{
+ return compatibility_get_pointer_internal_field<Eldbus_Message*>(o, 0);
+}
+
+inline
+v8::Local<v8::Object> wrap_eldbus_msg(Eldbus_Message *msg, v8::Isolate *isolate)
+{
+ using v8::String;
+ using v8::FunctionTemplate;
+
+ auto ret = wrap_const_eldbus_msg(msg, isolate);
+
+ auto ref = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto msg = extract_eldbus_msg(info.This());
+
+ eldbus_message_ref(msg);
+
+ return compatibility_return();
+ };
+
+ auto unref = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto msg = extract_eldbus_msg(info.This());
+
+ eldbus_message_unref(msg);
+
+ return compatibility_return();
+ };
+
+ ret->Set(compatibility_new<String>(isolate, "ref"),
+ compatibility_new<FunctionTemplate>(isolate, ref)->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "unref"),
+ compatibility_new<FunctionTemplate>(isolate, unref)
+ ->GetFunction());
+
+ return ret;
+}
+
+inline
+v8::Local<v8::Object> wrap_eldbus_pending(Eldbus_Pending *pending,
+ efl::eina::js::global_ref<v8::Value>*
+ persistent,
+ v8::Isolate *isolate)
+{
+ using v8::String;
+ using v8::Object;
+ using v8::Boolean;
+ using v8::ObjectTemplate;
+ using v8::FunctionTemplate;
+
+ typedef decltype(persistent) persistent_ptr_t;
+
+ auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
+ obj_tpl->SetInternalFieldCount(2);
+ auto ret = obj_tpl->NewInstance();
+
+ auto cancel = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto o = info.This();
+ auto pending
+ = compatibility_get_pointer_internal_field<Eldbus_Pending*>(o, 0);
+ auto persistent
+ = compatibility_get_pointer_internal_field<persistent_ptr_t>(o, 1);
+
+ eldbus_pending_cancel(pending);
+ delete persistent;
+ return compatibility_return();
+ };
+
+ auto destination_get = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = info.GetIsolate();
+ auto o = info.This();
+ auto pending
+ = compatibility_get_pointer_internal_field<Eldbus_Pending*>(o, 0);
+
+ auto ret = eldbus_pending_destination_get(pending);
+ return compatibility_return(compatibility_new<String>(isolate, ret),
+ info);
+ };
+
+ auto path_get = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = info.GetIsolate();
+ auto o = info.This();
+ auto pending
+ = compatibility_get_pointer_internal_field<Eldbus_Pending*>(o, 0);
+
+ auto ret = eldbus_pending_path_get(pending);
+ return compatibility_return(compatibility_new<String>(isolate, ret),
+ info);
+ };
+
+ auto interface_get = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = info.GetIsolate();
+ auto o = info.This();
+ auto pending
+ = compatibility_get_pointer_internal_field<Eldbus_Pending*>(o, 0);
+
+ auto ret = eldbus_pending_interface_get(pending);
+ return compatibility_return(compatibility_new<String>(isolate, ret),
+ info);
+ };
+
+ auto method_get = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = info.GetIsolate();
+ auto o = info.This();
+ auto pending
+ = compatibility_get_pointer_internal_field<Eldbus_Pending*>(o, 0);
+
+ auto ret = eldbus_pending_method_get(pending);
+ return compatibility_return(compatibility_new<String>(isolate, ret),
+ info);
+ };
+
+ ret->Set(compatibility_new<String>(isolate, "cancel"),
+ compatibility_new<FunctionTemplate>(isolate, cancel)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "destination_get"),
+ compatibility_new<FunctionTemplate>(isolate, destination_get)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "path_get"),
+ compatibility_new<FunctionTemplate>(isolate, path_get)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "interface_get"),
+ compatibility_new<FunctionTemplate>(isolate, interface_get)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "method_get"),
+ compatibility_new<FunctionTemplate>(isolate, method_get)
+ ->GetFunction());
+
+ compatibility_set_pointer_internal_field(ret, 0, pending);
+ compatibility_set_pointer_internal_field(ret, 1, persistent);
+
+ return ret;
+}
+
+inline
+v8::Local<v8::Object>
+wrap_eldbus_signal_handler(Eldbus_Signal_Handler *handler,
+ efl::eina::js::global_ref<v8::Value> *persistent,
+ v8::Isolate *isolate)
+{
+ using v8::String;
+ using v8::Object;
+ using v8::Boolean;
+ using v8::ObjectTemplate;
+ using v8::FunctionTemplate;
+
+ typedef decltype(persistent) persistent_ptr_t;
+
+ auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
+ obj_tpl->SetInternalFieldCount(2);
+ auto ret = obj_tpl->NewInstance();
+
+ auto ref = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto o = info.This();
+ auto handler
+ = (compatibility_get_pointer_internal_field<Eldbus_Signal_Handler*>
+ (o, 0));
+
+ eldbus_signal_handler_ref(handler);
+ return compatibility_return();
+ };
+
+ auto unref = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto o = info.This();
+ auto handler
+ = (compatibility_get_pointer_internal_field<Eldbus_Signal_Handler*>
+ (o, 0));
+
+ eldbus_signal_handler_unref(handler);
+ return compatibility_return();
+ };
+
+ auto del = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto o = info.This();
+ auto handler
+ = (compatibility_get_pointer_internal_field<Eldbus_Signal_Handler*>
+ (o, 0));
+ auto persistent
+ = compatibility_get_pointer_internal_field<persistent_ptr_t>(o, 1);
+
+ eldbus_signal_handler_del(handler);
+ delete persistent;
+ return compatibility_return();
+ };
+
+ auto sender_get = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = info.GetIsolate();
+ auto o = info.This();
+ auto handler
+ = (compatibility_get_pointer_internal_field<Eldbus_Signal_Handler*>
+ (o, 0));
+
+ auto ret = eldbus_signal_handler_sender_get(handler);
+ return compatibility_return(compatibility_new<String>(isolate, ret),
+ info);
+ };
+
+ auto path_get = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = info.GetIsolate();
+ auto o = info.This();
+ auto handler
+ = (compatibility_get_pointer_internal_field<Eldbus_Signal_Handler*>
+ (o, 0));
+
+ auto ret = eldbus_signal_handler_path_get(handler);
+ return compatibility_return(compatibility_new<String>(isolate, ret),
+ info);
+ };
+
+ auto interface_get = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = info.GetIsolate();
+ auto o = info.This();
+ auto handler
+ = (compatibility_get_pointer_internal_field<Eldbus_Signal_Handler*>
+ (o, 0));
+
+ auto ret = eldbus_signal_handler_interface_get(handler);
+ return compatibility_return(compatibility_new<String>(isolate, ret),
+ info);
+ };
+
+ auto member_get = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = info.GetIsolate();
+ auto o = info.This();
+ auto handler
+ = (compatibility_get_pointer_internal_field<Eldbus_Signal_Handler*>
+ (o, 0));
+
+ auto ret = eldbus_signal_handler_member_get(handler);
+ return compatibility_return(compatibility_new<String>(isolate, ret),
+ info);
+ };
+
+ auto match_get = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = info.GetIsolate();
+ auto o = info.This();
+ auto handler
+ = (compatibility_get_pointer_internal_field<Eldbus_Signal_Handler*>
+ (o, 0));
+
+ auto ret = eldbus_signal_handler_match_get(handler);
+ return compatibility_return(compatibility_new<String>(isolate, ret),
+ info);
+ };
+
+ auto connection_get = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = info.GetIsolate();
+ auto o = info.This();
+ auto handler
+ = (compatibility_get_pointer_internal_field<Eldbus_Signal_Handler*>
+ (o, 0));
+
+ auto ret = eldbus_signal_handler_connection_get(handler);
+ return compatibility_return(wrap_eldbus_connection(ret, isolate), info);
+ };
+
+ ret->Set(compatibility_new<String>(isolate, "ref"),
+ compatibility_new<FunctionTemplate>(isolate, ref)->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "unref"),
+ compatibility_new<FunctionTemplate>(isolate, unref)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "del"),
+ compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "sender_get"),
+ compatibility_new<FunctionTemplate>(isolate, sender_get)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "path_get"),
+ compatibility_new<FunctionTemplate>(isolate, path_get)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "interface_get"),
+ compatibility_new<FunctionTemplate>(isolate, interface_get)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "member_get"),
+ compatibility_new<FunctionTemplate>(isolate, member_get)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "match_get"),
+ compatibility_new<FunctionTemplate>(isolate, match_get)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "connection_get"),
+ compatibility_new<FunctionTemplate>(isolate, connection_get)
+ ->GetFunction());
+
+ compatibility_set_pointer_internal_field(ret, 0, handler);
+ compatibility_set_pointer_internal_field(ret, 1, persistent);
+
+ return ret;
+}
+
+static
+v8::Local<v8::Object> wrap_object_event_callback(Eldbus_Object *obj,
+ Eldbus_Object_Event_Type type,
+ Eldbus_Object_Event_Cb cb,
+ void *cb_data,
+ v8::Isolate *isolate)
+{
+ using v8::String;
+ using v8::Integer;
+ using v8::Value;
+ using v8::Object;
+ using v8::ObjectTemplate;
+ using v8::FunctionTemplate;
+
+ auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
+ obj_tpl->SetInternalFieldCount(3);
+ auto ret = obj_tpl->NewInstance();
+
+ ret->Set(compatibility_new<String>(isolate, "_type"),
+ compatibility_new<Integer>(isolate, type));
+
+ compatibility_set_pointer_internal_field(ret, 0, obj);
+ compatibility_set_pointer_internal_field(ret, 1, (void*)(cb));
+ compatibility_set_pointer_internal_field(ret, 2, cb_data);
+
+ auto del = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ auto o = info.This();
+ auto isolate = info.GetIsolate();
+
+ auto obj
+ = (compatibility_get_pointer_internal_field<Eldbus_Object*>
+ (o, 0));
+ auto cb
+ = (compatibility_get_pointer_internal_field
+ <Eldbus_Object_Event_Cb>(o, 1));
+ auto cb_data
+ = (compatibility_get_pointer_internal_field
+ <efl::eina::js::global_ref<Value>*>(o, 2));
+ auto type
+ = (static_cast<Eldbus_Object_Event_Type>
+ (o->Get(compatibility_new<String>(isolate, "_type"))
+ ->IntegerValue()));
+
+ eldbus_object_event_callback_del(obj, type, cb, cb_data);
+
+ delete cb_data;
+ return compatibility_return();
+ };
+
+ ret->Set(compatibility_new<String>(isolate, "del"),
+ compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
+
+ return ret;
+}
+
+inline
+Eldbus_Object *extract_eldbus_object(v8::Local<v8::Object> o)
+{
+ return compatibility_get_pointer_internal_field<Eldbus_Object*>(o, 0);
+}
+
+inline
+v8::Local<v8::Object> wrap_eldbus_object(Eldbus_Object *object,
+ v8::Isolate *isolate)
+{
+ using v8::String;
+ using v8::Value;
+ using v8::Handle;
+ using v8::Function;
+ using v8::ObjectTemplate;
+ using v8::FunctionTemplate;
+ using std::unique_ptr;
+
+ typedef efl::eina::js::global_ref<Value> persistent_t;
+
+ auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
+ obj_tpl->SetInternalFieldCount(1);
+ auto ret = obj_tpl->NewInstance();
+
+ auto ref = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto object = extract_eldbus_object(info.This());
+
+ eldbus_object_ref(object);
+ return compatibility_return();
+ };
+
+ auto unref = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto object = extract_eldbus_object(info.This());
+
+ eldbus_object_unref(object);
+ return compatibility_return();
+ };
+
+ auto event_callback_add = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 2 || !info[0]->IsNumber()
+ || !info[1]->IsFunction()) {
+ return compatibility_return();
+ }
+
+ Eldbus_Object_Event_Type type;
+
+ switch (info[0]->IntegerValue()) {
+ case ELDBUS_OBJECT_EVENT_IFACE_ADDED:
+ type = ELDBUS_OBJECT_EVENT_IFACE_ADDED;
+ break;
+ case ELDBUS_OBJECT_EVENT_IFACE_REMOVED:
+ type = ELDBUS_OBJECT_EVENT_IFACE_REMOVED;
+ break;
+ case ELDBUS_OBJECT_EVENT_PROPERTY_CHANGED:
+ type = ELDBUS_OBJECT_EVENT_PROPERTY_CHANGED;
+ break;
+ case ELDBUS_OBJECT_EVENT_PROPERTY_REMOVED:
+ type = ELDBUS_OBJECT_EVENT_PROPERTY_REMOVED;
+ break;
+ case ELDBUS_OBJECT_EVENT_DEL:
+ type = ELDBUS_OBJECT_EVENT_DEL;
+ break;
+ case ELDBUS_OBJECT_EVENT_LAST:
+ type = ELDBUS_OBJECT_EVENT_LAST;
+ break;
+ default:
+ return compatibility_return();
+ }
+
+ auto isolate = info.GetIsolate();
+
+ unique_ptr<persistent_t> cb_data{new persistent_t{isolate, info[1]}};
+
+ auto cb = [](void *data, Eldbus_Object *obj, void */*event_info*/) {
+ auto persistent = reinterpret_cast<persistent_t*>(data);
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args{wrap_eldbus_object(obj, isolate)};
+
+ Function::Cast(*o)->Call(o->ToObject(), 1, &args);
+ };
+
+ auto object = extract_eldbus_object(info.This());
+
+ eldbus_object_event_callback_add(object, type, cb, cb_data.get());
+ auto ret = wrap_object_event_callback(object, type, cb,
+ cb_data.release(), isolate);
+ return compatibility_return(ret, info);
+ };
+
+ auto connection_get = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = info.GetIsolate();
+ auto object = extract_eldbus_object(info.This());
+
+ auto conn = eldbus_object_connection_get(object);
+ return compatibility_return(wrap_eldbus_connection(conn, isolate),
+ info);
+ };
+
+ auto bus_name_get = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = info.GetIsolate();
+ auto object = extract_eldbus_object(info.This());
+
+ auto ret = eldbus_object_bus_name_get(object);
+ return compatibility_return(compatibility_new<String>(isolate, ret),
+ info);
+ };
+
+ auto path_get = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = info.GetIsolate();
+ auto object = extract_eldbus_object(info.This());
+
+ auto ret = eldbus_object_path_get(object);
+ return compatibility_return(compatibility_new<String>(isolate, ret),
+ info);
+ };
+
+ auto send = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 3 || !info[0]->IsObject() || !info[1]->IsFunction()
+ || !info[2]->IsNumber()) {
+ return compatibility_return();
+ }
+
+ auto isolate = info.GetIsolate();
+ auto obj = extract_eldbus_object(info.This());
+ auto msg
+ = (compatibility_get_pointer_internal_field<Eldbus_Message*>
+ (info[0]->ToObject(), 0));
+
+ unique_ptr<persistent_t> cb_data{new persistent_t{isolate, info[1]}};
+
+ auto cb = [](void *data, const Eldbus_Message *msg,
+ Eldbus_Pending *pending) {
+ auto persistent = reinterpret_cast<persistent_t*>(data);
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args[2] = {
+ wrap_const_eldbus_msg(msg, isolate),
+ wrap_eldbus_pending(pending, persistent, isolate)
+ };
+
+ Function::Cast(*o)->Call(o->ToObject(), 2, args);
+
+ delete persistent;
+ };
+
+ auto ret = eldbus_object_send(obj, msg, cb, cb_data.get(),
+ info[2]->NumberValue());
+ return compatibility_return(wrap_eldbus_pending(ret, cb_data.release(),
+ isolate),
+ info);
+ };
+
+ auto signal_handler_add = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 3 || !info[0]->IsString() || !info[1]->IsString()
+ || !info[2]->IsFunction()) {
+ return compatibility_return();
+ }
+
+ auto isolate = info.GetIsolate();
+ auto object = extract_eldbus_object(info.This());
+ String::Utf8Value interface(info[0]);
+ String::Utf8Value member(info[1]);
+
+ unique_ptr<persistent_t> cb_data{new persistent_t{isolate, info[2]}};
+
+ auto cb = [](void *data, const Eldbus_Message *msg) {
+ auto persistent = reinterpret_cast<persistent_t*>(data);
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args{wrap_const_eldbus_msg(msg, isolate)};
+
+ Function::Cast(*o)->Call(o->ToObject(), 1, &args);
+ };
+
+ auto ret = eldbus_object_signal_handler_add(object, *interface, *member,
+ cb, cb_data.get());
+ return
+ compatibility_return(wrap_eldbus_signal_handler(ret,
+ cb_data.release(),
+ isolate),
+ info);
+ };
+
+ auto method_call_new = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 2 || !info[0]->IsString()
+ || !info[1]->IsString()) {
+ return compatibility_return();
+ }
+
+ auto isolate = info.GetIsolate();
+ auto object = extract_eldbus_object(info.This());
+ auto ret = eldbus_object_method_call_new(object,
+ *String::Utf8Value(info[0]),
+ *String::Utf8Value(info[1]));
+ return compatibility_return(wrap_eldbus_msg(ret, isolate), info);
+ };
+
+ ret->Set(compatibility_new<String>(isolate, "ref"),
+ compatibility_new<FunctionTemplate>(isolate, ref)->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "unref"),
+ compatibility_new<FunctionTemplate>(isolate, unref)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "event_callback_add"),
+ compatibility_new<FunctionTemplate>(isolate, event_callback_add)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "connection_get"),
+ compatibility_new<FunctionTemplate>(isolate, connection_get)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "bus_name_get"),
+ compatibility_new<FunctionTemplate>(isolate, bus_name_get)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "path_get"),
+ compatibility_new<FunctionTemplate>(isolate, path_get)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "send"),
+ compatibility_new<FunctionTemplate>(isolate, send)->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "signal_handler_add"),
+ compatibility_new<FunctionTemplate>(isolate, signal_handler_add)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "method_call_new"),
+ compatibility_new<FunctionTemplate>(isolate, method_call_new)
+ ->GetFunction());
+
+ compatibility_set_pointer_internal_field(ret, 0, object);
+
+ return ret;
+}
+
+} } } // namespace efl { namespace eldbus { namespace js {
+
+#endif /* ELDBUS_JS_UTIL_HH */
diff --git a/src/bindings/eo_cxx/eo_concrete.hh b/src/bindings/eo_cxx/eo_concrete.hh
index 9e328b1d92..c975bbc5e3 100644
--- a/src/bindings/eo_cxx/eo_concrete.hh
+++ b/src/bindings/eo_cxx/eo_concrete.hh
@@ -187,6 +187,13 @@ struct concrete
Eo* _eo_raw; ///< The opaque <em>EO Object</em>.
};
+template<class CharT, class Traits>
+inline std::basic_ostream<CharT, Traits>&
+operator<<(std::basic_ostream<CharT, Traits>& os, concrete const& eo)
+{
+ return os << eo._eo_ptr();
+}
+
inline bool operator==(concrete const& lhs, concrete const& rhs)
{
return lhs._eo_ptr() == rhs._eo_ptr();
diff --git a/src/bindings/eo_js/Eo_Js.hh b/src/bindings/eo_js/Eo_Js.hh
new file mode 100644
index 0000000000..ab08b9886e
--- /dev/null
+++ b/src/bindings/eo_js/Eo_Js.hh
@@ -0,0 +1,15 @@
+#ifndef EFL_EO_JS_HH
+#define EFL_EO_JS_HH
+
+#include <Eina_Js.hh>
+
+#include <eo_js_direction.hh>
+#include <eo_js_constructor.hh>
+#include <eo_js_call_function.hh>
+#include <eo_js_event.hh>
+#include <eo_js_namespace.hh>
+#include <eo_js_struct.hh>
+#include <eo_js_construct_from_eo.hh>
+
+#endif
+
diff --git a/src/bindings/eo_js/eo_js_call_function.hh b/src/bindings/eo_js/eo_js_call_function.hh
new file mode 100644
index 0000000000..26bf03f862
--- /dev/null
+++ b/src/bindings/eo_js/eo_js_call_function.hh
@@ -0,0 +1,288 @@
+#ifndef EFL_EO_JS_CALL_FUNCTION_HH
+#define EFL_EO_JS_CALL_FUNCTION_HH
+
+#include <eina_tuple.hh>
+#include <eina_tuple_c.hh>
+#include <eina_function.hh>
+
+#include <cstdlib>
+#include <functional>
+#include <iostream>
+#include <cassert>
+#include <vector>
+
+namespace efl { namespace eo { namespace js {
+
+inline eina::js::compatibility_return_type call_function(eina::js::compatibility_callback_info_type args)
+{
+ void* data = v8::External::Cast(*args.Data())->Value();
+ std::function<eina::js::compatibility_return_type(eina::js::compatibility_callback_info_type)>*
+ f = static_cast<std::function<eina::js::compatibility_return_type(eina::js::compatibility_callback_info_type)>*>(data);
+ return (*f)(args);
+}
+
+template <typename In, std::size_t I>
+struct is_in : eina::_mpl::tuple_contains<std::integral_constant<std::size_t, I>, In>
+{};
+
+template <typename In, std::size_t I>
+struct arg_index : std::integral_constant<std::size_t,
+ std::conditional<is_in<In, I>::value, std::integral_constant<std::size_t, 1>, std::integral_constant<std::size_t, 0>>::type::value +
+ arg_index<In, I - 1>::value>
+{};
+
+template <typename In>
+struct arg_index<In, 0> : std::integral_constant<std::size_t, 0>
+{};
+
+template <typename In, typename Out, typename Ownership, typename F, typename Return, typename Parameters>
+struct method_caller
+{
+ typedef typename eina::_mpl::function_params<F>::type parameters_t;
+
+ template <std::size_t I>
+ struct is_out : eina::_mpl::tuple_contains<std::integral_constant<std::size_t, I>, Out>
+ {};
+
+ template <std::size_t I>
+ struct is_inout : std::integral_constant<bool,
+ eina::_mpl::tuple_contains<std::integral_constant<std::size_t, I>, Out>::value &&
+ eina::_mpl::tuple_contains<std::integral_constant<std::size_t, I>, In>::value>
+ {};
+
+ template <std::size_t I, typename Outs>
+ static
+ typename std::tuple_element<I, parameters_t>::type
+ get_value(eina::js::compatibility_callback_info_type args, Outs& /*outs*/, v8::Isolate* isolate, char const* class_name
+ , std::false_type)
+ {
+ using Param = typename std::tuple_element<I, Parameters>::type;
+ const auto js_index = arg_index<In, I>::value;
+
+ return eina::js::get_value_from_javascript
+ (args[js_index], isolate, class_name, eina::js::value_tag<Param>());
+ }
+
+ template <std::size_t I, typename Outs>
+ static
+ typename std::add_pointer<
+ typename std::tuple_element
+ <eina::_mpl::tuple_find<std::integral_constant<std::size_t, I>, Out>::value
+ , Outs>::type>::type
+ get_value(eina::js::compatibility_callback_info_type, Outs& outs, v8::Isolate*, char const*
+ , std::true_type)
+ {
+ return &std::get<eina::_mpl::tuple_find<std::integral_constant<std::size_t, I>, Out>::value>
+ (outs);
+ }
+
+ template <typename OutParameter, std::size_t I, typename R>
+ eina::js::compatibility_return_type
+ create_return_unique_value(eina::js::compatibility_callback_info_type args
+ , R const& r) const
+ {
+ return eina::js::compatibility_return(
+ eina::js::get_value_from_c(
+ eina::js::wrap_value<OutParameter>(r, eina::js::value_tag<OutParameter>{}),
+ args.GetIsolate(),
+ class_names[I]),
+ args);
+ }
+
+ template <typename OutParameters, typename Outs>
+ eina::js::compatibility_return_type
+ create_return_value(eina::js::compatibility_callback_info_type args
+ , Outs const& outs
+ , typename std::enable_if<std::tuple_size<Outs>::value == 1>::type* = 0) const
+ {
+ using OutParameter = typename std::tuple_element<0, OutParameters>::type;
+ return create_return_unique_value<OutParameter, std::tuple_element<0, Out>::type::value>(args, std::get<0u>(outs));
+ }
+
+ template <typename OutParameters, typename Outs>
+ eina::js::compatibility_return_type
+ create_return_value(eina::js::compatibility_callback_info_type
+ , Outs const&
+ , typename std::enable_if<std::tuple_size<Outs>::value == 0>::type* = 0) const
+ {
+ // nothing
+ return eina::js::compatibility_return();
+ }
+
+ template <typename OutParameters, typename Outs>
+ eina::js::compatibility_return_type
+ create_return_value(eina::js::compatibility_callback_info_type args
+ , Outs const& outs
+ , typename std::enable_if<(std::tuple_size<Outs>::value > 1)>::type* = 0) const
+ {
+ v8::Isolate* isolate = args.GetIsolate();
+ int const length = std::tuple_size<Outs>::value;
+ v8::Local<v8::Array> ret = eina::js::compatibility_new<v8::Array>(isolate, length);
+ set_return<OutParameters, 0u>(isolate, ret, outs, eina::make_index_sequence<std::tuple_size<Outs>::value>());
+ return eina::js::compatibility_return(ret, args);
+ }
+
+ template <typename OutParameters, typename R, typename Outs>
+ eina::js::compatibility_return_type
+ create_return_value(eina::js::compatibility_callback_info_type args
+ , R const& r
+ , Outs const&
+ , typename std::enable_if<std::tuple_size<Outs>::value == 0>::type* = 0) const
+ {
+ return create_return_unique_value<Return, std::tuple_size<Ownership>::value>(args, r);
+ }
+
+ template <typename OutParameters, std::size_t Offset, typename Outs, std::size_t...S>
+ void set_return(v8::Isolate* isolate, v8::Local<v8::Array> r
+ , Outs const& outs, eina::index_sequence<S...>) const
+ {
+ std::initializer_list<int> l
+ = {(r->Set(S+Offset, eina::js::get_value_from_c(
+ eina::js::wrap_value<typename std::tuple_element<S, OutParameters>::type>(std::get<S>(outs), eina::js::value_tag<typename std::tuple_element<S, OutParameters>::type>{}),
+ isolate,
+ class_names[std::tuple_element<S, Out>::type::value])),0)...};
+ static_cast<void>(l);
+ }
+
+ template <typename OutParameters, typename R, typename Outs>
+ eina::js::compatibility_return_type
+ create_return_value(eina::js::compatibility_callback_info_type args
+ , R const& r
+ , Outs const& outs
+ , typename std::enable_if<std::tuple_size<Outs>::value != 0>::type* = 0) const
+ {
+ v8::Isolate* isolate = args.GetIsolate();
+ int const length = std::tuple_size<Outs>::value + 1;
+ v8::Local<v8::Array> ret = eina::js::compatibility_new<v8::Array>(isolate, length);
+ ret->Set(0, eina::js::get_value_from_c(
+ eina::js::wrap_value<Return>(r, eina::js::value_tag<Return>{}),
+ isolate,
+ class_names[std::tuple_size<Ownership>::value]));
+ set_return<OutParameters, 1u>(isolate, ret, outs, eina::make_index_sequence<std::tuple_size<Outs>::value>());
+ return eina::js::compatibility_return(ret, args);
+ }
+
+ template <std::size_t I, typename Outs>
+ static void
+ init_inout(eina::js::compatibility_callback_info_type args
+ , Outs& outs
+ , v8::Isolate* isolate
+ , char const* class_name
+ , std::true_type)
+ {
+ using Param = typename std::remove_pointer<typename std::tuple_element<I, Parameters>::type>::type;
+
+ const auto js_index = arg_index<In, I>::value;
+
+ *get_value<I>(args, outs, args.GetIsolate(), class_name, std::true_type()) =
+ eina::js::get_value_from_javascript(args[js_index], isolate, class_name, eina::js::value_tag<Param>());;
+ }
+
+ template <std::size_t I, typename Outs>
+ static void
+ init_inout(eina::js::compatibility_callback_info_type
+ , Outs&
+ , v8::Isolate*
+ , char const*
+ , std::false_type)
+ {
+ }
+
+ template <typename OutParameters, std::size_t... I>
+ eina::js::compatibility_return_type
+ aux(eina::js::compatibility_callback_info_type args, eina::index_sequence<I...>
+ , std::true_type) const
+ {
+ typename eina::_mpl::tuple_transform<Out, out_transform<parameters_t> >::type outs {};
+ static_cast<void>(outs);
+
+ std::initializer_list<int> l =
+ {(init_inout<I>(args, outs, args.GetIsolate(), class_names[I], typename is_inout<I>::type()), 0)...};
+ static_cast<void>(l);
+
+ function(get_value<I>(args, outs, args.GetIsolate(), class_names[I], typename is_out<I>::type())...);
+ return create_return_value<OutParameters>(args, outs);
+ }
+
+ template <typename OutParameters, std::size_t... I>
+ eina::js::compatibility_return_type
+ aux(eina::js::compatibility_callback_info_type args, eina::index_sequence<I...>
+ , std::false_type) const
+ {
+ typename eina::_mpl::tuple_transform<Out, out_transform<parameters_t> >::type outs {};
+ static_cast<void>(outs);
+
+ std::initializer_list<int> l =
+ {(init_inout<I>(args, outs, args.GetIsolate(), class_names[I], typename is_inout<I>::type()), 0)...};
+ static_cast<void>(l);
+
+ typename eina::_mpl::function_return<F>::type r =
+ function(get_value<I>(args, outs, args.GetIsolate(), class_names[I], typename is_out<I>::type())...);
+ return create_return_value<OutParameters>(args, r, outs);
+ }
+
+ template <typename P>
+ struct out_transform
+ {
+ template <typename T>
+ struct apply
+ {
+ typedef typename std::remove_pointer<typename std::tuple_element<T::value, P>::type>::type type;
+ };
+ };
+
+ eina::js::compatibility_return_type operator()(eina::js::compatibility_callback_info_type args)
+ {
+ using OutParameters = typename eina::_mpl::tuple_transform<Out, out_transform<Parameters> >::type;
+
+ int input_parameters = std::tuple_size<In>::value;
+ if(input_parameters <= args.Length())
+ {
+ 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());
+ try
+ {
+ eo_do
+ (eo,
+ aux<OutParameters>(
+ args,
+ eina::make_index_sequence<std::tuple_size<parameters_t>::value>(),
+ std::is_same<void, Return>())
+ );
+ }
+ catch(std::logic_error const&)
+ {
+ return eina::js::compatibility_return();
+ }
+ }
+ else
+ {
+ return eina::js::compatibility_throw
+ (v8::Exception::TypeError
+ (eina::js::compatibility_new<v8::String>(nullptr, "Expected more arguments for this call")));
+ }
+ }
+
+ template <typename A>
+ method_caller(F f, A&& c)
+ : function(f)
+ , class_names(std::forward<A>(c))
+ {}
+
+ F function;
+ /// Hold the names of the type of each argument, with the return's type name at the end
+ std::array<const char*, std::tuple_size<Ownership>::value + 1> class_names;
+};
+
+template <typename In, typename Out, typename Ownership, typename Return, typename Parameters, std::size_t N, typename F>
+v8::Handle<v8::Value> call_function_data(v8::Isolate* isolate, std::array<const char*, N> class_names, F f)
+{
+ return eina::js::compatibility_new<v8::External>
+ (isolate, new std::function<eina::js::compatibility_return_type(eina::js::compatibility_callback_info_type const&)>
+ (method_caller<In, Out, Ownership, F, Return, Parameters>{f, class_names}));
+}
+
+} } }
+
+#endif
diff --git a/src/bindings/eo_js/eo_js_construct_from_eo.hh b/src/bindings/eo_js/eo_js_construct_from_eo.hh
new file mode 100644
index 0000000000..287aaa748c
--- /dev/null
+++ b/src/bindings/eo_js/eo_js_construct_from_eo.hh
@@ -0,0 +1,39 @@
+#ifndef EFL_EO_JS_CONSTRUCT_FROM_EO_HH
+#define EFL_EO_JS_CONSTRUCT_FROM_EO_HH
+
+#include <eina_tuple.hh>
+#include <eina_tuple_c.hh>
+#include <eina_function.hh>
+#include <Eo.h>
+
+#include <cstdlib>
+#include <functional>
+#include <iostream>
+#include <cassert>
+#include <vector>
+
+namespace efl { namespace eo { namespace js {
+
+inline eina::js::compatibility_return_type construct_from_eo(eina::js::compatibility_callback_info_type args)
+{
+ if(args.IsConstructCall())
+ {
+ Eo* eo = static_cast<Eo*>(v8::External::Cast(*args[0])->Value());
+ args.This()->SetInternalField(0, args[0]);
+ efl::eina::js::make_weak(args.GetIsolate(), args.This(), [eo] { eo_unref(eo); });
+ return eina::js::compatibility_return();
+ }
+ else
+ {
+ std::size_t argc = args.Length();
+ std::vector<v8::Local<v8::Value> > argv (argc ? argc : 1 );
+ for(int i = 0; i != args.Length(); ++i)
+ argv[i] = args[i];
+ args.Callee()->NewInstance(argc, &argv[0]);
+ return eina::js::compatibility_return();
+ }
+}
+
+} } }
+
+#endif
diff --git a/src/bindings/eo_js/eo_js_constructor.hh b/src/bindings/eo_js/eo_js_constructor.hh
new file mode 100644
index 0000000000..09cc9dce71
--- /dev/null
+++ b/src/bindings/eo_js/eo_js_constructor.hh
@@ -0,0 +1,136 @@
+#ifndef EFL_EO_JS_CONSTRUCTOR_HH
+#define EFL_EO_JS_CONSTRUCTOR_HH
+
+#include <Eina.hh>
+
+#include <eina_tuple.hh>
+#include <eina_function.hh>
+#include <Eo.h>
+
+#include <cstdlib>
+#include <functional>
+#include <iostream>
+#include <cassert>
+#include <vector>
+
+namespace efl { namespace eo { namespace js {
+
+inline eina::js::compatibility_return_type constructor(eina::js::compatibility_callback_info_type args)
+{
+ if(args.IsConstructCall())
+ {
+ void* data = v8::External::Cast(*args.Data())->Value();
+ std::function<eina::js::compatibility_return_type(eina::js::compatibility_callback_info_type)>*
+ f = static_cast<std::function<eina::js::compatibility_return_type(eina::js::compatibility_callback_info_type)>*>
+ (data);
+ return (*f)(args);
+ }
+ else
+ {
+ std::size_t argc = args.Length();
+ std::vector<v8::Local<v8::Value> > argv (argc ? argc : 1 );
+ for(int i = 0; i != args.Length(); ++i)
+ argv[i] = args[i];
+ args.Callee()->NewInstance(argc, &argv[0]);
+ return eina::js::compatibility_return();
+ }
+}
+
+template <typename...F>
+struct constructor_caller
+{
+ struct call
+ {
+ template <typename T>
+ void operator()(T function) const
+ {
+ int const parameters
+ = std::tuple_size<typename eina::_mpl::function_params<T>::type>::value;
+ if(*current + parameters <= args->Length())
+ {
+ aux(function, eina::make_index_sequence<parameters>());
+ *current += parameters;
+ }
+ 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("");
+ }
+ }
+
+ template <typename U, std::size_t I>
+ static
+ typename std::tuple_element<I, typename eina::_mpl::function_params<U>::type>::type
+ get_value(v8::Local<v8::Value> v, v8::Isolate* isolate)
+ {
+ typename std::tuple_element<I, typename eina::_mpl::function_params<U>::type>::type
+ tmp =
+ eina::js::get_value_from_javascript
+ (v, isolate, ""
+ , eina::js::value_tag<typename std::tuple_element
+ <I, typename eina::_mpl::function_params<U>::type>::type>());
+ return tmp;
+ }
+
+ template <typename T, std::size_t... I>
+ void aux(T function, eina::index_sequence<I...>) const
+ {
+ function(get_value<T, I>((*args)[I + *current], args->GetIsolate())...);
+ }
+
+ int* current;
+ eina::js::compatibility_callback_info_pointer args;
+ };
+
+ eina::js::compatibility_return_type operator()(eina::js::compatibility_callback_info_type args) const
+ {
+ int current_index = 1;
+ if(args.Length() != 0)
+ {
+ try
+ {
+ Eo* parent = eina::js::get_value_from_javascript
+ (args[0], args.GetIsolate(), "", eina::js::value_tag<Eo*>());
+ Eo* eo = eo_add
+ (klass
+ , parent
+ , eina::_mpl::for_each(constructors, call{&current_index, &args})
+ );
+ assert(eo != 0);
+ 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
+ , [eo]
+ {
+ eo_unref(eo);
+ });
+ }
+ catch(std::logic_error const&) {}
+ }
+ else
+ {
+ eina::js::compatibility_throw
+ (v8::Exception::TypeError
+ (eina::js::compatibility_new<v8::String>(args.GetIsolate(), "Expected at least one argument for this call")));
+ }
+ return eina::js::compatibility_return();
+ }
+
+ Eo_Class const* klass;
+ std::tuple<F...> constructors;
+};
+
+template <typename... F>
+v8::Handle<v8::Value> constructor_data(v8::Isolate* isolate, Eo_Class const* klass, F... f)
+{
+ return eina::js::compatibility_new<v8::External>
+ (isolate
+ , new std::function<eina::js::compatibility_return_type(eina::js::compatibility_callback_info_type)>
+ (constructor_caller<F...>{klass, std::tuple<F...>{f...}}));
+}
+
+} } }
+
+#endif
diff --git a/src/bindings/eo_js/eo_js_direction.hh b/src/bindings/eo_js/eo_js_direction.hh
new file mode 100644
index 0000000000..96cd07608c
--- /dev/null
+++ b/src/bindings/eo_js/eo_js_direction.hh
@@ -0,0 +1,12 @@
+#ifndef EFL_EO_JS_EO_JS_DIRECTION_HH
+#define EFL_EO_JS_EO_JS_DIRECTION_HH
+
+namespace efl { namespace eo { namespace js {
+
+struct input {};
+struct output {};
+struct input_output {};
+
+} } }
+
+#endif
diff --git a/src/bindings/eo_js/eo_js_event.hh b/src/bindings/eo_js/eo_js_event.hh
new file mode 100644
index 0000000000..ab2dd34fee
--- /dev/null
+++ b/src/bindings/eo_js/eo_js_event.hh
@@ -0,0 +1,126 @@
+#ifndef EFL_EO_JS_EVENT_HH
+#define EFL_EO_JS_EVENT_HH
+
+#include <eina_tuple.hh>
+#include <eina_tuple_c.hh>
+#include <eina_function.hh>
+#include <Eo.h>
+
+#include <cstdlib>
+#include <functional>
+#include <iostream>
+#include <cassert>
+#include <vector>
+
+namespace efl { namespace eo { namespace js {
+
+struct event_information
+{
+ eina::js::global_ref<v8::Function>* constructor;
+ Eo_Event_Description const* event;
+ Eo_Event_Cb event_callback;
+ const char* class_name;
+};
+
+typedef std::map<std::string, event_information*> event_information_map;
+
+struct event_callback_information
+{
+ event_information* event_info;
+ eina::js::global_ref<v8::Function> function;
+};
+
+template <typename T>
+v8::Local<v8::Value> get_event_info(void* event_info, v8::Isolate* isolate, const char* class_name)
+{
+ using no_tag_type = typename eina::js::remove_tag<T>::type;
+ return eina::js::get_value_from_c(
+ eina::js::wrap_value<T>(*static_cast<no_tag_type*>(event_info), eina::js::value_tag<T>{}),
+ isolate,
+ class_name);
+}
+
+// FIXME: This shouldn't be necessary. Reveiew Eolian standards.
+template <>
+inline v8::Local<v8::Value> get_event_info<const char*>(void* event_info, v8::Isolate* isolate, const char*)
+{
+ return eina::js::get_value_from_c(static_cast<const char*>(event_info), isolate, "");
+}
+
+template <>
+inline v8::Local<v8::Value> get_event_info<void>(void*, v8::Isolate* isolate, const char*)
+{
+ return v8::Undefined(isolate);
+}
+
+template <typename T>
+inline Eina_Bool event_callback(void* data, Eo* obj, Eo_Event_Description const*
+ , void* event_info)
+{
+ v8::Isolate* isolate = v8::Isolate::GetCurrent();
+ v8::HandleScope handle_scope(isolate);
+ event_callback_information* event = static_cast<event_callback_information*>(data);
+ v8::Handle<v8::Value> a[] = {eina::js::compatibility_new<v8::External>(isolate, obj)};
+ v8::Local<v8::Object> self = (event->event_info->constructor->handle())->NewInstance(1, a);
+
+ v8::Local<v8::Value> call_args[] = {
+ self,
+ get_event_info<T>(event_info, isolate, event->event_info->class_name)
+ };
+ event->function.handle()->Call(eina::js::compatibility_global(), 2, call_args);
+
+ return EO_CALLBACK_CONTINUE;
+}
+
+inline eina::js::compatibility_return_type on_event(eina::js::compatibility_callback_info_type args)
+{
+ if (args.Length() >= 2)
+ {
+ v8::Local<v8::Value> ev_name = args[0];
+ v8::Local<v8::Value> f = args[1];
+ if (ev_name->IsString() && f->IsFunction())
+ {
+ v8::Local<v8::Value> data = args.Data();
+ auto ev_map =
+ static_cast<event_information_map*>
+ (v8::External::Cast(*data)->Value());
+
+ v8::String::Utf8Value str(ev_name->ToString());
+ auto found = ev_map->find(*str);
+ if (found == ev_map->end())
+ return eina::js::compatibility_return();
+
+ auto event = found->second;
+
+ 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());
+
+ auto isolate = args.GetIsolate();
+
+ event_callback_information* i = new event_callback_information
+ {event, {isolate, eina::js::compatibility_cast<v8::Function>(f)}};
+ eo_do(eo, eo_event_callback_priority_add
+ (event->event, EO_CALLBACK_PRIORITY_DEFAULT, event->event_callback, i));
+ }
+ else
+ {
+ eina::js::compatibility_throw
+ (v8::Exception::TypeError
+ (eina::js::compatibility_new<v8::String>(args.GetIsolate(), "Invalid argument type")));
+ throw std::logic_error("");
+ }
+ }
+ 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("");
+ }
+ return eina::js::compatibility_return();
+}
+
+} } }
+
+#endif
diff --git a/src/bindings/eo_js/eo_js_namespace.hh b/src/bindings/eo_js/eo_js_namespace.hh
new file mode 100644
index 0000000000..4fe9d9b797
--- /dev/null
+++ b/src/bindings/eo_js/eo_js_namespace.hh
@@ -0,0 +1,24 @@
+#ifndef EFL_EO_JS_NAMESPACE_HH
+#define EFL_EO_JS_NAMESPACE_HH
+
+namespace efl { namespace eo { namespace js {
+
+inline
+v8::Local<v8::Object> get_namespace(std::vector<const char*> const& nss, v8::Isolate* isolate, v8::Local<v8::Object> to_export)
+{
+ for (auto ns : nss)
+ {
+ v8::Local<v8::Value> ns_obj = to_export->Get(::efl::eina::js::compatibility_new<v8::String>(isolate, ns));
+ if (ns_obj->IsUndefined() || ns_obj->IsNull())
+ {
+ ns_obj = ::efl::eina::js::compatibility_new<v8::Object>(isolate);
+ to_export->Set(::efl::eina::js::compatibility_new<v8::String>(isolate, ns), ns_obj);
+ }
+ to_export = ns_obj->ToObject();
+ }
+ return to_export;
+}
+
+} } }
+
+#endif
diff --git a/src/bindings/eo_js/eo_js_struct.hh b/src/bindings/eo_js/eo_js_struct.hh
new file mode 100644
index 0000000000..731f9d093c
--- /dev/null
+++ b/src/bindings/eo_js/eo_js_struct.hh
@@ -0,0 +1,106 @@
+#ifndef EFL_EO_JS_STRUCT_HH
+#define EFL_EO_JS_STRUCT_HH
+
+#include <eina_tuple.hh>
+#include <eina_tuple_c.hh>
+#include <eina_function.hh>
+#include <Eo.h>
+
+#include <cstdlib>
+#include <functional>
+#include <iostream>
+#include <cassert>
+#include <vector>
+
+namespace efl { namespace eo { namespace js {
+
+template <typename S, typename M, M S::*MPtr, typename K>
+eina::js::compatibility_accessor_getter_return_type
+get_struct_member(v8::Local<v8::String>, eina::js::compatibility_accessor_getter_callback_info_type info)
+{
+ v8::Local<v8::Object> self_obj = eina::js::compatibility_cast<v8::Object>(info.This());
+ auto sct = static_cast<S*>(eina::js::compatibility_get_pointer_internal_field(self_obj, 0));
+ return eina::js::compatibility_return(eina::js::get_value_from_c(sct->*MPtr, info.GetIsolate(), K::class_name()), info);
+}
+
+template <typename S, typename GenTag, typename M, M S::*MPtr, typename K>
+eina::js::compatibility_accessor_setter_return_type
+set_struct_member(v8::Local<v8::String>, v8::Local<v8::Value> value, eina::js::compatibility_accessor_setter_callback_info_type info)
+{
+ v8::Local<v8::Object> self_obj = eina::js::compatibility_cast<v8::Object>(info.This());
+ auto sct = static_cast<S*>(eina::js::compatibility_get_pointer_internal_field(self_obj, 0));
+ sct->*MPtr = eina::js::get_value_from_javascript(value, info.GetIsolate(), K::class_name(), eina::js::value_tag<GenTag>());
+}
+
+template <typename S>
+eina::js::compatibility_return_type new_struct(eina::js::compatibility_callback_info_type args)
+{
+ if (!args.IsConstructCall())
+ return eina::js::compatibility_throw
+ (nullptr, v8::Exception::TypeError
+ (eina::js::compatibility_new<v8::String>(nullptr, "Not constructor call")));
+
+ if(args.Length() == 0)
+ {
+ S* p = new S{};
+ eina::js::compatibility_set_pointer_internal_field(args.This(), 0, static_cast<void*>(p));
+ }
+ else
+ {
+ if (!args[0]->IsExternal())
+ return eina::js::compatibility_throw
+ (nullptr, v8::Exception::TypeError
+ (eina::js::compatibility_new<v8::String>(nullptr, "Invalid argument type for constructor call")));
+
+ S* p = reinterpret_cast<S*>(v8::External::Cast(*args[0])->Value());
+ eina::js::compatibility_set_pointer_internal_field(args.This(), 0, static_cast<void*>(p));
+ }
+
+ return eina::js::compatibility_return();
+}
+
+template <typename S, typename F>
+inline void register_struct_persistent(v8::Isolate* isolate, const char* name, const char* full_name, F&& fields_func)
+{
+ v8::Handle<v8::FunctionTemplate> constructor = eina::js::compatibility_new<v8::FunctionTemplate>(isolate, &efl::eo::js::new_struct<S>);
+ constructor->SetClassName(eina::js::compatibility_new<v8::String>(isolate, name));
+
+ v8::Local<v8::ObjectTemplate> instance_t = constructor->InstanceTemplate();
+ instance_t->SetInternalFieldCount(1);
+ v8::Local<v8::ObjectTemplate> prototype = constructor->PrototypeTemplate();
+
+ fields_func(isolate, prototype);
+
+ static efl::eina::js::global_ref<v8::ObjectTemplate> instance_persistent{isolate, instance_t};
+ static efl::eina::js::global_ref<v8::Function> instance_template{isolate, constructor->GetFunction()};
+ (void)instance_persistent;
+
+ eina::js::register_class_constructor(full_name, instance_template.handle());
+}
+
+template <typename S, typename F>
+void register_struct_exports(v8::Isolate* isolate, const char* name, v8::Handle<v8::Object> exports, F&& fields_func)
+{
+ v8::Handle<v8::FunctionTemplate> constructor = eina::js::compatibility_new<v8::FunctionTemplate>(isolate, &efl::eo::js::new_struct<S>);
+ constructor->SetClassName(eina::js::compatibility_new<v8::String>(isolate, name));
+
+ v8::Local<v8::ObjectTemplate> instance_t = constructor->InstanceTemplate();
+ instance_t->SetInternalFieldCount(1);
+ v8::Local<v8::ObjectTemplate> prototype = constructor->PrototypeTemplate();
+
+ fields_func(isolate, prototype);
+
+ exports->Set(eina::js::compatibility_new<v8::String>(isolate, name), constructor->GetFunction());
+}
+
+
+template <typename S, typename F>
+void register_struct(v8::Isolate* isolate, const char* name, const char* full_name, v8::Handle<v8::Object> exports, F&& fields_func)
+{
+ register_struct_persistent<S>(isolate, name, full_name, std::forward<F>(fields_func));
+ register_struct_exports<S>(isolate, name, exports, std::forward<F>(fields_func));
+}
+
+} } }
+
+#endif
diff --git a/src/bindings/ethumb_js/Ethumb_Js.hh b/src/bindings/ethumb_js/Ethumb_Js.hh
new file mode 100644
index 0000000000..39459708ae
--- /dev/null
+++ b/src/bindings/ethumb_js/Ethumb_Js.hh
@@ -0,0 +1,48 @@
+#ifndef ETHUMB_JS_INIT_HH
+#define ETHUMB_JS_INIT_HH
+
+#include <Eina.hh>
+
+#include <Eina_Js.hh>
+#include <Ethumb_Client.h>
+
+#ifdef EAPI
+# undef EAPI
+#endif
+
+#ifdef _WIN32
+# ifdef EFL_ETHUMB_JS_BUILD
+# ifdef DLL_EXPORT
+# define EAPI __declspec(dllexport)
+# else
+# define EAPI
+# endif /* ! DLL_EXPORT */
+# else
+# define EAPI __declspec(dllimport)
+# endif /* ! EFL_ETHUMB_JS_BUILD */
+#else
+# ifdef __GNUC__
+# if __GNUC__ >= 4
+# define EAPI __attribute__ ((visibility("default")))
+# else
+# define EAPI
+# endif
+# else
+# define EAPI
+# endif
+#endif /* ! _WIN32 */
+
+namespace efl { namespace ethumb { namespace js {
+
+using ::efl::eina::js::compatibility_new;
+using ::efl::eina::js::compatibility_return_type;
+using ::efl::eina::js::compatibility_callback_info_type;
+using ::efl::eina::js::compatibility_return;
+using ::efl::eina::js::compatibility_get_pointer_internal_field;
+using ::efl::eina::js::compatibility_set_pointer_internal_field;
+
+EAPI void register_ethumb(v8::Isolate *isolate, v8::Handle<v8::Object> exports);
+
+} } } // namespace efl { namespace ethumb { namespace js {
+
+#endif /* ETHUMB_JS_INIT_HH */
diff --git a/src/bindings/ethumb_js/ethumb_js_client.cc b/src/bindings/ethumb_js/ethumb_js_client.cc
new file mode 100644
index 0000000000..50aaee39a4
--- /dev/null
+++ b/src/bindings/ethumb_js/ethumb_js_client.cc
@@ -0,0 +1,571 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <Ethumb_Js.hh>
+
+namespace efl { namespace ethumb { namespace js {
+
+namespace {
+
+Ethumb_Exists* extract_ethumb_exists(v8::Local<v8::Object> object)
+{
+ return compatibility_get_pointer_internal_field<Ethumb_Exists*>(object, 0);
+}
+
+efl::eina::js::global_ref<v8::Value>*
+extract_ethumb_exists_cb(v8::Local<v8::Object> object)
+{
+ return compatibility_get_pointer_internal_field
+ <efl::eina::js::global_ref<v8::Value>*>(object, 1);
+}
+
+v8::Local<v8::Object> wrap_ethumb_exists(Ethumb_Exists *exists,
+ efl::eina::js::global_ref<v8::Value>*
+ cb,
+ v8::Isolate *isolate)
+{
+ using v8::String;
+ using v8::Boolean;
+ using v8::ObjectTemplate;
+ using v8::FunctionTemplate;
+
+ auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
+ obj_tpl->SetInternalFieldCount(2);
+ auto ret = obj_tpl->NewInstance();
+
+ auto cancel = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto exists = extract_ethumb_exists(info.This());
+ auto cb = extract_ethumb_exists_cb(info.This());
+
+ if (ethumb_client_thumb_exists_check(exists))
+ return compatibility_return();
+
+ delete cb;
+
+ ethumb_client_thumb_exists_cancel(exists);
+ return compatibility_return();
+ };
+
+ auto check = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = info.GetIsolate();
+ auto exists = extract_ethumb_exists(info.This());
+
+ auto ret = ethumb_client_thumb_exists_check(exists);
+
+ return compatibility_return(compatibility_new<Boolean>(isolate, ret),
+ info);
+ };
+
+ ret->Set(compatibility_new<String>(isolate, "cancel"),
+ compatibility_new<FunctionTemplate>(isolate, cancel)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "check"),
+ compatibility_new<FunctionTemplate>(isolate, check)
+ ->GetFunction());
+
+ compatibility_set_pointer_internal_field(ret, 0, exists);
+ compatibility_set_pointer_internal_field(ret, 1, cb);
+
+ return ret;
+}
+
+// ====================================================
+
+Ethumb_Client_Async* extract_ethumb_client_async(v8::Local<v8::Object> o)
+{
+ return compatibility_get_pointer_internal_field<Ethumb_Client_Async*>(o, 0);
+}
+
+efl::eina::js::global_ref<v8::Value>*
+extract_ethumb_client_async_cb(v8::Local<v8::Object> object)
+{
+ return compatibility_get_pointer_internal_field
+ <efl::eina::js::global_ref<v8::Value>*>(object, 1);
+}
+
+Ethumb_Client* extract_ethumb_client_async_client(v8::Local<v8::Object> o)
+{
+ return compatibility_get_pointer_internal_field<Ethumb_Client*>(o, 0);
+}
+
+v8::Local<v8::Object>
+wrap_ethumb_client_async(Ethumb_Client_Async *request,
+ efl::eina::js::global_ref<v8::Value>* cb,
+ Ethumb_Client *client,
+ v8::Isolate *isolate)
+{
+ using v8::String;
+ using v8::Boolean;
+ using v8::ObjectTemplate;
+ using v8::FunctionTemplate;
+
+ auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
+ obj_tpl->SetInternalFieldCount(3);
+ auto ret = obj_tpl->NewInstance();
+
+ auto cancel = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto request = extract_ethumb_client_async(info.This());
+ auto cb = extract_ethumb_client_async_cb(info.This());
+ auto client = extract_ethumb_client_async_client(info.This());
+
+ delete cb;
+
+ ethumb_client_thumb_async_cancel(client, request);
+ return compatibility_return();
+ };
+
+ ret->Set(compatibility_new<String>(isolate, "cancel"),
+ compatibility_new<FunctionTemplate>(isolate, cancel)
+ ->GetFunction());
+
+ compatibility_set_pointer_internal_field(ret, 0, request);
+ compatibility_set_pointer_internal_field(ret, 1, cb);
+ compatibility_set_pointer_internal_field(ret, 2, client);
+
+ return ret;
+}
+
+Ethumb_Client* extract_ethumb_client(v8::Local<v8::Object> object)
+{
+ return compatibility_get_pointer_internal_field<Ethumb_Client*>(object, 0);
+}
+
+v8::Local<v8::Object> wrap_ethumb_client(Ethumb_Client *client,
+ v8::Isolate *isolate)
+{
+ using v8::Integer;
+ using v8::String;
+ using v8::Boolean;
+ using v8::Value;
+ using v8::Object;
+ using v8::ObjectTemplate;
+ using v8::Handle;
+ using v8::Function;
+ using v8::FunctionTemplate;
+ using std::unique_ptr;
+
+ typedef efl::eina::js::global_ref<Value> persistent_t;
+
+ auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
+ obj_tpl->SetInternalFieldCount(1);
+ auto ret = obj_tpl->NewInstance();
+
+ auto disconnect = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ ethumb_client_disconnect(extract_ethumb_client(info.This()));
+ return compatibility_return();
+ };
+
+ auto on_server_die_callback_set = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 1 || !info[0]->IsFunction())
+ return compatibility_return();
+
+ auto isolate = info.GetIsolate();
+
+ unique_ptr<persistent_t> cb_data{new persistent_t(isolate, info[0])};
+
+ auto client = extract_ethumb_client(info.This());
+ auto server_die_cb = [](void *data, Ethumb_Client *client) {
+ auto persistent = reinterpret_cast<persistent_t*>(data);
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args{wrap_ethumb_client(client, isolate)};
+
+ Function::Cast(*o)->Call(o->ToObject(), 1, &args);
+ };
+ auto free_data = [](void *data) {
+ auto persistent = reinterpret_cast<persistent_t*>(data);
+ delete persistent;
+ };
+
+ ethumb_client_on_server_die_callback_set(client, server_die_cb,
+ cb_data.release(), free_data);
+ return compatibility_return();
+ };
+
+ auto file_set = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 2 || !info[0]->IsString() || !info[1]->IsString())
+ return compatibility_return();
+
+ auto isolate = info.GetIsolate();
+
+ auto ret = ethumb_client_file_set(extract_ethumb_client(info.This()),
+ *String::Utf8Value(info[0]),
+ *String::Utf8Value(info[1]));
+ return compatibility_return(compatibility_new<Boolean>(isolate, ret),
+ info);
+ };
+
+ auto file_get = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = info.GetIsolate();
+
+ auto ret = compatibility_new<Object>(isolate);
+ const char *path;
+ const char *key;
+
+ ethumb_client_file_get(extract_ethumb_client(info.This()), &path, &key);
+
+ ret->Set(compatibility_new<String>(isolate, "path"),
+ compatibility_new<String>(isolate, path));
+ ret->Set(compatibility_new<String>(isolate, "key"),
+ compatibility_new<String>(isolate, key));
+
+ return compatibility_return(ret, info);
+ };
+
+ auto file_free = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ ethumb_client_file_free(extract_ethumb_client(info.This()));
+
+ return compatibility_return();
+ };
+
+ auto thumb_exists = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 1 || !info[0]->IsFunction())
+ return compatibility_return();
+
+ auto isolate = info.GetIsolate();
+
+ unique_ptr<persistent_t> cb_data{new persistent_t(isolate, info[0])};
+
+ auto client = extract_ethumb_client(info.This());
+ auto exists_cb = [](void *data, Ethumb_Client *client,
+ Ethumb_Exists *thread, Eina_Bool exists) {
+ auto persistent = reinterpret_cast<persistent_t*>(data);
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args[3] = {
+ wrap_ethumb_client(client, isolate),
+ wrap_ethumb_exists(thread, NULL, isolate),
+ compatibility_new<Boolean>(isolate, exists)
+ };
+
+ Function::Cast(*o)->Call(o->ToObject(), 3, args);
+
+ delete persistent;
+ };
+
+ auto ret = ethumb_client_thumb_exists(client, exists_cb,
+ cb_data.get());
+ return compatibility_return(wrap_ethumb_exists(ret, cb_data.release(),
+ isolate),
+ info);
+ };
+
+ auto generate = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 1 || !info[0]->IsFunction())
+ return compatibility_return();
+
+ auto isolate = info.GetIsolate();
+
+ unique_ptr<persistent_t> cb_data{new persistent_t(isolate, info[0])};
+
+ auto client = extract_ethumb_client(info.This());
+ auto generated_cb = [](void *data, Ethumb_Client *client, int id,
+ const char *file, const char *key,
+ const char *thumb_path, const char *thumb_key,
+ Eina_Bool success) {
+ auto persistent = reinterpret_cast<persistent_t*>(data);
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args[7] = {
+ wrap_ethumb_client(client, isolate),
+ compatibility_new<Integer>(isolate, id),
+ compatibility_new<String>(isolate, file),
+ compatibility_new<String>(isolate, key),
+ compatibility_new<String>(isolate, thumb_path),
+ compatibility_new<String>(isolate, thumb_key),
+ compatibility_new<Boolean>(isolate, success)
+ };
+
+ Function::Cast(*o)->Call(o->ToObject(), 7, args);
+ };
+ auto free_data = [](void *data) {
+ auto persistent = reinterpret_cast<persistent_t*>(data);
+ delete persistent;
+ };
+
+ auto ret = ethumb_client_generate(client, generated_cb,
+ cb_data.release(), free_data);
+ return compatibility_return(compatibility_new<Integer>(isolate, ret),
+ info);
+ };
+
+ auto generate_cancel = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 2 || !info[0]->IsNumber()
+ || !info[1]->IsFunction()) {
+ return compatibility_return();
+ }
+
+ auto isolate = info.GetIsolate();
+
+ unique_ptr<persistent_t> cb_data{new persistent_t(isolate, info[1])};
+
+ auto client = extract_ethumb_client(info.This());
+ auto cancel_cb = [](void *data, Eina_Bool success) {
+ auto persistent = reinterpret_cast<persistent_t*>(data);
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args{compatibility_new<Boolean>(isolate, success)};
+
+ Function::Cast(*o)->Call(o->ToObject(), 1, &args);
+ };
+ auto free_data = [](void *data) {
+ auto persistent = reinterpret_cast<persistent_t*>(data);
+ delete persistent;
+ };
+
+ ethumb_client_generate_cancel(client, info[0]->IntegerValue(),
+ cancel_cb, cb_data.release(), free_data);
+ return compatibility_return();
+ };
+
+ auto generate_cancel_all = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 1 || !info[0]->IsFunction())
+ return compatibility_return();
+
+ auto client = extract_ethumb_client(info.This());
+
+ ethumb_client_generate_cancel_all(client);
+ return compatibility_return();
+ };
+
+ auto thumb_async_get = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 1 || !info[0]->IsFunction())
+ return compatibility_return();
+
+ auto isolate = info.GetIsolate();
+
+ unique_ptr<persistent_t> cb_data{new persistent_t(isolate, info[0])};
+
+ auto client = extract_ethumb_client(info.This());
+ auto done_cb = [](Ethumb_Client *client, const char *thumb_path,
+ const char *thumb_key, void *data) {
+ auto persistent = reinterpret_cast<persistent_t*>(data);
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args[3] = {
+ wrap_ethumb_client(client, isolate),
+ compatibility_new<String>(isolate, thumb_path),
+ compatibility_new<String>(isolate, thumb_key)
+ };
+
+ Function::Cast(*o)->Call(o->ToObject(), 3, args);
+
+ delete persistent;
+ };
+ auto error_cb = [](Ethumb_Client *client, void *data) {
+ auto persistent = reinterpret_cast<persistent_t*>(data);
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args{wrap_ethumb_client(client, isolate)};
+
+ Function::Cast(*o)->Call(o->ToObject(), 1, &args);
+
+ delete persistent;
+ };
+
+ auto ret = ethumb_client_thumb_async_get(client, done_cb, error_cb,
+ cb_data.get());
+ auto wrapped_ret = wrap_ethumb_client_async(ret, cb_data.release(),
+ client, isolate);
+ return compatibility_return(wrapped_ret, info);
+ };
+
+ ret->Set(compatibility_new<String>(isolate, "disconnect"),
+ compatibility_new<FunctionTemplate>(isolate, disconnect)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "on_server_die_callback_set"),
+ compatibility_new<FunctionTemplate>(isolate,
+ on_server_die_callback_set)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "file_set"),
+ compatibility_new<FunctionTemplate>(isolate, file_set)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "file_get"),
+ compatibility_new<FunctionTemplate>(isolate, file_get)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "file_free"),
+ compatibility_new<FunctionTemplate>(isolate, file_free)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "thumb_exists"),
+ compatibility_new<FunctionTemplate>(isolate, thumb_exists)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "generate"),
+ compatibility_new<FunctionTemplate>(isolate, generate)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "generate_cancel"),
+ compatibility_new<FunctionTemplate>(isolate, generate_cancel)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "generate_cancel_all"),
+ compatibility_new<FunctionTemplate>(isolate, generate_cancel_all)
+ ->GetFunction());
+ ret->Set(compatibility_new<String>(isolate, "thumb_async_get"),
+ compatibility_new<FunctionTemplate>(isolate, thumb_async_get)
+ ->GetFunction());
+
+ compatibility_set_pointer_internal_field(ret, 0, client);
+
+ return ret;
+}
+
+EAPI
+void register_client_init(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::FunctionTemplate;
+
+ auto init = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ethumb_client_init();
+ return compatibility_return(compatibility_new<Integer>(isolate, ret),
+ args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, init)
+ ->GetFunction());
+}
+
+EAPI
+void register_client_shutdown(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::FunctionTemplate;
+
+ auto shutdown = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 0)
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ethumb_client_shutdown();
+ return compatibility_return(compatibility_new<Integer>(isolate, ret),
+ args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, shutdown)
+ ->GetFunction());
+}
+
+EAPI
+void register_client_connect(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::Boolean;
+ using v8::Value;
+ using v8::FunctionTemplate;
+ using v8::Function;
+ using v8::Handle;
+ using std::unique_ptr;
+
+ typedef efl::eina::js::global_ref<Value> persistent_t;
+
+ auto shutdown = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsFunction())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+
+ unique_ptr<persistent_t> cb_data{new persistent_t(isolate, args[0])};
+
+ auto connect_cb = [](void *data, Ethumb_Client *client,
+ Eina_Bool success) {
+ auto persistent = reinterpret_cast<persistent_t*>(data);
+ auto o = persistent->handle();
+
+ auto isolate = v8::Isolate::GetCurrent();
+
+ Handle<Value> args[2] = {
+ wrap_ethumb_client(client, isolate),
+ compatibility_new<Boolean>(isolate, success)
+ };
+
+ Function::Cast(*o)->Call(o->ToObject(), 2, args);
+ };
+ auto free_data = [](void *data) {
+ auto persistent = reinterpret_cast<persistent_t*>(data);
+ delete persistent;
+ };
+
+ auto ret = ethumb_client_connect(connect_cb, cb_data.release(),
+ free_data);
+ return compatibility_return(wrap_ethumb_client(ret, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, shutdown)
+ ->GetFunction());
+}
+
+}
+
+EAPI
+void register_ethumb(v8::Isolate *isolate, v8::Handle<v8::Object> exports)
+{
+ using v8::String;
+ register_client_init(isolate, exports,
+ compatibility_new<String>(isolate,
+ "ethumb_client_init"));
+ register_client_shutdown(isolate, exports,
+ compatibility_new<String>(isolate,
+ "ethumb_client_shutdown"));
+ register_client_connect(isolate, exports,
+ compatibility_new<String>(isolate,
+ "ethumb_client_connect"));
+}
+
+} } } // namespace efl { namespace ethumb { namespace js {