summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2019-11-11 10:29:08 +0100
committerSébastien Helleu <flashcode@flashtux.org>2021-01-30 14:35:39 +0100
commitb20b5f1e41e7680c470d8311e9590282b6718553 (patch)
tree0b735440722c0c0c28e5f8cd969ba66301503c1f
parentirc: add function irc_server_get_chantypes (diff)
downloadweechat-javascript-v8-node.tar.xz
weechat-javascript-v8-node.zip
[WIP] javascript: add compatibility with v8 version 6.8javascript-v8-node
This is work in progress, the javascript plugin does not yet compile. Compatibility with old v8 lib will be added later, for now I'm focused on compiling the plugin with v8 version 6.8.
-rw-r--r--cmake/FindV8.cmake1
-rw-r--r--src/plugins/javascript/weechat-js-api.cpp22
-rw-r--r--src/plugins/javascript/weechat-js-v8.cpp23
-rw-r--r--src/plugins/javascript/weechat-js.cpp14
4 files changed, 39 insertions, 21 deletions
diff --git a/cmake/FindV8.cmake b/cmake/FindV8.cmake
index 1da4ab3ae..573ce0b5e 100644
--- a/cmake/FindV8.cmake
+++ b/cmake/FindV8.cmake
@@ -33,6 +33,7 @@ endif()
set(V8_INC_PATHS
/usr/include
+ /usr/include/v8
${CMAKE_INCLUDE_PATH}
)
find_path(V8_INCLUDE_DIR v8.h PATHS ${V8_INC_PATHS})
diff --git a/src/plugins/javascript/weechat-js-api.cpp b/src/plugins/javascript/weechat-js-api.cpp
index f4f973a1f..a301a3d3b 100644
--- a/src/plugins/javascript/weechat-js-api.cpp
+++ b/src/plugins/javascript/weechat-js-api.cpp
@@ -41,14 +41,14 @@ extern "C"
#define API_DEF_FUNC(__name) \
weechat_obj->Set( \
- v8::String::New(#__name), \
+ v8::String::NewFromUtf8(isolate, #__name), \
v8::FunctionTemplate::New(weechat_js_api_##__name));
#define API_DEF_CONST_INT(__name) \
- weechat_obj->Set(v8::String::New(#__name), \
- v8::Integer::New(__name));
+ weechat_obj->Set(v8::String::NewFromUtf8(#__name), \
+ v8::Integer::NewFromUtf8(__name));
#define API_DEF_CONST_STR(__name) \
- weechat_obj->Set(v8::String::New(#__name), \
- v8::String::New(__name));
+ weechat_obj->Set(v8::String::NewFromUtf8(#__name), \
+ v8::String::NewFromUtf8(__name));
#define API_FUNC(__name) \
static v8::Handle<v8::Value> \
weechat_js_api_##__name(const v8::Arguments &args)
@@ -98,19 +98,20 @@ extern "C"
#define API_RETURN_OK return v8::True();
#define API_RETURN_ERROR return v8::False();
#define API_RETURN_EMPTY \
- return v8::String::New("");
+ return v8::String::NewFromUtf8("");
#define API_RETURN_STRING(__string) \
if (__string) \
- return v8::String::New(__string); \
- return v8::String::New("")
+ return v8::String::NewFromUtf8(__string); \
+ return v8::String::NewFromUtf8("")
#define API_RETURN_STRING_FREE(__string) \
if (__string) \
{ \
- v8::Handle<v8::Value> return_value = v8::String::New(__string); \
+ v8::Handle<v8::Value> return_value = \
+ v8::String::NewFromUtf8(__string); \
free ((void *)__string); \
return return_value; \
} \
- return v8::String::New("")
+ return v8::String::NewFromUtf8("")
#define API_RETURN_INT(__int) \
return v8::Integer::New(__int)
#define API_RETURN_LONG(__int) \
@@ -4894,6 +4895,7 @@ void
WeechatJsV8::loadLibs()
{
v8::Local<v8::ObjectTemplate> weechat_obj = v8::ObjectTemplate::New();
+ v8::Isolate* isolate = v8::Isolate::GetCurrent();
/* constants */
API_DEF_CONST_INT(WEECHAT_RC_OK);
diff --git a/src/plugins/javascript/weechat-js-v8.cpp b/src/plugins/javascript/weechat-js-v8.cpp
index c78200973..d890b10c3 100644
--- a/src/plugins/javascript/weechat-js-v8.cpp
+++ b/src/plugins/javascript/weechat-js-v8.cpp
@@ -49,7 +49,9 @@ using namespace v8;
WeechatJsV8::WeechatJsV8()
{
- this->global = ObjectTemplate::New();
+ v8::Isolate* isolate = v8::Isolate::GetCurrent();
+
+ this->global = ObjectTemplate::New(isolate);
}
/*
@@ -80,7 +82,9 @@ WeechatJsV8::load(Handle<String> source)
bool
WeechatJsV8::load(const char *source)
{
- Handle<String> src = String::New(source);
+ v8::Isolate* isolate = v8::Isolate::GetCurrent();
+
+ Handle<String> src = String::NewFromUtf8(isolate, source);
return this->load(src);
}
@@ -92,7 +96,8 @@ WeechatJsV8::load(const char *source)
bool
WeechatJsV8::execScript()
{
- v8::TryCatch trycatch;
+ v8::Isolate* isolate = v8::Isolate::GetCurrent();
+ v8::TryCatch trycatch(isolate);
this->context = Context::New(NULL, this->global);
Context::Scope context_scope(this->context);
@@ -126,7 +131,8 @@ WeechatJsV8::functionExists(const char *function)
Context::Scope context_scope(this->context);
Handle<Object> global = this->context->Global();
- Handle<Value> value = global->Get(String::New(function));
+ v8::Isolate* isolate = v8::Isolate::GetCurrent();
+ Handle<Value> value = global->Get(String::NewFromUtf8(isolate, function));
return value->IsFunction();
}
@@ -137,12 +143,13 @@ WeechatJsV8::functionExists(const char *function)
Handle<Value>
WeechatJsV8::execFunction(const char *function, int argc, Handle<Value> *argv)
{
- v8::TryCatch trycatch;
+ v8::Isolate* isolate = v8::Isolate::GetCurrent();
+ v8::TryCatch trycatch(isolate);
Context::Scope context_scope(this->context);
Handle<Object> global = this->context->Global();
- Handle<Value> value = global->Get(String::New(function));
+ Handle<Value> value = global->Get(String::NewFromUtf8(isolate, function));
Handle<Function> func = Handle<Function>::Cast(value);
Handle<Value> res = func->Call(global, argc, argv);
@@ -170,5 +177,7 @@ WeechatJsV8::addGlobal(Handle<String> key, Handle<Template> val)
void
WeechatJsV8::addGlobal(const char *key, Handle<Template> val)
{
- this->addGlobal(String::New(key), val);
+ v8::Isolate* isolate = v8::Isolate::GetCurrent();
+
+ this->addGlobal(String::NewFromUtf8(isolate, key), val);
}
diff --git a/src/plugins/javascript/weechat-js.cpp b/src/plugins/javascript/weechat-js.cpp
index 5dec4f171..cb17f08aa 100644
--- a/src/plugins/javascript/weechat-js.cpp
+++ b/src/plugins/javascript/weechat-js.cpp
@@ -102,9 +102,11 @@ weechat_js_hashtable_map_cb (void *data,
/* make C++ compiler happy */
(void) hashtable;
+ v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::Handle<v8::Object> *obj = (v8::Handle<v8::Object> *)data;
- (*obj)->Set(v8::String::New(key), v8::String::New(value));
+ (*obj)->Set(v8::String::NewFromUtf8(isolate, key),
+ v8::String::NewFromUtf8(isolate, value));
}
/*
@@ -114,7 +116,8 @@ weechat_js_hashtable_map_cb (void *data,
v8::Handle<v8::Object>
weechat_js_hashtable_to_object (struct t_hashtable *hashtable)
{
- v8::Handle<v8::Object> obj = v8::Object::New();
+ v8::Isolate* isolate = v8::Isolate::GetCurrent();
+ v8::Handle<v8::Object> obj = v8::Object::New(isolate);
weechat_hashtable_map_string (hashtable,
&weechat_js_hashtable_map_cb,
@@ -185,6 +188,8 @@ weechat_js_exec (struct t_plugin_script *script,
ret_value = NULL;
+ v8::Isolate* isolate = v8::Isolate::GetCurrent();
+
old_js_current_script = js_current_script;
js_current_script = script;
js_v8 = (WeechatJsV8 *)(script->interpreter);
@@ -206,10 +211,11 @@ weechat_js_exec (struct t_plugin_script *script,
switch (format[i])
{
case 's': /* string */
- argv2[i] = v8::String::New((const char *)argv[i]);
+ argv2[i] = v8::String::NewFromUtf8(isolate,
+ (const char *)argv[i]);
break;
case 'i': /* integer */
- argv2[i] = v8::Integer::New(*((int *)argv[i]));
+ argv2[i] = v8::Integer::New(isolate, *((int *)argv[i]));
break;
case 'h': /* hash */
argv2[i] = weechat_js_hashtable_to_object (