mirror of
https://github.com/phpv8/v8js.git
synced 2024-12-22 19:51:51 +00:00
Get rid of V8JS_NEW macro.
This commit is contained in:
parent
16af153c3e
commit
f6310f9994
@ -39,14 +39,6 @@ extern "C" {
|
|||||||
/* V8Js Version */
|
/* V8Js Version */
|
||||||
#define V8JS_VERSION "0.1.5"
|
#define V8JS_VERSION "0.1.5"
|
||||||
|
|
||||||
/* V8 from 3.23.12 has most v8::Anything::New constructors expect isolates
|
|
||||||
as their first argument. Older versions don't provide these. */
|
|
||||||
#if PHP_V8_API_VERSION < 3023012
|
|
||||||
#define V8JS_NEW(t, i, v...) t::New(v)
|
|
||||||
#else
|
|
||||||
#define V8JS_NEW(t, i, v...) t::New(i, v)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Helper macros */
|
/* Helper macros */
|
||||||
#define V8JS_SYM(v) v8::String::NewFromUtf8(isolate, v, v8::String::kInternalizedString, sizeof(v) - 1)
|
#define V8JS_SYM(v) v8::String::NewFromUtf8(isolate, v, v8::String::kInternalizedString, sizeof(v) - 1)
|
||||||
#define V8JS_SYML(v, l) v8::String::NewFromUtf8(isolate, v, v8::String::kInternalizedString, l)
|
#define V8JS_SYML(v, l) v8::String::NewFromUtf8(isolate, v, v8::String::kInternalizedString, l)
|
||||||
|
4
v8js.cc
4
v8js.cc
@ -963,7 +963,7 @@ static PHP_METHOD(V8Js, __construct)
|
|||||||
/* Create global template for global object */
|
/* Create global template for global object */
|
||||||
// Now we are using multiple isolates this needs to be created for every context
|
// Now we are using multiple isolates this needs to be created for every context
|
||||||
|
|
||||||
v8::Local<v8::FunctionTemplate> tpl = V8JS_NEW(v8::FunctionTemplate, c->isolate, 0);
|
v8::Local<v8::FunctionTemplate> tpl = v8::FunctionTemplate::New(c->isolate, 0);
|
||||||
|
|
||||||
tpl->SetClassName(V8JS_SYM("V8Js"));
|
tpl->SetClassName(V8JS_SYM("V8Js"));
|
||||||
c->global_template.Reset(isolate, tpl);
|
c->global_template.Reset(isolate, tpl);
|
||||||
@ -991,7 +991,7 @@ static PHP_METHOD(V8Js, __construct)
|
|||||||
v8::Context::Scope context_scope(context);
|
v8::Context::Scope context_scope(context);
|
||||||
|
|
||||||
/* Create the PHP container object's function template */
|
/* Create the PHP container object's function template */
|
||||||
v8::Local<v8::FunctionTemplate> php_obj_t = V8JS_NEW(v8::FunctionTemplate, isolate, 0);
|
v8::Local<v8::FunctionTemplate> php_obj_t = v8::FunctionTemplate::New(isolate, 0);
|
||||||
|
|
||||||
/* Set class name for PHP object */
|
/* Set class name for PHP object */
|
||||||
#if PHP_VERSION_ID >= 50400
|
#if PHP_VERSION_ID >= 50400
|
||||||
|
@ -318,7 +318,7 @@ static void php_v8js_construct_callback(const v8::FunctionCallbackInfo<v8::Value
|
|||||||
if (ctor_ptr != NULL) {
|
if (ctor_ptr != NULL) {
|
||||||
php_v8js_call_php_func(value, ce, ctor_ptr, isolate, info TSRMLS_CC);
|
php_v8js_call_php_func(value, ce, ctor_ptr, isolate, info TSRMLS_CC);
|
||||||
}
|
}
|
||||||
php_object = V8JS_NEW(v8::External, isolate, value);
|
php_object = v8::External::New(isolate, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
newobj->SetAlignedPointerInInternalField(0, ext_tmpl->Value());
|
newobj->SetAlignedPointerInInternalField(0, ext_tmpl->Value());
|
||||||
@ -405,7 +405,7 @@ static void php_v8js_weak_closure_callback(const v8::WeakCallbackData<v8::Object
|
|||||||
!strncasecmp(key, mname, key_len - 1))
|
!strncasecmp(key, mname, key_len - 1))
|
||||||
|
|
||||||
#define PHP_V8JS_CALLBACK(isolate, mptr, tmpl) \
|
#define PHP_V8JS_CALLBACK(isolate, mptr, tmpl) \
|
||||||
V8JS_NEW(v8::FunctionTemplate, (isolate), php_v8js_php_callback, V8JS_NEW(v8::External, (isolate), mptr), V8JS_NEW(v8::Signature, (isolate), tmpl))->GetFunction()
|
v8::FunctionTemplate::New((isolate), php_v8js_php_callback, v8::External::New((isolate), mptr), v8::Signature::New((isolate), tmpl))->GetFunction()
|
||||||
|
|
||||||
|
|
||||||
static void php_v8js_named_property_enumerator(const v8::PropertyCallbackInfo<v8::Array> &info) /* {{{ */
|
static void php_v8js_named_property_enumerator(const v8::PropertyCallbackInfo<v8::Array> &info) /* {{{ */
|
||||||
@ -413,7 +413,7 @@ static void php_v8js_named_property_enumerator(const v8::PropertyCallbackInfo<v8
|
|||||||
// note: 'special' properties like 'constructor' are not enumerated.
|
// note: 'special' properties like 'constructor' are not enumerated.
|
||||||
v8::Isolate *isolate = info.GetIsolate();
|
v8::Isolate *isolate = info.GetIsolate();
|
||||||
v8::Local<v8::Object> self = info.Holder();
|
v8::Local<v8::Object> self = info.Holder();
|
||||||
v8::Local<v8::Array> result = V8JS_NEW(v8::Array, isolate, 0);
|
v8::Local<v8::Array> result = v8::Array::New(isolate, 0);
|
||||||
uint32_t result_len = 0;
|
uint32_t result_len = 0;
|
||||||
|
|
||||||
V8JS_TSRMLS_FETCH();
|
V8JS_TSRMLS_FETCH();
|
||||||
@ -690,9 +690,9 @@ static inline v8::Local<v8::Value> php_v8js_named_property_callback(v8::Local<v8
|
|||||||
// (only use this if method_ptr==NULL, which means
|
// (only use this if method_ptr==NULL, which means
|
||||||
// there is no actual PHP __call() implementation)
|
// there is no actual PHP __call() implementation)
|
||||||
v8::Local<v8::Function> cb =
|
v8::Local<v8::Function> cb =
|
||||||
V8JS_NEW(v8::FunctionTemplate, isolate,
|
v8::FunctionTemplate::New(isolate,
|
||||||
php_v8js_fake_call_impl, V8JS_NULL,
|
php_v8js_fake_call_impl, V8JS_NULL,
|
||||||
V8JS_NEW(v8::Signature, isolate, tmpl))->GetFunction();
|
v8::Signature::New(isolate, tmpl))->GetFunction();
|
||||||
cb->SetName(property);
|
cb->SetName(property);
|
||||||
ret_value = cb;
|
ret_value = cb;
|
||||||
} else {
|
} else {
|
||||||
@ -931,7 +931,7 @@ static v8::Handle<v8::Value> php_v8js_hash_to_jsobj(zval *value, v8::Isolate *is
|
|||||||
}
|
}
|
||||||
catch (const std::out_of_range &) {
|
catch (const std::out_of_range &) {
|
||||||
/* No cached v8::FunctionTemplate available as of yet, create one. */
|
/* No cached v8::FunctionTemplate available as of yet, create one. */
|
||||||
new_tpl = V8JS_NEW(v8::FunctionTemplate, isolate, 0);
|
new_tpl = v8::FunctionTemplate::New(isolate, 0);
|
||||||
|
|
||||||
new_tpl->SetClassName(V8JS_STRL(ce->name, ce->name_length));
|
new_tpl->SetClassName(V8JS_STRL(ce->name, ce->name_length));
|
||||||
new_tpl->InstanceTemplate()->SetInternalFieldCount(1);
|
new_tpl->InstanceTemplate()->SetInternalFieldCount(1);
|
||||||
@ -964,14 +964,14 @@ static v8::Handle<v8::Value> php_v8js_hash_to_jsobj(zval *value, v8::Isolate *is
|
|||||||
new_tpl->InstanceTemplate()->SetCallAsFunctionHandler(php_v8js_invoke_callback, PHP_V8JS_CALLBACK(isolate, invoke_method_ptr, new_tpl));
|
new_tpl->InstanceTemplate()->SetCallAsFunctionHandler(php_v8js_invoke_callback, PHP_V8JS_CALLBACK(isolate, invoke_method_ptr, new_tpl));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
v8::Local<v8::Array> call_handler_data = V8JS_NEW(v8::Array, isolate, 2);
|
v8::Local<v8::Array> call_handler_data = v8::Array::New(isolate, 2);
|
||||||
call_handler_data->Set(0, V8JS_NEW(v8::External, isolate, persist_tpl_));
|
call_handler_data->Set(0, v8::External::New(isolate, persist_tpl_));
|
||||||
call_handler_data->Set(1, V8JS_NEW(v8::External, isolate, ce));
|
call_handler_data->Set(1, v8::External::New(isolate, ce));
|
||||||
new_tpl->SetCallHandler(php_v8js_construct_callback, call_handler_data);
|
new_tpl->SetCallHandler(php_v8js_construct_callback, call_handler_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create v8 wrapper object
|
// Create v8 wrapper object
|
||||||
v8::Handle<v8::Value> external = V8JS_NEW(v8::External, isolate, value);
|
v8::Handle<v8::Value> external = v8::External::New(isolate, value);
|
||||||
newobj = new_tpl->GetFunction()->NewInstance(1, &external);
|
newobj = new_tpl->GetFunction()->NewInstance(1, &external);
|
||||||
|
|
||||||
if (ce == zend_ce_closure) {
|
if (ce == zend_ce_closure) {
|
||||||
@ -981,7 +981,7 @@ static v8::Handle<v8::Value> php_v8js_hash_to_jsobj(zval *value, v8::Isolate *is
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// @todo re-use template likewise
|
// @todo re-use template likewise
|
||||||
v8::Local<v8::FunctionTemplate> new_tpl = V8JS_NEW(v8::FunctionTemplate, isolate, 0);
|
v8::Local<v8::FunctionTemplate> new_tpl = v8::FunctionTemplate::New(isolate, 0);
|
||||||
|
|
||||||
new_tpl->SetClassName(V8JS_SYM("Array"));
|
new_tpl->SetClassName(V8JS_SYM("Array"));
|
||||||
newobj = new_tpl->InstanceTemplate()->NewInstance();
|
newobj = new_tpl->InstanceTemplate()->NewInstance();
|
||||||
@ -1050,7 +1050,7 @@ static v8::Handle<v8::Value> php_v8js_hash_to_jsarr(zval *value, v8::Isolate *is
|
|||||||
return V8JS_NULL;
|
return V8JS_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
newarr = V8JS_NEW(v8::Array, isolate, i);
|
newarr = v8::Array::New(isolate, i);
|
||||||
|
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
{
|
{
|
||||||
|
@ -302,9 +302,9 @@ V8JS_METHOD(require)
|
|||||||
|
|
||||||
// Create a template for the global object and set the built-in global functions
|
// Create a template for the global object and set the built-in global functions
|
||||||
v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
|
v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
|
||||||
global->Set(V8JS_SYM("print"), V8JS_NEW(v8::FunctionTemplate, isolate, V8JS_MN(print)), v8::ReadOnly);
|
global->Set(V8JS_SYM("print"), v8::FunctionTemplate::New(isolate, V8JS_MN(print)), v8::ReadOnly);
|
||||||
global->Set(V8JS_SYM("sleep"), V8JS_NEW(v8::FunctionTemplate, isolate, V8JS_MN(sleep)), v8::ReadOnly);
|
global->Set(V8JS_SYM("sleep"), v8::FunctionTemplate::New(isolate, V8JS_MN(sleep)), v8::ReadOnly);
|
||||||
global->Set(V8JS_SYM("require"), V8JS_NEW(v8::FunctionTemplate, isolate, V8JS_MN(require), V8JS_NEW(v8::External, isolate, c)), v8::ReadOnly);
|
global->Set(V8JS_SYM("require"), v8::FunctionTemplate::New(isolate, V8JS_MN(require), v8::External::New(isolate, c)), v8::ReadOnly);
|
||||||
|
|
||||||
// Add the exports object in which the module can return its API
|
// Add the exports object in which the module can return its API
|
||||||
v8::Local<v8::ObjectTemplate> exports_template = v8::ObjectTemplate::New();
|
v8::Local<v8::ObjectTemplate> exports_template = v8::ObjectTemplate::New();
|
||||||
@ -396,13 +396,13 @@ V8JS_METHOD(require)
|
|||||||
void php_v8js_register_methods(v8::Handle<v8::ObjectTemplate> global, php_v8js_ctx *c) /* {{{ */
|
void php_v8js_register_methods(v8::Handle<v8::ObjectTemplate> global, php_v8js_ctx *c) /* {{{ */
|
||||||
{
|
{
|
||||||
v8::Isolate *isolate = c->isolate;
|
v8::Isolate *isolate = c->isolate;
|
||||||
global->Set(V8JS_SYM("exit"), V8JS_NEW(v8::FunctionTemplate, isolate, V8JS_MN(exit)), v8::ReadOnly);
|
global->Set(V8JS_SYM("exit"), v8::FunctionTemplate::New(isolate, V8JS_MN(exit)), v8::ReadOnly);
|
||||||
global->Set(V8JS_SYM("sleep"), V8JS_NEW(v8::FunctionTemplate, isolate, V8JS_MN(sleep)), v8::ReadOnly);
|
global->Set(V8JS_SYM("sleep"), v8::FunctionTemplate::New(isolate, V8JS_MN(sleep)), v8::ReadOnly);
|
||||||
global->Set(V8JS_SYM("print"), V8JS_NEW(v8::FunctionTemplate, isolate, V8JS_MN(print)), v8::ReadOnly);
|
global->Set(V8JS_SYM("print"), v8::FunctionTemplate::New(isolate, V8JS_MN(print)), v8::ReadOnly);
|
||||||
global->Set(V8JS_SYM("var_dump"), V8JS_NEW(v8::FunctionTemplate, isolate, V8JS_MN(var_dump)), v8::ReadOnly);
|
global->Set(V8JS_SYM("var_dump"), v8::FunctionTemplate::New(isolate, V8JS_MN(var_dump)), v8::ReadOnly);
|
||||||
|
|
||||||
c->modules_base.push_back("");
|
c->modules_base.push_back("");
|
||||||
global->Set(V8JS_SYM("require"), V8JS_NEW(v8::FunctionTemplate, isolate, V8JS_MN(require), V8JS_NEW(v8::External, isolate, c)), v8::ReadOnly);
|
global->Set(V8JS_SYM("require"), v8::FunctionTemplate::New(isolate, V8JS_MN(require), v8::External::New(isolate, c)), v8::ReadOnly);
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ void php_v8js_register_accessors(std::vector<php_v8js_accessor_ctx*> *accessor_l
|
|||||||
ctx->isolate = isolate;
|
ctx->isolate = isolate;
|
||||||
|
|
||||||
/* Set the variable fetch callback for given symbol on named property */
|
/* Set the variable fetch callback for given symbol on named property */
|
||||||
php_obj->SetAccessor(V8JS_STRL(property_name, property_name_len - 1), php_v8js_fetch_php_variable, NULL, V8JS_NEW(v8::External, isolate, ctx), v8::PROHIBITS_OVERWRITING, v8::ReadOnly, V8JS_NEW(v8::AccessorSignature, isolate, php_obj_t));
|
php_obj->SetAccessor(V8JS_STRL(property_name, property_name_len - 1), php_v8js_fetch_php_variable, NULL, v8::External::New(isolate, ctx), v8::PROHIBITS_OVERWRITING, v8::ReadOnly, v8::AccessorSignature::New(isolate, php_obj_t));
|
||||||
|
|
||||||
/* record the context so we can free it later */
|
/* record the context so we can free it later */
|
||||||
accessor_list->push_back(ctx);
|
accessor_list->push_back(ctx);
|
||||||
|
Loading…
Reference in New Issue
Block a user