aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVinícius dos Santos Oliveira <vini.ipsmaker@expertisesolutions.com.br>2015-06-02 14:14:32 -0300
committerVinícius dos Santos Oliveira <vini.ipsmaker@expertisesolutions.com.br>2015-06-02 14:14:32 -0300
commit09265accc26966c78d7572e087ecf84bb1c324ff (patch)
treeb179ed6c8945dcf79614c7d40ad1c6534ceaab44
parentInitial bindings for Ecore_Job (diff)
downloadefl-09265accc26966c78d7572e087ecf84bb1c324ff.tar.gz
Initial bindings for Ecore_Idle
-rw-r--r--src/Makefile_Ecore_Js.am6
-rw-r--r--src/bindings/ecore_js/ecore_js_idle.cc293
-rw-r--r--src/bindings/ecore_js/ecore_js_idle.hh35
-rw-r--r--src/tests/ecore_js/ecore_js_suite.cc17
-rwxr-xr-xsrc/tests/ecore_js/ecore_js_suite.js43
5 files changed, 392 insertions, 2 deletions
diff --git a/src/Makefile_Ecore_Js.am b/src/Makefile_Ecore_Js.am
index b2195699cb..7d3f831306 100644
--- a/src/Makefile_Ecore_Js.am
+++ b/src/Makefile_Ecore_Js.am
@@ -25,7 +25,8 @@ bindings/ecore_js/ecore_js_init.cc \
bindings/ecore_js/ecore_js_mainloop.cc \
bindings/ecore_js/ecore_js_timer.cc \
bindings/ecore_js/ecore_js_event.cc \
-bindings/ecore_js/ecore_js_job.cc
+bindings/ecore_js/ecore_js_job.cc \
+bindings/ecore_js/ecore_js_idle.cc
ECORE_JS_TEST_CXXFLAGS = -I$(top_builddir)/src/lib/efl \
-DTESTS_WD=\"`pwd`\" \
@@ -46,7 +47,8 @@ bindings/ecore_js/ecore_js_init.hh \
bindings/ecore_js/ecore_js_mainloop.hh \
bindings/ecore_js/ecore_js_timer.hh \
bindings/ecore_js/ecore_js_event.hh \
-bindings/ecore_js/ecore_js_job.hh
+bindings/ecore_js/ecore_js_job.hh \
+bindings/ecore_js/ecore_js_idle.hh
### Unit tests
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..8cfffc02e1
--- /dev/null
+++ b/src/bindings/ecore_js/ecore_js_idle.cc
@@ -0,0 +1,293 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <ecore_js_idle.hh>
+#include <Ecore.h>
+
+namespace efl { namespace ecore { namespace js {
+
+struct persistent_with_isolate_t
+{
+ template<class S>
+ persistent_with_isolate_t(v8::Isolate *isolate, v8::Handle<S> that)
+ : isolate(isolate)
+ , persistent(isolate, that)
+ {}
+
+ v8::Isolate *isolate;
+ v8::Persistent<v8::Value> persistent;
+};
+
+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()));
+ };
+
+ 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()));
+ };
+
+ 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()));
+ };
+
+ ret->Set(compatibility_new<String>(isolate, "del"),
+ compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
+
+ ret->SetInternalField(0, compatibility_new<External>(isolate, idle_exiter));
+
+ return ret;
+}
+
+EAPI
+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();
+
+ persistent_with_isolate_t *f
+ = new persistent_with_isolate_t(args.GetIsolate(), args[0]);
+ auto ret = ecore_idler_add([](void *data) -> Eina_Bool {
+ persistent_with_isolate_t *persistent
+ = reinterpret_cast<persistent_with_isolate_t *>(data);
+ auto value = Local<Value>::New(persistent->isolate,
+ persistent->persistent);
+ auto closure = Function::Cast(*value);
+
+ auto ret = closure->Call(Undefined(persistent->isolate), 0, NULL);
+ auto bret = ret->IsBoolean() && ret->BooleanValue();
+
+ if (!bret)
+ 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());
+}
+
+EAPI
+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();
+
+ persistent_with_isolate_t *f
+ = new persistent_with_isolate_t(args.GetIsolate(), args[0]);
+ auto ret = ecore_idle_enterer_add([](void *data) -> Eina_Bool {
+ persistent_with_isolate_t *persistent
+ = reinterpret_cast<persistent_with_isolate_t *>(data);
+ auto value = Local<Value>::New(persistent->isolate,
+ persistent->persistent);
+ auto closure = Function::Cast(*value);
+
+ auto ret = closure->Call(Undefined(persistent->isolate), 0, NULL);
+ auto bret = ret->IsBoolean() && ret->BooleanValue();
+
+ if (!bret)
+ 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());
+}
+
+EAPI
+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();
+
+ persistent_with_isolate_t *f
+ = new persistent_with_isolate_t(args.GetIsolate(), args[0]);
+ auto ret = ecore_idle_enterer_before_add([](void *data) -> Eina_Bool {
+ persistent_with_isolate_t *persistent
+ = reinterpret_cast<persistent_with_isolate_t *>(data);
+ auto value = Local<Value>::New(persistent->isolate,
+ persistent->persistent);
+ auto closure = Function::Cast(*value);
+
+ auto ret = closure->Call(Undefined(persistent->isolate), 0, NULL);
+ auto bret = ret->IsBoolean() && ret->BooleanValue();
+
+ if (!bret)
+ 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());
+}
+
+EAPI
+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();
+
+ persistent_with_isolate_t *f
+ = new persistent_with_isolate_t(args.GetIsolate(), args[0]);
+ auto ret = ecore_idle_exiter_add([](void *data) -> Eina_Bool {
+ persistent_with_isolate_t *persistent
+ = reinterpret_cast<persistent_with_isolate_t *>(data);
+ auto value = Local<Value>::New(persistent->isolate,
+ persistent->persistent);
+ auto closure = Function::Cast(*value);
+
+ auto ret = closure->Call(Undefined(persistent->isolate), 0, NULL);
+ auto bret = ret->IsBoolean() && ret->BooleanValue();
+
+ if (!bret)
+ 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());
+}
+
+} } } // namespace efl { namespace js {
diff --git a/src/bindings/ecore_js/ecore_js_idle.hh b/src/bindings/ecore_js/ecore_js_idle.hh
new file mode 100644
index 0000000000..9b7f513509
--- /dev/null
+++ b/src/bindings/ecore_js/ecore_js_idle.hh
@@ -0,0 +1,35 @@
+#ifndef ECORE_JS_IDLE_HH
+#define ECORE_JS_IDLE_HH
+
+#include <Eina.hh>
+#include EINA_STRINGIZE(V8_INCLUDE_HEADER)
+
+#include <eina_js_compatibility.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;
+
+void register_idler_add(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_idle_enterer_add(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_idle_enterer_before_add(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_idle_exiter_add(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+} } } // namespace efl { namespace ecore { namespace js {
+
+#endif /* ECORE_JS_IDLE_HH */
diff --git a/src/tests/ecore_js/ecore_js_suite.cc b/src/tests/ecore_js/ecore_js_suite.cc
index c40d7f0094..2eb0c6c48f 100644
--- a/src/tests/ecore_js/ecore_js_suite.cc
+++ b/src/tests/ecore_js/ecore_js_suite.cc
@@ -18,6 +18,7 @@
#include <ecore_js_timer.hh>
#include <ecore_js_event.hh>
#include <ecore_js_job.hh>
+#include <ecore_js_idle.hh>
const char* ToCString(const v8::String::Utf8Value& value) {
return *value ? *value : "<string conversion failed>";
@@ -251,6 +252,22 @@ void test_setup(v8::Handle<v8::Object> exports)
register_job_add(isolate, exports,
compatibility_new<String>(isolate, "ecore_job_add"));
+ // idle
+ register_idler_add(isolate, exports,
+ compatibility_new<String>(isolate, "ecore_idler_add"));
+ register_idle_enterer_add(isolate, exports,
+ compatibility_new<String>(isolate,
+ "ecore_idle_enterer"
+ "_add"));
+ register_idle_enterer_before_add(isolate, exports,
+ compatibility_new<String>(isolate,
+ "ecore_idle"
+ "_enterer_before"
+ "_add"));
+ register_idle_exiter_add(isolate, exports,
+ compatibility_new<String>(isolate,
+ "ecore_idle_exiter_add"));
+
std::cerr << __LINE__ << std::endl;
}
diff --git a/src/tests/ecore_js/ecore_js_suite.js b/src/tests/ecore_js/ecore_js_suite.js
index 2c52276807..5baa2941cf 100755
--- a/src/tests/ecore_js/ecore_js_suite.js
+++ b/src/tests/ecore_js/ecore_js_suite.js
@@ -213,6 +213,49 @@ job.del();
suite.ecore_mainloop_begin();
assert(captured === false);
+// Ecore idle
+var counter = 1;
+captured = [0, 0, 0, 0, 0];
+
+suite.ecore_idler_add(function() {
+ captured[0] = counter;
+ counter += 1;
+ suite.ecore_job_add(function() {});
+ return suite.ECORE_CALLBACK_DONE;
+});
+
+suite.ecore_idle_enterer_add(function() {
+ captured[1] = counter;
+ counter += 1;
+ return suite.ECORE_CALLBACK_DONE;
+});
+
+suite.ecore_idle_enterer_add(function() {
+ captured[2] = counter;
+ counter += 1;
+ return suite.ECORE_CALLBACK_DONE;
+});
+
+suite.ecore_idle_enterer_before_add(function() {
+ captured[3] = counter;
+ counter += 1;
+ return suite.ECORE_CALLBACK_DONE;
+});
+
+suite.ecore_idle_exiter_add(function() {
+ captured[4] = counter;
+ counter += 1;
+ suite.ecore_mainloop_quit();
+ return suite.ECORE_CALLBACK_DONE;
+});
+
+suite.ecore_mainloop_begin();
+assert(captured[0] === 4);
+assert(captured[1] === 2);
+assert(captured[2] === 3);
+assert(captured[3] === 1);
+assert(captured[4] === 5);
+
// Ecore shutdown
suite.ecore_shutdown();