aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVinícius dos Santos Oliveira <vini.ipsmaker@expertisesolutions.com.br>2015-06-02 14:12:49 -0300
committerVinícius dos Santos Oliveira <vini.ipsmaker@expertisesolutions.com.br>2015-06-02 14:12:49 -0300
commitfca3e3aac05238c63e564adda8cf566b60e3e04b (patch)
tree8648d6b003685f3efcf9b6ecefe55f2a20a81170
parentfix build error when nodejs is built with --shared-libuv (diff)
downloadefl-fca3e3aac05238c63e564adda8cf566b60e3e04b.tar.gz
Initial binding for Ecore
This commit adds the binding for the init group.
-rw-r--r--configure.ac27
-rw-r--r--src/Makefile.am1
-rw-r--r--src/Makefile_Ecore_Js.am89
-rw-r--r--src/bindings/ecore_js/ecore_js_init.cc56
-rw-r--r--src/bindings/ecore_js/ecore_js_init.hh26
-rw-r--r--src/tests/ecore_js/ecore_js_suite.cc203
-rwxr-xr-xsrc/tests/ecore_js/ecore_js_suite.js36
7 files changed, 438 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index 5e691446d3..8cc04e1044 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1113,6 +1113,33 @@ EFL_EVAL_PKGS([EINA_JS])
EFL_LIB_END([Eina_Js])
#### End of Eina JS
+#### Ecore JS
+EFL_LIB_START([Ecore_Js])
+
+AC_LANG_PUSH([C++])
+case "$want_js" in
+ nodejs)
+ ;;
+ libv8)
+ EFL_DEPEND_PKG([ECORE_JS], [V8], [v8 >= 3.25.28])
+ ;;
+ libuv)
+ EFL_DEPEND_PKG([ECORE_JS], [V8], [v8 >= 3.25.28])
+ EFL_DEPEND_PKG([ECORE_JS], [UV], [v8 >= 1.1.0])
+ ;;
+ none)
+ ;;
+ *) AC_MSG_ERROR([Invalid javascript dependency (${want_js}): must be none, nodejs, libv8 or libuv]) ;;
+esac
+AC_LANG_POP([C++])
+
+EFL_INTERNAL_DEPEND_PKG([ECORE_JS], [ecore])
+EFL_ADD_CFLAGS([ECORE_JS], [${EFL_PTHREAD_CFLAGS}])
+EFL_EVAL_PKGS([ECORE_JS])
+
+EFL_LIB_END([Ecore_Js])
+#### End of Ecore JS
+
#### Eina JS
EFL_LIB_START([Eo_Js])
diff --git a/src/Makefile.am b/src/Makefile.am
index 51b53e8205..df583c44ea 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -80,6 +80,7 @@ include Makefile_Eo_Cxx.am
include Makefile_Efl_Cxx.am
include Makefile_Eina_Js.am
+include Makefile_Ecore_Js.am
include Makefile_Eo_Js.am
include Makefile_Evas_Js.am
include Makefile_Eolian_Js.am
diff --git a/src/Makefile_Ecore_Js.am b/src/Makefile_Ecore_Js.am
new file mode 100644
index 0000000000..330076bf74
--- /dev/null
+++ b/src/Makefile_Ecore_Js.am
@@ -0,0 +1,89 @@
+
+### Library
+
+if HAVE_JS
+lib_LTLIBRARIES += lib/ecore_js/libecore_js.la
+
+lib_ecore_js_libecore_js_la_CPPFLAGS = -I$(top_builddir)/src/lib/efl \
+@EINA_JS_CFLAGS@ \
+@EINA_CXX_CFLAGS@ \
+@ECORE_CXX_CFLAGS@ \
+@EO_CXX_CFLAGS@ \
+@EO_CFLAGS@ \
+@ECORE_JS_CFLAGS@ \
+-DPACKAGE_BIN_DIR=\"$(bindir)\" \
+-DPACKAGE_LIB_DIR=\"$(libdir)\" \
+-DPACKAGE_DATA_DIR=\"$(datadir)/ecore_js\" \
+@VALGRIND_CFLAGS@
+
+lib_ecore_js_libecore_js_la_LIBADD = @ECORE_LIBS@ @DL_LIBS@ @ECORE_JS_LIBS@
+lib_ecore_js_libecore_js_la_DEPENDENCIES = @ECORE_INTERNAL_LIBS@ @DL_INTERNAL_LIBS@ @ECORE_JS_INTERNAL_LIBS@
+lib_ecore_js_libecore_js_la_LDFLAGS = @EFL_LTLIBRARY_FLAGS@
+
+lib_ecore_js_libecore_js_la_SOURCES = \
+bindings/ecore_js/ecore_js_init.cc
+
+ECORE_JS_TEST_CXXFLAGS = -I$(top_builddir)/src/lib/efl \
+-DTESTS_WD=\"`pwd`\" \
+-DTESTS_SRC_DIR=\"$(top_srcdir)/src/tests/ecore_js\" \
+-DPACKAGE_BUILD_DIR=\"$(abs_top_builddir)/src/tests/ecore_js\" \
+-DTESTS_BUILD_DIR=\"$(top_builddir)/src/tests/ecore_js\" \
+@CHECK_CFLAGS@ \
+@EINA_JS_CFLAGS@ \
+@EINA_CXX_CFLAGS@ \
+@ECORE_CXX_CFLAGS@ \
+@EO_CXX_CFLAGS@ \
+@EO_CFLAGS@ \
+@ECORE_JS_CFLAGS@
+
+installed_ecorejsheadersdir = $(includedir)/ecore-js-@VMAJ@
+dist_installed_ecorejsheaders_DATA = \
+bindings/ecore_js/ecore_js_init.hh
+
+### Unit tests
+
+if EFL_ENABLE_TESTS
+
+if HAVE_NODEJS
+AM_TESTS_ENVIRONMENT = NODE_PATH='$(abs_builddir)/tests/ecore_js'; export NODE_PATH;
+
+TESTS += tests/ecore_js/ecore_js_suite.js
+
+lib_LTLIBRARIES += tests/ecore_js/libecore_js_suite.la
+
+tests/ecore_js/ecore_js_suite.js: tests/ecore_js/ecore_js_suite_mod.node
+
+AM_V_CP = $(am__v_CP_@AM_V@)
+am__v_CP_ = $(am__v_CP_@AM_DEFAULT_V@)
+am__v_CP_0 = @echo " CP " $@;
+
+CP = cp
+
+tests/ecore_js/ecore_js_suite_mod.node: $(top_builddir)/src/tests/ecore_js/libecore_js_suite.la
+ $(AM_V_CP)$(CP) $(top_builddir)/src/tests/ecore_js/.libs/libecore_js_suite.so $(top_builddir)/src/tests/ecore_js/ecore_js_suite_mod.node
+
+tests_ecore_js_libecore_js_suite_la_SOURCES = \
+tests/ecore_js/ecore_js_suite.cc
+
+tests_ecore_js_libecore_js_suite_la_CXXFLAGS = $(ECORE_JS_TEST_CXXFLAGS)
+tests_ecore_js_libecore_js_suite_la_LIBADD = \
+@CHECK_LIBS@ @USE_EO_LIBS@ @USE_ECORE_LIBS@ @USE_EOLIAN_LIBS@ @USE_ECORE_JS_LIBS@
+tests_ecore_js_libecore_js_suite_la_DEPENDENCIES = @USE_ECORE_INTERNAL_LIBS@ @USE_ECORE_JS_INTERNAL_LIBS@ @USE_EO_INTERNAL_LIBS@
+
+else
+check_PROGRAMS += tests/ecore_js/ecore_js_suite
+TESTS += tests/ecore_js/ecore_js_suite
+
+tests_ecore_js_ecore_js_suite_SOURCES = \
+tests/ecore_js/ecore_js_suite.cc
+
+tests_ecore_js_ecore_js_suite_CXXFLAGS = $(ECORE_JS_TEST_CXXFLAGS)
+tests_ecore_js_ecore_js_suite_LDADD = \
+@CHECK_LIBS@ @USE_EO_LIBS@ @USE_ECORE_LIBS@ @USE_EOLIAN_LIBS@ @USE_ECORE_JS_LIBS@ @ECORE_JS_LIBS@
+tests_ecore_js_ecore_js_suite_DEPENDENCIES = @USE_ECORE_INTERNAL_LIBS@ @USE_ECORE_JS_INTERNAL_LIBS@ @USE_EO_INTERNAL_LIBS@ tests/ecore_js/ecore_js_suite.js
+
+endif
+
+endif
+endif
+
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..28abc15add
--- /dev/null
+++ b/src/bindings/ecore_js/ecore_js_init.cc
@@ -0,0 +1,56 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <ecore_js_init.hh>
+#include <Ecore.h>
+
+namespace efl { namespace ecore { namespace js {
+
+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 = ecore_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 = ecore_shutdown();
+ return compatibility_return(compatibility_new<Integer>(isolate, ret),
+ args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, shutdown)
+ ->GetFunction());
+}
+
+} } } // namespace efl { namespace js {
diff --git a/src/bindings/ecore_js/ecore_js_init.hh b/src/bindings/ecore_js/ecore_js_init.hh
new file mode 100644
index 0000000000..859076541f
--- /dev/null
+++ b/src/bindings/ecore_js/ecore_js_init.hh
@@ -0,0 +1,26 @@
+#ifndef ECORE_JS_INIT_HH
+#define ECORE_JS_INIT_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_init(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_shutdown(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+} } } // namespace efl { namespace ecore { namespace js {
+
+#endif /* ECORE_JS_INIT_HH */
diff --git a/src/tests/ecore_js/ecore_js_suite.cc b/src/tests/ecore_js/ecore_js_suite.cc
new file mode 100644
index 0000000000..4191ecbb24
--- /dev/null
+++ b/src/tests/ecore_js/ecore_js_suite.cc
@@ -0,0 +1,203 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <Eina.hh>
+#include EINA_STRINGIZE(V8_INCLUDE_HEADER)
+
+#include <cassert>
+#include <cstdlib>
+#include <fstream>
+
+#include <eina_js_compatibility.hh>
+#include <Eina.h>
+#include <Eo.hh>
+
+#include <ecore_js_init.hh>
+
+const char* ToCString(const v8::String::Utf8Value& value) {
+ return *value ? *value : "<string conversion failed>";
+}
+
+// Executes a string within the current v8 context.
+bool ExecuteString(v8::Isolate* isolate,
+ v8::Handle<v8::String> source,
+ v8::Handle<v8::Value> name)
+{
+ efl::eina::js::compatibility_handle_scope handle_scope(isolate);
+ v8::TryCatch try_catch;
+ v8::ScriptOrigin origin(name);
+ v8::Handle<v8::Script> script = v8::Script::Compile(source, &origin);
+ if (script.IsEmpty()) {
+ std::cerr << "Compilation failed" << std::endl;
+ std::abort();
+ // Print errors that happened during compilation.
+ // if (report_exceptions)
+ // ReportException(isolate, &try_catch);
+ return false;
+ }
+ else
+ {
+ std::cerr << "Compilation succesful" << std::endl;
+ v8::Handle<v8::Value> result = script->Run();
+ if (result.IsEmpty()) {
+ std::cout << "Failed with exception thrown" << std::endl;
+ //assert(try_catch.HasCaught());
+ //std::abort();
+ // Print errors that happened during execution.
+ // if (report_exceptions)
+ // ReportException(isolate, &try_catch);
+ if(try_catch.HasCaught())
+ std::cerr << "Exception " << ToCString(v8::String::Utf8Value(try_catch.Message()->Get()))
+ << std::endl;
+ std::abort();
+ return false;
+ } else {
+ assert(!try_catch.HasCaught());
+ // if (print_result && !result->IsUndefined()) {
+ // // If all went well and the result wasn't undefined then print
+ // // the returned value.
+ // v8::String::Utf8Value str(result);
+ // const char* cstr = ToCString(str);
+ // printf("%s\n", cstr);
+ // }
+ return true;
+ }
+ }
+}
+
+efl::eina::js::compatibility_return_type Print(efl::eina::js::compatibility_callback_info_type args)
+{
+ bool first = true;
+ for (int i = 0; i < args.Length(); i++) {
+ efl::eina::js::compatibility_handle_scope handle_scope(args.GetIsolate());
+ if (first) {
+ first = false;
+ } else {
+ printf(" ");
+ }
+ v8::String::Utf8Value str(args[i]);
+ const char* cstr = ToCString(str);
+ printf("%s", cstr);
+ }
+ printf("\n");
+ fflush(stdout);
+ return efl::eina::js::compatibility_return();
+}
+
+void test_setup(v8::Handle<v8::Object> exports)
+{
+ v8::Isolate *isolate = v8::Isolate::GetCurrent();
+
+ 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"));
+
+ std::cerr << __LINE__ << std::endl;
+}
+
+#ifndef HAVE_NODEJS
+int main(int, char*[])
+{
+ efl::eina::eina_init eina_init;
+ efl::eo::eo_init eo_init;
+
+ efl::eina::js::compatibility_initialize();
+ v8::Isolate* isolate = v8::Isolate::New();
+ assert(isolate != 0);
+
+ v8::Isolate::Scope isolate_scope(isolate);
+
+ efl::eina::js::compatibility_handle_scope handle_scope(isolate);
+ v8::Handle<v8::Context> context
+ = efl::eina::js::compatibility_new<v8::Context>
+ (isolate, nullptr
+ , efl::eina::js::compatibility_new<v8::ObjectTemplate>(isolate));
+ if (context.IsEmpty()) {
+ fprintf(stderr, "Error creating context\n");
+ return 1;
+ }
+ context->Enter();
+ {
+ std::vector<char> script;
+ {
+ std::ifstream script_file(TESTS_SRC_DIR "/ecore_js_suite.js");
+ script_file.seekg(0, std::ios::end);
+ std::size_t script_size = script_file.tellg();
+ script_file.seekg(0, std::ios::beg);
+ script.resize(script_size+1);
+ script_file.rdbuf()->sgetn(&script[0], script_size);
+ auto line_break = std::find(script.begin(), script.end(), '\n');
+ assert(line_break != script.end());
+ ++line_break;
+ std::fill(script.begin(), line_break, ' ');
+
+ std::cerr << "program:" << std::endl;
+ std::copy(script.begin(), script.end(), std::ostream_iterator<char>(std::cerr));
+ std::cerr << "end of program" << std::endl;
+ }
+
+
+ // Enter the execution environment before evaluating any code.
+ v8::Context::Scope context_scope(context);
+ v8::Local<v8::String> name(efl::eina::js::compatibility_new<v8::String>
+ (nullptr, "(shell)"));
+ v8::Local<v8::Object> global = context->Global();
+ v8::Handle<v8::Object> console = efl::eina::js::compatibility_new<v8::Object>(isolate);
+ global->Set(efl::eina::js::compatibility_new<v8::String>(isolate, "console"), console);
+ console->Set(efl::eina::js::compatibility_new<v8::String>(isolate, "log")
+ , efl::eina::js::compatibility_new<v8::FunctionTemplate>(isolate, & ::Print)
+ ->GetFunction());
+
+ std::cerr << __LINE__ << std::endl;
+ v8::Handle<v8::Object> exports = efl::eina::js::compatibility_new<v8::Object>(isolate);
+ global->Set(efl::eina::js::compatibility_new<v8::String>(isolate, "suite"), exports);
+
+ test_setup(exports);
+ std::cerr << __LINE__ << std::endl;
+
+
+ efl::eina::js::compatibility_handle_scope handle_scope(v8::Isolate::GetCurrent());
+ std::cerr << __LINE__ << std::endl;
+ ExecuteString(v8::Isolate::GetCurrent(),
+ efl::eina::js::compatibility_new<v8::String>(v8::Isolate::GetCurrent(), &script[0]),
+ name);
+ std::cerr << __LINE__ << std::endl;
+ }
+ context->Exit();
+}
+
+#else
+#include EINA_STRINGIZE(NODE_INCLUDE_HEADER)
+
+namespace {
+
+void eina_js_module_init(v8::Handle<v8::Object> exports)
+{
+ fprintf(stderr, "teste\n"); fflush(stderr);
+ try
+ {
+
+ eina_init();
+ eo_init();
+
+ test_setup(exports);
+
+ std::cerr << "registered" << std::endl;
+ }
+ catch(...)
+ {
+ std::cerr << "Error" << std::endl;
+ std::abort();
+ }
+}
+
+}
+
+NODE_MODULE(ecore_js_suite_mod, ::eina_js_module_init)
+
+#endif
diff --git a/src/tests/ecore_js/ecore_js_suite.js b/src/tests/ecore_js/ecore_js_suite.js
new file mode 100755
index 0000000000..c790da526d
--- /dev/null
+++ b/src/tests/ecore_js/ecore_js_suite.js
@@ -0,0 +1,36 @@
+#!/usr/bin/env node
+
+var suite;
+var assert;
+
+if(typeof process !== 'undefined')
+{
+ console.log('running from nodejs');
+ console.log('path', process.env.NODE_PATH);
+ console.log("teste1");
+
+ suite = require('ecore_js_suite_mod');
+ assert = require('assert');
+ assert(suite != null);
+}
+else
+{
+ assert = function(test, message) { if (test !== true) throw message; };
+ console.log('running from libv8')
+}
+
+// Ecore initialization
+
+suite.ecore_init();
+
+console.log("Finished init");
+
+// Ecore shutdown
+
+suite.ecore_shutdown();
+
+console.log("Finished shutdown");
+
+// finished tests
+
+console.log ("Test execution with success");