mirror of
https://github.com/weechat/weechat.git
synced 2026-06-12 14:14:48 +02:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b20b5f1e41 |
@@ -33,6 +33,7 @@ endif()
|
|||||||
|
|
||||||
set(V8_INC_PATHS
|
set(V8_INC_PATHS
|
||||||
/usr/include
|
/usr/include
|
||||||
|
/usr/include/v8
|
||||||
${CMAKE_INCLUDE_PATH}
|
${CMAKE_INCLUDE_PATH}
|
||||||
)
|
)
|
||||||
find_path(V8_INCLUDE_DIR v8.h PATHS ${V8_INC_PATHS})
|
find_path(V8_INCLUDE_DIR v8.h PATHS ${V8_INC_PATHS})
|
||||||
|
|||||||
@@ -41,14 +41,14 @@ extern "C"
|
|||||||
|
|
||||||
#define API_DEF_FUNC(__name) \
|
#define API_DEF_FUNC(__name) \
|
||||||
weechat_obj->Set( \
|
weechat_obj->Set( \
|
||||||
v8::String::New(#__name), \
|
v8::String::NewFromUtf8(isolate, #__name), \
|
||||||
v8::FunctionTemplate::New(weechat_js_api_##__name));
|
v8::FunctionTemplate::New(weechat_js_api_##__name));
|
||||||
#define API_DEF_CONST_INT(__name) \
|
#define API_DEF_CONST_INT(__name) \
|
||||||
weechat_obj->Set(v8::String::New(#__name), \
|
weechat_obj->Set(v8::String::NewFromUtf8(#__name), \
|
||||||
v8::Integer::New(__name));
|
v8::Integer::NewFromUtf8(__name));
|
||||||
#define API_DEF_CONST_STR(__name) \
|
#define API_DEF_CONST_STR(__name) \
|
||||||
weechat_obj->Set(v8::String::New(#__name), \
|
weechat_obj->Set(v8::String::NewFromUtf8(#__name), \
|
||||||
v8::String::New(__name));
|
v8::String::NewFromUtf8(__name));
|
||||||
#define API_FUNC(__name) \
|
#define API_FUNC(__name) \
|
||||||
static v8::Handle<v8::Value> \
|
static v8::Handle<v8::Value> \
|
||||||
weechat_js_api_##__name(const v8::Arguments &args)
|
weechat_js_api_##__name(const v8::Arguments &args)
|
||||||
@@ -98,19 +98,20 @@ extern "C"
|
|||||||
#define API_RETURN_OK return v8::True();
|
#define API_RETURN_OK return v8::True();
|
||||||
#define API_RETURN_ERROR return v8::False();
|
#define API_RETURN_ERROR return v8::False();
|
||||||
#define API_RETURN_EMPTY \
|
#define API_RETURN_EMPTY \
|
||||||
return v8::String::New("");
|
return v8::String::NewFromUtf8("");
|
||||||
#define API_RETURN_STRING(__string) \
|
#define API_RETURN_STRING(__string) \
|
||||||
if (__string) \
|
if (__string) \
|
||||||
return v8::String::New(__string); \
|
return v8::String::NewFromUtf8(__string); \
|
||||||
return v8::String::New("")
|
return v8::String::NewFromUtf8("")
|
||||||
#define API_RETURN_STRING_FREE(__string) \
|
#define API_RETURN_STRING_FREE(__string) \
|
||||||
if (__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); \
|
free ((void *)__string); \
|
||||||
return return_value; \
|
return return_value; \
|
||||||
} \
|
} \
|
||||||
return v8::String::New("")
|
return v8::String::NewFromUtf8("")
|
||||||
#define API_RETURN_INT(__int) \
|
#define API_RETURN_INT(__int) \
|
||||||
return v8::Integer::New(__int)
|
return v8::Integer::New(__int)
|
||||||
#define API_RETURN_LONG(__int) \
|
#define API_RETURN_LONG(__int) \
|
||||||
@@ -4894,6 +4895,7 @@ void
|
|||||||
WeechatJsV8::loadLibs()
|
WeechatJsV8::loadLibs()
|
||||||
{
|
{
|
||||||
v8::Local<v8::ObjectTemplate> weechat_obj = v8::ObjectTemplate::New();
|
v8::Local<v8::ObjectTemplate> weechat_obj = v8::ObjectTemplate::New();
|
||||||
|
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||||
|
|
||||||
/* constants */
|
/* constants */
|
||||||
API_DEF_CONST_INT(WEECHAT_RC_OK);
|
API_DEF_CONST_INT(WEECHAT_RC_OK);
|
||||||
|
|||||||
@@ -49,7 +49,9 @@ using namespace v8;
|
|||||||
|
|
||||||
WeechatJsV8::WeechatJsV8()
|
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
|
bool
|
||||||
WeechatJsV8::load(const char *source)
|
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);
|
return this->load(src);
|
||||||
}
|
}
|
||||||
@@ -92,7 +96,8 @@ WeechatJsV8::load(const char *source)
|
|||||||
bool
|
bool
|
||||||
WeechatJsV8::execScript()
|
WeechatJsV8::execScript()
|
||||||
{
|
{
|
||||||
v8::TryCatch trycatch;
|
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||||
|
v8::TryCatch trycatch(isolate);
|
||||||
|
|
||||||
this->context = Context::New(NULL, this->global);
|
this->context = Context::New(NULL, this->global);
|
||||||
Context::Scope context_scope(this->context);
|
Context::Scope context_scope(this->context);
|
||||||
@@ -126,7 +131,8 @@ WeechatJsV8::functionExists(const char *function)
|
|||||||
Context::Scope context_scope(this->context);
|
Context::Scope context_scope(this->context);
|
||||||
|
|
||||||
Handle<Object> global = this->context->Global();
|
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();
|
return value->IsFunction();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,12 +143,13 @@ WeechatJsV8::functionExists(const char *function)
|
|||||||
Handle<Value>
|
Handle<Value>
|
||||||
WeechatJsV8::execFunction(const char *function, int argc, Handle<Value> *argv)
|
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);
|
Context::Scope context_scope(this->context);
|
||||||
|
|
||||||
Handle<Object> global = this->context->Global();
|
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<Function> func = Handle<Function>::Cast(value);
|
||||||
|
|
||||||
Handle<Value> res = func->Call(global, argc, argv);
|
Handle<Value> res = func->Call(global, argc, argv);
|
||||||
@@ -170,5 +177,7 @@ WeechatJsV8::addGlobal(Handle<String> key, Handle<Template> val)
|
|||||||
void
|
void
|
||||||
WeechatJsV8::addGlobal(const char *key, Handle<Template> val)
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,9 +102,11 @@ weechat_js_hashtable_map_cb (void *data,
|
|||||||
/* make C++ compiler happy */
|
/* make C++ compiler happy */
|
||||||
(void) hashtable;
|
(void) hashtable;
|
||||||
|
|
||||||
|
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||||
v8::Handle<v8::Object> *obj = (v8::Handle<v8::Object> *)data;
|
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>
|
v8::Handle<v8::Object>
|
||||||
weechat_js_hashtable_to_object (struct t_hashtable *hashtable)
|
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_hashtable_map_string (hashtable,
|
||||||
&weechat_js_hashtable_map_cb,
|
&weechat_js_hashtable_map_cb,
|
||||||
@@ -185,6 +188,8 @@ weechat_js_exec (struct t_plugin_script *script,
|
|||||||
|
|
||||||
ret_value = NULL;
|
ret_value = NULL;
|
||||||
|
|
||||||
|
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||||
|
|
||||||
old_js_current_script = js_current_script;
|
old_js_current_script = js_current_script;
|
||||||
js_current_script = script;
|
js_current_script = script;
|
||||||
js_v8 = (WeechatJsV8 *)(script->interpreter);
|
js_v8 = (WeechatJsV8 *)(script->interpreter);
|
||||||
@@ -206,10 +211,11 @@ weechat_js_exec (struct t_plugin_script *script,
|
|||||||
switch (format[i])
|
switch (format[i])
|
||||||
{
|
{
|
||||||
case 's': /* string */
|
case 's': /* string */
|
||||||
argv2[i] = v8::String::New((const char *)argv[i]);
|
argv2[i] = v8::String::NewFromUtf8(isolate,
|
||||||
|
(const char *)argv[i]);
|
||||||
break;
|
break;
|
||||||
case 'i': /* integer */
|
case 'i': /* integer */
|
||||||
argv2[i] = v8::Integer::New(*((int *)argv[i]));
|
argv2[i] = v8::Integer::New(isolate, *((int *)argv[i]));
|
||||||
break;
|
break;
|
||||||
case 'h': /* hash */
|
case 'h': /* hash */
|
||||||
argv2[i] = weechat_js_hashtable_to_object (
|
argv2[i] = weechat_js_hashtable_to_object (
|
||||||
|
|||||||
Reference in New Issue
Block a user