summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2015-01-09 04:05:43 -0200
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2015-01-09 04:05:43 -0200
commit83cc60e9c2c362ea52bdb0a1980ef096e79b732e (patch)
treeabe97b3c59442580c59176b93cfed7cc92d10d21
parenta090a65bb3f1771a10b445d12d3405bea92d8980 (diff)
downloadefl-83cc60e9c2c362ea52bdb0a1980ef096e79b732e.tar.gz
Fixes for compatibility
-rw-r--r--src/Makefile_Eina_Js.am1
-rw-r--r--src/bin/eolian_js/main.cc4
-rw-r--r--src/bindings/eina_js/eina_js_compatibility.hh102
-rw-r--r--src/bindings/eina_js/eina_js_container.cc3
-rw-r--r--src/bindings/eo_js/eo_js_event.hh2
5 files changed, 67 insertions, 45 deletions
diff --git a/src/Makefile_Eina_Js.am b/src/Makefile_Eina_Js.am
index 55827dace1..40f1d42216 100644
--- a/src/Makefile_Eina_Js.am
+++ b/src/Makefile_Eina_Js.am
@@ -112,6 +112,7 @@ tests/eina_js/eina_js_log.cc
tests_eina_js_libeina_js_iterator_la_SOURCES = \
tests/eina_js/eina_js_iterator.cc
+tests_eina_js_libeina_js_suite_la_CXXFLAGS = $(EINA_JS_TEST_CXXFLAGS)
tests_eina_js_libeina_js_suite_la_LIBADD = \
@CHECK_LIBS@ @USE_EO_LIBS@ @USE_EINA_LIBS@ @USE_EOLIAN_LIBS@ @USE_EOLIAN_JS_LIBS@ @USE_EINA_JS_LIBS@
tests_eina_js_libeina_js_suite_la_DEPENDENCIES = @USE_EINA_INTERNAL_LIBS@ @USE_EINA_JS_INTERNAL_LIBS@ @USE_EO_INTERNAL_LIBS@
diff --git a/src/bin/eolian_js/main.cc b/src/bin/eolian_js/main.cc
index c74fd70632..d43e2b135e 100644
--- a/src/bin/eolian_js/main.cc
+++ b/src/bin/eolian_js/main.cc
@@ -452,8 +452,8 @@ int main(int argc, char** argv)
<< "\"));\n";
os << " v8::Local<v8::ObjectTemplate> instance = "
<< "register_" << lower_case_class_name << "_from_constructor(isolate, constructor);\n";
- os << " persistent_instance = ::efl::eina::js::compatibility_persistent<v8::ObjectTemplate>(isolate, instance);\n";
- os << " constructor_from_eo = ::efl::eina::js::compatibility_persistent<v8::Function>(isolate, constructor->GetFunction());\n";
+ os << " persistent_instance = {isolate, instance};\n";
+ os << " constructor_from_eo = {isolate, constructor->GetFunction()};\n";
os << " }\n";
os << "}\n\n";
diff --git a/src/bindings/eina_js/eina_js_compatibility.hh b/src/bindings/eina_js/eina_js_compatibility.hh
index bfe799abb7..8b48c2fbc5 100644
--- a/src/bindings/eina_js/eina_js_compatibility.hh
+++ b/src/bindings/eina_js/eina_js_compatibility.hh
@@ -68,8 +68,7 @@ struct _libv8_callback_info_test
template <typename T = v8::ObjectTemplate, typename Enable = void>
struct _libv8_property_callback_info_test
- : std::true_type
-{};
+ : 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&);
@@ -77,7 +76,7 @@ typedef void(*_libv8_setter_callback)(v8::Local<v8::String>, v8::Local<v8::Value
template <typename T>
struct _libv8_property_callback_info_test
<T, typename std::enable_if
- <!std::is_same<decltype( & T::SetAccessor)
+ <std::is_same<decltype( & T::SetAccessor)
, void (T::*)
(v8::Handle<v8::String>
, _libv8_getter_callback
@@ -91,23 +90,6 @@ struct _libv8_property_callback_info_test
{
};
-// 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;
@@ -129,38 +111,56 @@ using compatibility_accessor_callback_info_type
, v8::PropertyCallbackInfo<v8::Value> const&, v8::AccessorInfo const&>
::type;
-static_assert(v8_uses_callback_info, "");
-static_assert(v8_uses_isolate, "");
+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 <typename T = std::integral_constant<bool, v8_uses_isolate> >
+template <bool = v8_uses_isolate>
struct compatibility_string;
template <>
-struct compatibility_string<std::true_type> : v8::String {};
-
-template <>
-struct compatibility_string<std::false_type> : v8::String
+struct compatibility_string<true> : v8::String
{
template <typename... Args>
- static v8::Local<v8::String> NewFromUtf8(v8::Isolate*, const char* data, Args...args)
+ static v8::Local<v8::String> New(Args...args)
{
- return New(data, args...);
+ return NewFromUtf8(v8::Isolate::GetCurrent(), args...);
}
};
+
+template <>
+struct compatibility_string<false> : v8::String
+{
+};
-template <typename T, typename...Args>
-auto compatibility_new_impl(v8::Isolate* isolate, T, compatibility_type_tag<v8::String>
+template <typename...Args>
+auto compatibility_new_impl(v8::Isolate* isolate, std::true_type, compatibility_type_tag<v8::String>
, Args...args) ->
decltype(compatibility_string<>::NewFromUtf8(isolate, args...))
{
return compatibility_string<>::NewFromUtf8(isolate, args...);
}
-template <typename T, typename...Args>
-auto compatibility_new_impl(nullptr_t, T, compatibility_type_tag<v8::String>
+template <typename...Args>
+auto compatibility_new_impl(v8::Isolate* isolate, std::false_type, compatibility_type_tag<v8::String>
+ , Args...args) ->
+ decltype(compatibility_string<>::NewFromUtf8(isolate, args...))
+{
+ return compatibility_string<>::NewFromUtf8(isolate, args...);
+}
+
+template <typename...Args>
+auto compatibility_new_impl(nullptr_t, std::true_type, compatibility_type_tag<v8::String>
+ , Args...args) ->
+ decltype(compatibility_string<>::NewFromUtf8(v8::Isolate::GetCurrent(), args...))
+{
+ return compatibility_string<>::NewFromUtf8(v8::Isolate::GetCurrent(), args...);
+}
+
+template <typename...Args>
+auto compatibility_new_impl(nullptr_t, std::false_type, compatibility_type_tag<v8::String>
, Args...args) ->
decltype(compatibility_string<>::NewFromUtf8(v8::Isolate::GetCurrent(), args...))
{
@@ -337,7 +337,12 @@ struct compatibility_persistent<T, true> : v8::UniquePersistent<T>
: _base(other.Pass()), handle_(other.handle())
{
}
- compatibility_persistent<T>& operator=(compatibility_persistent<T>&&) = default;
+ compatibility_persistent& operator=(compatibility_persistent&& other)
+ {
+ this->_base::operator=(other.Pass());
+ handle_ = other.handle();
+ return *this;
+ }
compatibility_persistent() {}
compatibility_persistent(v8::Isolate* isolate, v8::Handle<T> v)
@@ -361,11 +366,6 @@ struct compatibility_persistent<T, false> : v8::Persistent<T>
{
typedef v8::Persistent<T> _base;
- compatibility_persistent(compatibility_persistent const&);
- compatibility_persistent(compatibility_persistent&&);
- compatibility_persistent& operator=(compatibility_persistent const&);
- compatibility_persistent& operator=(compatibility_persistent&&);
-
compatibility_persistent() {}
compatibility_persistent(v8::Isolate*, v8::Handle<T> v)
: _base(v)
@@ -394,7 +394,7 @@ struct _v8_object_internal_field<std::false_type> : v8::Object
{
return GetPointerFromInternalField(index);
}
- void SetAlignedPointerFromInternalField(int index, void* p)
+ void SetAlignedPointerInInternalField(int index, void* p)
{
SetPointerInInternalField(index, p);
}
@@ -468,6 +468,28 @@ v8::Local<T> compatibility_cast(U* v)
{
return *static_cast<v8::Local<T>*>(static_cast<void*>(v));
}
+
+template <typename T = v8::Context, 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();
+ }
+};
+
+inline v8::Local<v8::Object> compatibility_global()
+{
+ return v8::Isolate::GetCurrent()->GetCurrentContext()->Global();
+}
} } }
diff --git a/src/bindings/eina_js/eina_js_container.cc b/src/bindings/eina_js/eina_js_container.cc
index d5de4a3ec3..f3f1b38e56 100644
--- a/src/bindings/eina_js/eina_js_container.cc
+++ b/src/bindings/eina_js/eina_js_container.cc
@@ -364,8 +364,7 @@ void register_class(v8::Isolate* isolate, container_type type, const char* class
v8::Local<v8::ObjectTemplate> instance_t = efl::eina::js::register_template(isolate, constructor);
- efl::eina::js::instance_persistents[type]
- = compatibility_persistent<v8::ObjectTemplate> {isolate, instance_t};
+ efl::eina::js::instance_persistents[type] = {isolate, instance_t};
efl::eina::js::instance_templates[type] = constructor->GetFunction();
}
diff --git a/src/bindings/eo_js/eo_js_event.hh b/src/bindings/eo_js/eo_js_event.hh
index 843b5bda50..27f410ec57 100644
--- a/src/bindings/eo_js/eo_js_event.hh
+++ b/src/bindings/eo_js/eo_js_event.hh
@@ -39,7 +39,7 @@ inline Eina_Bool event_callback(void* data, Eo* obj, Eo_Event_Description const*
v8::Local<v8::Object> self = (*event->event_info->constructor)->NewInstance(1, a);
v8::Handle<v8::Value> call_args[] = {self};
- event->function->Call(v8::Isolate::GetCurrent()->GetCurrentContext()->Global(), 1, call_args);
+ event->function->Call(eina::js::compatibility_global(), 1, call_args);
return EO_CALLBACK_CONTINUE;
}