[JS bindings]: restore compatibility with Ubuntu Trusty's NodeJS version

This commit is contained in:
Vinícius dos Santos Oliveira 2015-06-16 09:19:16 -03:00
parent f6a72df9d0
commit 85d01fba6d
9 changed files with 92 additions and 59 deletions

View File

@ -31,6 +31,7 @@ static v8::Local<v8::Object> wrap_animator(Ecore_Animator *animator,
return compatibility_return();
ecore_animator_del(extract_animator(info.This()));
return compatibility_return();
};
auto freeze = [](compatibility_callback_info_type info)
@ -39,6 +40,7 @@ static v8::Local<v8::Object> wrap_animator(Ecore_Animator *animator,
return compatibility_return();
ecore_animator_freeze(extract_animator(info.This()));
return compatibility_return();
};
auto thaw = [](compatibility_callback_info_type info)
@ -47,6 +49,7 @@ static v8::Local<v8::Object> wrap_animator(Ecore_Animator *animator,
return compatibility_return();
ecore_animator_thaw(extract_animator(info.This()));
return compatibility_return();
};
ret->Set(compatibility_new<String>(isolate, "del"),
@ -226,6 +229,7 @@ void register_animator_frametime_set(v8::Isolate *isolate,
return compatibility_return();
ecore_animator_frametime_set(args[0]->NumberValue());
return compatibility_return();
};
global->Set(name,
@ -428,6 +432,7 @@ void register_animator_source_set(v8::Isolate *isolate,
}
ecore_animator_source_set(source);
return compatibility_return();
};
global->Set(name,
@ -484,9 +489,8 @@ register_animator_custom_source_tick_begin_callback_set(v8::Isolate *isolate,
using v8::Undefined;
using v8::Isolate;
auto isolate = Isolate::GetCurrent();
Function::Cast(*animator_custom_source_tick_begin_cb_data
.handle())->Call(Undefined(isolate), 0, NULL);
auto o = animator_custom_source_tick_begin_cb_data.handle();
Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
}, NULL);
};
@ -516,9 +520,8 @@ register_animator_custom_source_tick_end_callback_set(v8::Isolate *isolate,
using v8::Undefined;
using v8::Isolate;
auto isolate = Isolate::GetCurrent();
Function::Cast(*animator_custom_source_tick_end_cb_data
.handle())->Call(Undefined(isolate), 0, NULL);
auto o = animator_custom_source_tick_end_cb_data.handle();
Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
}, NULL);
};
@ -567,10 +570,9 @@ void register_animator_add(v8::Isolate *isolate, v8::Handle<v8::Object> global,
auto cb = [](void *data) -> Eina_Bool {
auto persistent
= reinterpret_cast<compatibility_persistent<Value>*>(data);
auto closure = Function::Cast(*persistent->handle());
auto o = persistent->handle();
auto ret = closure->Call(Undefined(v8::Isolate::GetCurrent()), 0,
NULL);
auto ret = Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
auto bret = ret->IsBoolean() && ret->BooleanValue();
if (!bret)
@ -613,12 +615,12 @@ void register_animator_timeline_add(v8::Isolate *isolate,
auto cb = [](void *data, double pos) -> Eina_Bool {
auto persistent
= reinterpret_cast<compatibility_persistent<Value>*>(data);
auto closure = Function::Cast(*persistent->handle());
auto o = persistent->handle();
auto isolate = v8::Isolate::GetCurrent();
Handle<Value> args = compatibility_new<Number>(isolate, pos);
auto ret = closure->Call(Undefined(isolate), 1, &args);
auto ret = Function::Cast(*o)->Call(o->ToObject(), 1, &args);
auto bret = ret->IsBoolean() && ret->BooleanValue();
if (!bret)

View File

@ -29,6 +29,7 @@ static v8::Local<v8::Object> wrap_event(Ecore_Event *event,
return compatibility_return();
ecore_event_del(extract_event(info.This()));
return compatibility_return();
};
ret->Set(compatibility_new<String>(isolate, "del"),
@ -65,6 +66,7 @@ static v8::Local<v8::Object> wrap_event_handler(Ecore_Event_Handler *handler,
auto p = ecore_event_handler_del(extract_event_handler(info.This()));
delete reinterpret_cast<compatibility_persistent<Value>*>(p);
return compatibility_return();
};
ret->Set(compatibility_new<String>(isolate, "del"),
@ -100,6 +102,7 @@ static v8::Local<v8::Object> wrap_event_filter(Ecore_Event_Filter *filter,
auto p = ecore_event_filter_del(extract_event_filter(info.This()));
delete[] reinterpret_cast<compatibility_persistent<Value>*>(p);
return compatibility_return();
};
ret->Set(compatibility_new<String>(isolate, "del"),
@ -292,12 +295,12 @@ void register_event_handler_add(v8::Isolate *isolate,
auto cb = [](void *d, int type, void */*event*/) -> Eina_Bool {
auto persistent
= reinterpret_cast<compatibility_persistent<Value>*>(d);
auto closure = Function::Cast(*persistent->handle());
auto o = persistent->handle();
auto isolate = v8::Isolate::GetCurrent();
Handle<Value> args = compatibility_new<Integer>(isolate, type);
auto ret = closure->Call(Undefined(isolate), 1, &args);
auto ret = Function::Cast(*o)->Call(o->ToObject(), 1, &args);
auto bret = ret->IsBoolean() && ret->BooleanValue();
return bret ? EINA_TRUE : EINA_FALSE;
@ -339,9 +342,9 @@ void register_event_filter_add(v8::Isolate *isolate,
auto start_cb = [](void *data) -> void* {
auto p = reinterpret_cast<compatibility_persistent<Value>*>(data);
auto isolate = v8::Isolate::GetCurrent();
auto closure = Function::Cast(*p->handle());
auto o = p->handle();
auto ret = closure->Call(Undefined(isolate), 0, NULL);
auto ret = Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
return new compatibility_persistent<Value>{isolate, ret};
};
@ -351,14 +354,14 @@ void register_event_filter_add(v8::Isolate *isolate,
auto p = reinterpret_cast<p_t*>(data) + 1;
auto isolate = v8::Isolate::GetCurrent();
auto closure = Function::Cast(*p->handle());
auto o = p->handle();
Handle<Value> args[2]{
reinterpret_cast<p_t*>(loop_data)->handle(),
compatibility_new<Integer>(isolate, type)
};
auto ret = closure->Call(Undefined(isolate), 2, args);
auto ret = Function::Cast(*o)->Call(o->ToObject(), 2, args);
auto bret = ret->IsBoolean() && ret->BooleanValue();
return bret ? EINA_TRUE : EINA_FALSE;
@ -370,11 +373,11 @@ void register_event_filter_add(v8::Isolate *isolate,
auto loop_data = std::unique_ptr<p_t>(reinterpret_cast<p_t*>
(func_data));
auto p = reinterpret_cast<p_t*>(user_data) + 2;
auto closure = Function::Cast(*p->handle());
auto o = p->handle();
Handle<Value> args = p->handle();
closure->Call(Undefined(v8::Isolate::GetCurrent()), 1, &args);
Function::Cast(*o)->Call(o->ToObject(), 1, &args);
};
auto ret = ecore_event_filter_add(start_cb, filter_cb, end_cb, p);
@ -530,7 +533,7 @@ void register_event_signal_user_handler_add(v8::Isolate *isolate,
auto cb = [](void *d, int type, void *event) -> Eina_Bool {
auto p = reinterpret_cast<compatibility_persistent<Value>*>(d);
auto isolate = v8::Isolate::GetCurrent();
auto closure = Function::Cast(*p->handle());
auto o = p->handle();
auto wrapped_event = compatibility_new<Object>(isolate);
@ -546,7 +549,7 @@ void register_event_signal_user_handler_add(v8::Isolate *isolate,
wrapped_event
};
auto ret = closure->Call(Undefined(isolate), 2, args);
auto ret = Function::Cast(*o)->Call(o->ToObject(), 2, args);
auto bret = ret->IsBoolean() && ret->BooleanValue();
return bret ? EINA_TRUE : EINA_FALSE;
@ -587,7 +590,7 @@ void register_event_signal_exit_handler_add(v8::Isolate *isolate,
auto cb = [](void *d, int type, void *ev) -> Eina_Bool {
auto p = reinterpret_cast<compatibility_persistent<Value>*>(d);
auto isolate = v8::Isolate::GetCurrent();
auto closure = Function::Cast(*p->handle());
auto o = p->handle();
auto wrapped_event = compatibility_new<Object>(isolate);
@ -614,7 +617,7 @@ void register_event_signal_exit_handler_add(v8::Isolate *isolate,
wrapped_event
};
auto ret = closure->Call(Undefined(isolate), 2, args);
auto ret = Function::Cast(*o)->Call(o->ToObject(), 2, args);
auto bret = ret->IsBoolean() && ret->BooleanValue();
return bret ? EINA_TRUE : EINA_FALSE;
@ -654,7 +657,7 @@ void register_event_signal_realtime_handler_add(v8::Isolate *isolate,
auto cb = [](void *d, int type, void *ev) -> Eina_Bool {
auto p = reinterpret_cast<compatibility_persistent<Value>*>(d);
auto isolate = v8::Isolate::GetCurrent();
auto closure = Function::Cast(*p->handle());
auto o = p->handle();
auto wrapped_event = compatibility_new<Object>(isolate);
@ -670,7 +673,7 @@ void register_event_signal_realtime_handler_add(v8::Isolate *isolate,
wrapped_event
};
auto ret = closure->Call(Undefined(isolate), 2, args);
auto ret = Function::Cast(*o)->Call(o->ToObject(), 2, args);
auto bret = ret->IsBoolean() && ret->BooleanValue();
return bret ? EINA_TRUE : EINA_FALSE;

View File

@ -31,6 +31,7 @@ v8::Local<v8::Object> wrap_idler(Ecore_Idler *idler, v8::Isolate *isolate)
return compatibility_return();
ecore_idler_del(extract_idler(info.This()));
return compatibility_return();
};
ret->Set(compatibility_new<String>(isolate, "del"),
@ -66,6 +67,7 @@ static v8::Local<v8::Object> wrap_idle_enterer(Ecore_Idle_Enterer *idle_enterer,
return compatibility_return();
ecore_idle_enterer_del(extract_idle_enterer(info.This()));
return compatibility_return();
};
ret->Set(compatibility_new<String>(isolate, "del"),
@ -102,6 +104,7 @@ static v8::Local<v8::Object> wrap_idle_exiter(Ecore_Idle_Exiter *idle_exiter,
return compatibility_return();
ecore_idle_exiter_del(extract_idle_exiter(info.This()));
return compatibility_return();
};
ret->Set(compatibility_new<String>(isolate, "del"),
@ -132,10 +135,9 @@ void register_idler_add(v8::Isolate *isolate, v8::Handle<v8::Object> global,
auto ret = ecore_idler_add([](void *data) -> Eina_Bool {
compatibility_persistent<Value> *persistent
= reinterpret_cast<compatibility_persistent<Value>*>(data);
auto closure = Function::Cast(*persistent->handle());
auto o = persistent->handle();
auto ret = closure->Call(Undefined(v8::Isolate::GetCurrent()), 0,
NULL);
auto ret = Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
auto bret = ret->IsBoolean() && ret->BooleanValue();
if (!bret)
@ -172,10 +174,9 @@ void register_idle_enterer_add(v8::Isolate *isolate,
auto ret = ecore_idle_enterer_add([](void *data) -> Eina_Bool {
compatibility_persistent<Value> *persistent
= reinterpret_cast<compatibility_persistent<Value>*>(data);
auto closure = Function::Cast(*persistent->handle());
auto o = persistent->handle();
auto ret = closure->Call(Undefined(v8::Isolate::GetCurrent()), 0,
NULL);
auto ret = Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
auto bret = ret->IsBoolean() && ret->BooleanValue();
if (!bret)
@ -213,10 +214,9 @@ void register_idle_enterer_before_add(v8::Isolate *isolate,
auto ret = ecore_idle_enterer_before_add([](void *data) -> Eina_Bool {
compatibility_persistent<Value> *persistent
= reinterpret_cast<compatibility_persistent<Value>*>(data);
auto closure = Function::Cast(*persistent->handle());
auto o = persistent->handle();
auto ret = closure->Call(Undefined(v8::Isolate::GetCurrent()), 0,
NULL);
auto ret = Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
auto bret = ret->IsBoolean() && ret->BooleanValue();
if (!bret)
@ -254,10 +254,9 @@ void register_idle_exiter_add(v8::Isolate *isolate,
auto ret = ecore_idle_exiter_add([](void *data) -> Eina_Bool {
compatibility_persistent<Value> *persistent
= reinterpret_cast<compatibility_persistent<Value>*>(data);
auto closure = Function::Cast(*persistent->handle());
auto o = persistent->handle();
auto ret = closure->Call(Undefined(v8::Isolate::GetCurrent()), 0,
NULL);
auto ret = Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
auto bret = ret->IsBoolean() && ret->BooleanValue();
if (!bret)

View File

@ -30,6 +30,7 @@ static v8::Local<v8::Object> wrap_job(Ecore_Job *job, v8::Isolate *isolate)
return compatibility_return();
ecore_job_del(extract_job(info.This()));
return compatibility_return();
};
ret->Set(compatibility_new<String>(isolate, "del"),
@ -60,9 +61,9 @@ void register_job_add(v8::Isolate *isolate, v8::Handle<v8::Object> global,
auto ret = ecore_job_add([](void *data) {
compatibility_persistent<Value> *persistent
= reinterpret_cast<compatibility_persistent<Value>*>(data);
auto closure = Function::Cast(*persistent->handle());
auto o = persistent->handle();
closure->Call(Undefined(v8::Isolate::GetCurrent()), 0, NULL);
Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
delete persistent;
}, f);

View File

@ -195,9 +195,8 @@ void register_mainloop_thread_safe_call_async(v8::Isolate *isolate,
ecore_main_loop_thread_safe_call_async([](void *data) {
compatibility_persistent<Value> *persistent
= reinterpret_cast<compatibility_persistent<Value>*>(data);
auto closure = Function::Cast(*persistent->handle());
closure->Call(Undefined(v8::Isolate::GetCurrent()), 0, NULL);
auto o = persistent->handle();
Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
delete persistent;
}, f);
@ -230,8 +229,8 @@ void register_mainloop_thread_safe_call_sync(v8::Isolate *isolate,
compatibility_persistent<Value> *persistent
= reinterpret_cast<compatibility_persistent<Value>*>(data);
auto isolate = v8::Isolate::GetCurrent();
auto closure = Function::Cast(*persistent->handle());
auto res = closure->Call(Undefined(isolate), 0, NULL);
auto o = persistent->handle();
auto res = Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
void *ret = new compatibility_persistent<Value>(isolate, res);
delete persistent;

View File

@ -31,6 +31,7 @@ static v8::Local<v8::Object> wrap_poller(Ecore_Poller *poller,
return compatibility_return();
ecore_poller_del(extract_poller(info.This()));
return compatibility_return();
};
ret->Set(compatibility_new<String>(isolate, "del"),
@ -74,6 +75,7 @@ void register_poller_poll_interval_set(v8::Isolate *isolate,
}
ecore_poller_poll_interval_set(type, args[1]->NumberValue());
return compatibility_return();
};
global->Set(name,
@ -146,9 +148,9 @@ void register_poller_add(v8::Isolate *isolate, v8::Handle<v8::Object> global,
auto cb = [](void *data) -> Eina_Bool {
auto persistent
= reinterpret_cast<compatibility_persistent<Value>*>(data);
auto closure = Function::Cast(*persistent->handle());
auto o = persistent->handle();
auto ret = closure->Call(Undefined(Isolate::GetCurrent()), 0, NULL);
auto ret = Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
auto bret = ret->IsBoolean() && ret->BooleanValue();
if (!bret)

View File

@ -33,6 +33,7 @@ static v8::Local<v8::Object> wrap_timer(Ecore_Timer *timer,
return compatibility_return();
ecore_timer_del(extract_timer(info.This()));
return compatibility_return();
};
auto freeze = [](compatibility_callback_info_type info)
@ -41,6 +42,7 @@ static v8::Local<v8::Object> wrap_timer(Ecore_Timer *timer,
return compatibility_return();
ecore_timer_freeze(extract_timer(info.This()));
return compatibility_return();
};
auto freeze_get = [](compatibility_callback_info_type info)
@ -60,6 +62,7 @@ static v8::Local<v8::Object> wrap_timer(Ecore_Timer *timer,
return compatibility_return();
ecore_timer_thaw(extract_timer(info.This()));
return compatibility_return();
};
ret->Set(compatibility_new<String>(isolate, "del"),
@ -173,10 +176,9 @@ void register_timer_add(v8::Isolate *isolate, v8::Handle<v8::Object> global,
auto cb = [](void *data) -> Eina_Bool {
auto persistent
= reinterpret_cast<compatibility_persistent<Value>*>(data);
auto closure = Function::Cast(*persistent->handle());
auto o = persistent->handle();
auto ret = closure->Call(Undefined(v8::Isolate::GetCurrent()), 0,
NULL);
auto ret = Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
auto bret = ret->IsBoolean() && ret->BooleanValue();
if (!bret)
@ -217,10 +219,9 @@ void register_timer_loop_add(v8::Isolate *isolate,
auto cb = [](void *d) -> Eina_Bool {
auto persistent
= reinterpret_cast<compatibility_persistent<Value>*>(d);
auto closure = Function::Cast(*persistent->handle());
auto o = persistent->handle();
auto ret = closure->Call(Undefined(v8::Isolate::GetCurrent()), 0,
NULL);
auto ret = Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
auto bret = ret->IsBoolean() && ret->BooleanValue();
if (!bret)

View File

@ -477,7 +477,23 @@ inline v8::Local<v8::Object> compatibility_global()
{
return _v8_get_current_context<>::GetCurrent()->Global();
}
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);
}
} } }
#endif

View File

@ -42,8 +42,7 @@ static void js_eina_log_print_cb(const Eina_Log_Domain *d, Eina_Log_Level level,
constexpr unsigned argc = 7;
v8::Handle<v8::Value> argv[argc] = {
compatibility_new<String>(isolate, d->name, String::kNormalString,
d->namelen),
compatibility_new<String>(isolate, d->name),
compatibility_new<String>(isolate, d->color),
compatibility_new<Integer>(isolate, static_cast<int>(level)),
compatibility_new<String>(isolate, file),
@ -53,7 +52,7 @@ static void js_eina_log_print_cb(const Eina_Log_Domain *d, Eina_Log_Level level,
};
auto o = js_eina_log_print_cb_data.handle();
v8::Function::Cast(*o)->Call(v8::Undefined(isolate), argc, argv);
v8::Function::Cast(*o)->Call(o->ToObject(), argc, argv);
}
static bool valid_level_conversion(int src, Eina_Log_Level &dst)
@ -138,15 +137,15 @@ void register_log_print(v8::Isolate *isolate, v8::Handle<v8::Object> global,
if (!valid_level_conversion(args[1]->NumberValue(), level))
return compatibility_return();
auto frame = StackTrace::CurrentStackTrace(args.GetIsolate(), 1,
StackTrace::kDetailed)
->GetFrame(0);
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,
@ -193,6 +192,7 @@ void register_log_domain_unregister(v8::Isolate *isolate,
return compatibility_return();
eina_log_domain_unregister(args[0]->NumberValue());
return compatibility_return();
};
global->Set(name,
@ -237,6 +237,7 @@ void register_log_domain_registered_level_set(v8::Isolate *isolate,
eina_log_domain_registered_level_set(args[0]->NumberValue(),
args[1]->NumberValue());
return compatibility_return();
};
global->Set(name,
@ -259,6 +260,7 @@ void register_log_print_cb_set(v8::Isolate *isolate,
js_eina_log_print_cb_data
= compatibility_persistent<Value>(args.GetIsolate(), args[0]);
eina_log_print_cb_set(js_eina_log_print_cb, NULL);
return compatibility_return();
};
global->Set(name,
@ -278,6 +280,7 @@ void register_log_level_set(v8::Isolate *isolate, v8::Handle<v8::Object> global,
return compatibility_return();
eina_log_level_set(args[0]->NumberValue());
return compatibility_return();
};
global->Set(name,
@ -343,6 +346,7 @@ void register_log_color_disable_set(v8::Isolate *isolate,
return compatibility_return();
eina_log_color_disable_set(args[0]->BooleanValue());
return compatibility_return();
};
global->Set(name,
@ -386,6 +390,7 @@ void register_log_file_disable_set(v8::Isolate *isolate,
return compatibility_return();
eina_log_file_disable_set(args[0]->BooleanValue());
return compatibility_return();
};
global->Set(name,
@ -429,6 +434,7 @@ void register_log_function_disable_set(v8::Isolate *isolate,
return compatibility_return();
eina_log_function_disable_set(args[0]->BooleanValue());
return compatibility_return();
};
global->Set(name,
@ -472,6 +478,7 @@ void register_log_abort_on_critical_set(v8::Isolate *isolate,
return compatibility_return();
eina_log_abort_on_critical_set(args[0]->BooleanValue());
return compatibility_return();
};
global->Set(name,
@ -515,6 +522,7 @@ void register_log_abort_on_critical_level_set(v8::Isolate *isolate,
return compatibility_return();
eina_log_abort_on_critical_level_set(args[0]->NumberValue());
return compatibility_return();
};
global->Set(name,
@ -560,6 +568,7 @@ void register_log_domain_level_set(v8::Isolate *isolate,
eina_log_domain_level_set(*String::Utf8Value(args[0]),
args[1]->NumberValue());
return compatibility_return();
};
global->Set(name,
@ -626,6 +635,7 @@ void register_log_timing(v8::Isolate *isolate, v8::Handle<v8::Object> global,
eina_log_timing(args[0]->NumberValue(),
static_cast<Eina_Log_State>(args[1]->NumberValue()),
*String::Utf8Value(args[2]));
return compatibility_return();
};
global->Set(name,