]> jfr.im git - irc/weechat/weechat.git/commitdiff
[WIP] javascript: add compatibility with v8 version 6.8 origin/javascript-v8-node
authorSébastien Helleu <redacted>
Mon, 11 Nov 2019 09:29:08 +0000 (10:29 +0100)
committerSébastien Helleu <redacted>
Sat, 30 Jan 2021 13:35:39 +0000 (14:35 +0100)
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.

cmake/FindV8.cmake
src/plugins/javascript/weechat-js-api.cpp
src/plugins/javascript/weechat-js-v8.cpp
src/plugins/javascript/weechat-js.cpp

index 1da4ab3ae51acf4b31133747ac75b1860eb94d6a..573ce0b5e010c3a317615d2ff9ecb380a30b3b84 100644 (file)
@@ -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})
index f4f973a1fcece5723b384835672f06fbd0b797bb..a301a3d3bddc6b530b108f32fe3fee33b4e95ef3 100644 (file)
@@ -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);
index c78200973d5d996afe6de5b6395731a02794dda5..d890b10c3e58e27b8651de56d8eeb7121b52d502 100644 (file)
@@ -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);
 }
index 5dec4f171c0bfe6fa6455f7bf00ecebb03d08c7a..cb17f08aac7a96450e8d8751dbf8c969c8a5b0bf 100644 (file)
@@ -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 (