Compare commits

...

1 Commits

Author SHA1 Message Date
Sébastien Helleu
b20b5f1e41 [WIP] javascript: add compatibility with v8 version 6.8
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.
2021-01-30 14:35:39 +01:00
4 changed files with 39 additions and 21 deletions

View 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})

View 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);

View 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);
}

View 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 (