forked from enlightenment/efl
Test for JS binding
This commit is contained in:
parent
e62dfdd79e
commit
b151da61ae
12
configure.ac
12
configure.ac
|
@ -999,6 +999,18 @@ EFL_EVAL_PKGS([EINA_CXX])
|
|||
EFL_LIB_END([Eina_Cxx])
|
||||
#### End of Eina CXX
|
||||
|
||||
#### Eina JS
|
||||
EFL_LIB_START([Eina_Js])
|
||||
|
||||
EFL_DEPEND_PKG([EINA_JS], [V8], [v8 >= 3.25.28])
|
||||
|
||||
EFL_INTERNAL_DEPEND_PKG([EINA_JS], [eina])
|
||||
EFL_ADD_CFLAGS([EINA_JS], [${EFL_PTHREAD_CFLAGS}])
|
||||
EFL_EVAL_PKGS([EINA_JS])
|
||||
|
||||
EFL_LIB_END([Eina_Js])
|
||||
#### End of Eina JS
|
||||
|
||||
#### Eet
|
||||
|
||||
EFL_LIB_START([Eet])
|
||||
|
|
|
@ -78,6 +78,9 @@ include Makefile_Eolian_Cxx.am
|
|||
include Makefile_Eet_Cxx.am
|
||||
include Makefile_Eo_Cxx.am
|
||||
include Makefile_Efl_Cxx.am
|
||||
|
||||
include Makefile_Eina_Js.am
|
||||
|
||||
include Makefile_Elua.am
|
||||
include Makefile_Elocation.am
|
||||
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
|
||||
### Library
|
||||
|
||||
if HAVE_CXX11
|
||||
lib_LTLIBRARIES += lib/eina_js/libeina_js.la
|
||||
|
||||
lib_eina_js_libeina_js_la_CPPFLAGS = -I$(top_builddir)/src/lib/efl \
|
||||
@EINA_JS_CFLAGS@ \
|
||||
-DPACKAGE_BIN_DIR=\"$(bindir)\" \
|
||||
-DPACKAGE_LIB_DIR=\"$(libdir)\" \
|
||||
-DPACKAGE_DATA_DIR=\"$(datadir)/eina_js\" \
|
||||
@VALGRIND_CFLAGS@
|
||||
|
||||
lib_eina_js_libeina_js_la_LIBADD = @EINA_LIBS@ @DL_LIBS@
|
||||
lib_eina_js_libeina_js_la_DEPENDENCIES = @EINA_INTERNAL_LIBS@ @DL_INTERNAL_LIBS@
|
||||
lib_eina_js_libeina_js_la_LDFLAGS = @EFL_LTLIBRARY_FLAGS@
|
||||
|
||||
lib_eina_js_libeina_js_la_SOURCES = \
|
||||
bindings/eina_js/eina_list.cc
|
||||
|
||||
#installed_einacxxmainheadersdir = $(includedir)/eina-cxx-@VMAJ@
|
||||
#dist_installed_einacxxmainheaders_DATA = \
|
||||
bindings/eina_cxx/Eina.hh
|
||||
|
||||
#installed_einacxxheadersdir = $(includedir)/eina-cxx-@VMAJ@/eina-cxx
|
||||
#dist_installed_einacxxheaders_DATA = \
|
||||
bindings/eina_cxx/eina_accessor.hh \
|
||||
bindings/eina_cxx/eina_array.hh \
|
||||
bindings/eina_cxx/eina_clone_allocators.hh \
|
||||
bindings/eina_cxx/eina_error.hh \
|
||||
bindings/eina_cxx/eina_eo_base_fwd.hh \
|
||||
bindings/eina_cxx/eina_fold.hh \
|
||||
bindings/eina_cxx/eina_inarray.hh \
|
||||
bindings/eina_cxx/eina_inlist.hh \
|
||||
bindings/eina_cxx/eina_integer_sequence.hh \
|
||||
bindings/eina_cxx/eina_iterator.hh \
|
||||
bindings/eina_cxx/eina_lists_auxiliary.hh \
|
||||
bindings/eina_cxx/eina_list.hh \
|
||||
bindings/eina_cxx/eina_log.hh \
|
||||
bindings/eina_cxx/eina_optional.hh \
|
||||
bindings/eina_cxx/eina_ptrarray.hh \
|
||||
bindings/eina_cxx/eina_ptrlist.hh \
|
||||
bindings/eina_cxx/eina_range_types.hh \
|
||||
bindings/eina_cxx/eina_ref.hh \
|
||||
bindings/eina_cxx/eina_stringshare.hh \
|
||||
bindings/eina_cxx/eina_thread.hh \
|
||||
bindings/eina_cxx/eina_tuple.hh \
|
||||
bindings/eina_cxx/eina_tuple_unwrap.hh \
|
||||
bindings/eina_cxx/eina_type_traits.hh \
|
||||
bindings/eina_cxx/eina_value.hh
|
||||
|
||||
### Unit tests
|
||||
|
||||
if EFL_ENABLE_TESTS
|
||||
|
||||
check_PROGRAMS += tests/eina_js/eina_js_suite
|
||||
TESTS += tests/eina_js/eina_js_suite
|
||||
|
||||
tests_eina_js_eina_js_suite_SOURCES = \
|
||||
tests/eina_js/eina_js_suite.cc
|
||||
|
||||
tests_eina_js_eina_js_suite_CXXFLAGS = -I$(top_builddir)/src/lib/efl \
|
||||
-DTESTS_WD=\"`pwd`\" \
|
||||
-DTESTS_SRC_DIR=\"$(top_srcdir)/src/tests/eina_js\" \
|
||||
-DPACKAGE_BUILD_DIR=\"$(abs_top_builddir)/src/tests/eina_js\" \
|
||||
-DTESTS_BUILD_DIR=\"$(top_builddir)/src/tests/eina_js\" \
|
||||
@CHECK_CFLAGS@ \
|
||||
@EINA_JS_CFLAGS@
|
||||
tests_eina_js_eina_js_suite_LDADD = @CHECK_LIBS@ @USE_EINA_LIBS@ @USE_EO_LIBS@ @USE_EINA_JS_LIBS@
|
||||
tests_eina_js_eina_js_suite_DEPENDENCIES = @USE_EINA_INTERNAL_LIBS@ @USE_EO_INTERNAL_LIBS@ @USE_EINA_JS_INTERNAL_LIBS@
|
||||
|
||||
endif
|
||||
endif
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
|
||||
void js_foo()
|
||||
{
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
|
||||
#include <v8.h>
|
||||
#include <Eina.h>
|
||||
#include <cstdlib>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace efl { namespace js { namespace {
|
||||
|
||||
struct eina_list
|
||||
{
|
||||
Eina_List* _list;
|
||||
};
|
||||
|
||||
void new_eina_list(v8::FunctionCallbackInfo<v8::Value> const& args)
|
||||
{
|
||||
std::cerr << "called eina list constructor" << std::endl;
|
||||
args.This()->SetAlignedPointerInInternalField(0, new eina_list);
|
||||
}
|
||||
|
||||
} } }
|
||||
|
||||
EAPI void eina_list_register(v8::Handle<v8::ObjectTemplate> global, v8::Isolate* isolate)
|
||||
{
|
||||
v8::Local<v8::FunctionTemplate> constructor = v8::FunctionTemplate::New(isolate, &efl::js::new_eina_list );
|
||||
v8::Local<v8::ObjectTemplate> instance_t = constructor->InstanceTemplate();
|
||||
instance_t->SetInternalFieldCount(1);
|
||||
global->Set(v8::String::NewFromUtf8(isolate, "List"), constructor);
|
||||
}
|
||||
|
|
@ -0,0 +1,122 @@
|
|||
|
||||
#include <v8.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
|
||||
#include <Eina.h>
|
||||
|
||||
static const char script[] =
|
||||
"print(\"teste\");\n"
|
||||
"var l = new List();\n"
|
||||
;
|
||||
|
||||
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)
|
||||
{
|
||||
v8::HandleScope 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::abort();
|
||||
// Print errors that happened during compilation.
|
||||
// if (report_exceptions)
|
||||
// ReportException(isolate, &try_catch);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
v8::Handle<v8::Value> result = script->Run();
|
||||
if (result.IsEmpty()) {
|
||||
assert(try_catch.HasCaught());
|
||||
std::abort();
|
||||
// Print errors that happened during execution.
|
||||
// if (report_exceptions)
|
||||
// ReportException(isolate, &try_catch);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Print(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
||||
bool first = true;
|
||||
for (int i = 0; i < args.Length(); i++) {
|
||||
v8::HandleScope 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);
|
||||
}
|
||||
|
||||
EAPI void eina_list_register(v8::Handle<v8::ObjectTemplate> global, v8::Isolate* isolate);
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
v8::V8::InitializeICU();
|
||||
v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
|
||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
v8::Handle<v8::Context> context;
|
||||
{
|
||||
// Create a template for the global object.
|
||||
v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate);
|
||||
// Bind the global 'print' function to the C++ Print callback.
|
||||
global->Set(v8::String::NewFromUtf8(isolate, "print"),
|
||||
v8::FunctionTemplate::New(isolate, Print));
|
||||
eina_list_register(global, isolate);
|
||||
// // Bind the global 'read' function to the C++ Read callback.
|
||||
// global->Set(v8::String::NewFromUtf8(isolate, "read"),
|
||||
// v8::FunctionTemplate::New(isolate, Read));
|
||||
// // Bind the global 'load' function to the C++ Load callback.
|
||||
// global->Set(v8::String::NewFromUtf8(isolate, "load"),
|
||||
// v8::FunctionTemplate::New(isolate, Load));
|
||||
// // Bind the 'quit' function
|
||||
// global->Set(v8::String::NewFromUtf8(isolate, "quit"),
|
||||
// v8::FunctionTemplate::New(isolate, Quit));
|
||||
// // Bind the 'version' function
|
||||
// global->Set(v8::String::NewFromUtf8(isolate, "version"),
|
||||
// v8::FunctionTemplate::New(isolate, Version));
|
||||
context = v8::Context::New(isolate, NULL, global);
|
||||
}
|
||||
if (context.IsEmpty()) {
|
||||
fprintf(stderr, "Error creating context\n");
|
||||
return 1;
|
||||
}
|
||||
context->Enter();
|
||||
{
|
||||
// Enter the execution environment before evaluating any code.
|
||||
v8::Context::Scope context_scope(context);
|
||||
v8::Local<v8::String> name(v8::String::NewFromUtf8(context->GetIsolate(), "(shell)"));
|
||||
|
||||
v8::HandleScope handle_scope(context->GetIsolate());
|
||||
ExecuteString(context->GetIsolate(),
|
||||
v8::String::NewFromUtf8(context->GetIsolate(), script),
|
||||
name);
|
||||
}
|
||||
context->Exit();
|
||||
}
|
Loading…
Reference in New Issue