Skip to content

Commit f6310f9

Browse files
committed
Get rid of V8JS_NEW macro.
1 parent 16af153 commit f6310f9

File tree

5 files changed

+23
-31
lines changed

5 files changed

+23
-31
lines changed

php_v8js_macros.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,6 @@ extern "C" {
3939
/* V8Js Version */
4040
#define V8JS_VERSION "0.1.5"
4141

42-
/* V8 from 3.23.12 has most v8::Anything::New constructors expect isolates
43-
as their first argument. Older versions don't provide these. */
44-
#if PHP_V8_API_VERSION < 3023012
45-
#define V8JS_NEW(t, i, v...) t::New(v)
46-
#else
47-
#define V8JS_NEW(t, i, v...) t::New(i, v)
48-
#endif
49-
5042
/* Helper macros */
5143
#define V8JS_SYM(v) v8::String::NewFromUtf8(isolate, v, v8::String::kInternalizedString, sizeof(v) - 1)
5244
#define V8JS_SYML(v, l) v8::String::NewFromUtf8(isolate, v, v8::String::kInternalizedString, l)

v8js.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ static PHP_METHOD(V8Js, __construct)
963963
/* Create global template for global object */
964964
// Now we are using multiple isolates this needs to be created for every context
965965

966-
v8::Local<v8::FunctionTemplate> tpl = V8JS_NEW(v8::FunctionTemplate, c->isolate, 0);
966+
v8::Local<v8::FunctionTemplate> tpl = v8::FunctionTemplate::New(c->isolate, 0);
967967

968968
tpl->SetClassName(V8JS_SYM("V8Js"));
969969
c->global_template.Reset(isolate, tpl);
@@ -991,7 +991,7 @@ static PHP_METHOD(V8Js, __construct)
991991
v8::Context::Scope context_scope(context);
992992

993993
/* Create the PHP container object's function template */
994-
v8::Local<v8::FunctionTemplate> php_obj_t = V8JS_NEW(v8::FunctionTemplate, isolate, 0);
994+
v8::Local<v8::FunctionTemplate> php_obj_t = v8::FunctionTemplate::New(isolate, 0);
995995

996996
/* Set class name for PHP object */
997997
#if PHP_VERSION_ID >= 50400

v8js_convert.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ static void php_v8js_construct_callback(const v8::FunctionCallbackInfo<v8::Value
318318
if (ctor_ptr != NULL) {
319319
php_v8js_call_php_func(value, ce, ctor_ptr, isolate, info TSRMLS_CC);
320320
}
321-
php_object = V8JS_NEW(v8::External, isolate, value);
321+
php_object = v8::External::New(isolate, value);
322322
}
323323

324324
newobj->SetAlignedPointerInInternalField(0, ext_tmpl->Value());
@@ -405,15 +405,15 @@ static void php_v8js_weak_closure_callback(const v8::WeakCallbackData<v8::Object
405405
!strncasecmp(key, mname, key_len - 1))
406406

407407
#define PHP_V8JS_CALLBACK(isolate, mptr, tmpl) \
408-
V8JS_NEW(v8::FunctionTemplate, (isolate), php_v8js_php_callback, V8JS_NEW(v8::External, (isolate), mptr), V8JS_NEW(v8::Signature, (isolate), tmpl))->GetFunction()
408+
v8::FunctionTemplate::New((isolate), php_v8js_php_callback, v8::External::New((isolate), mptr), v8::Signature::New((isolate), tmpl))->GetFunction()
409409

410410

411411
static void php_v8js_named_property_enumerator(const v8::PropertyCallbackInfo<v8::Array> &info) /* {{{ */
412412
{
413413
// note: 'special' properties like 'constructor' are not enumerated.
414414
v8::Isolate *isolate = info.GetIsolate();
415415
v8::Local<v8::Object> self = info.Holder();
416-
v8::Local<v8::Array> result = V8JS_NEW(v8::Array, isolate, 0);
416+
v8::Local<v8::Array> result = v8::Array::New(isolate, 0);
417417
uint32_t result_len = 0;
418418

419419
V8JS_TSRMLS_FETCH();
@@ -690,9 +690,9 @@ static inline v8::Local<v8::Value> php_v8js_named_property_callback(v8::Local<v8
690690
// (only use this if method_ptr==NULL, which means
691691
// there is no actual PHP __call() implementation)
692692
v8::Local<v8::Function> cb =
693-
V8JS_NEW(v8::FunctionTemplate, isolate,
693+
v8::FunctionTemplate::New(isolate,
694694
php_v8js_fake_call_impl, V8JS_NULL,
695-
V8JS_NEW(v8::Signature, isolate, tmpl))->GetFunction();
695+
v8::Signature::New(isolate, tmpl))->GetFunction();
696696
cb->SetName(property);
697697
ret_value = cb;
698698
} else {
@@ -931,7 +931,7 @@ static v8::Handle<v8::Value> php_v8js_hash_to_jsobj(zval *value, v8::Isolate *is
931931
}
932932
catch (const std::out_of_range &) {
933933
/* No cached v8::FunctionTemplate available as of yet, create one. */
934-
new_tpl = V8JS_NEW(v8::FunctionTemplate, isolate, 0);
934+
new_tpl = v8::FunctionTemplate::New(isolate, 0);
935935

936936
new_tpl->SetClassName(V8JS_STRL(ce->name, ce->name_length));
937937
new_tpl->InstanceTemplate()->SetInternalFieldCount(1);
@@ -964,14 +964,14 @@ static v8::Handle<v8::Value> php_v8js_hash_to_jsobj(zval *value, v8::Isolate *is
964964
new_tpl->InstanceTemplate()->SetCallAsFunctionHandler(php_v8js_invoke_callback, PHP_V8JS_CALLBACK(isolate, invoke_method_ptr, new_tpl));
965965
}
966966
}
967-
v8::Local<v8::Array> call_handler_data = V8JS_NEW(v8::Array, isolate, 2);
968-
call_handler_data->Set(0, V8JS_NEW(v8::External, isolate, persist_tpl_));
969-
call_handler_data->Set(1, V8JS_NEW(v8::External, isolate, ce));
967+
v8::Local<v8::Array> call_handler_data = v8::Array::New(isolate, 2);
968+
call_handler_data->Set(0, v8::External::New(isolate, persist_tpl_));
969+
call_handler_data->Set(1, v8::External::New(isolate, ce));
970970
new_tpl->SetCallHandler(php_v8js_construct_callback, call_handler_data);
971971
}
972972

973973
// Create v8 wrapper object
974-
v8::Handle<v8::Value> external = V8JS_NEW(v8::External, isolate, value);
974+
v8::Handle<v8::Value> external = v8::External::New(isolate, value);
975975
newobj = new_tpl->GetFunction()->NewInstance(1, &external);
976976

977977
if (ce == zend_ce_closure) {
@@ -981,7 +981,7 @@ static v8::Handle<v8::Value> php_v8js_hash_to_jsobj(zval *value, v8::Isolate *is
981981
}
982982
} else {
983983
// @todo re-use template likewise
984-
v8::Local<v8::FunctionTemplate> new_tpl = V8JS_NEW(v8::FunctionTemplate, isolate, 0);
984+
v8::Local<v8::FunctionTemplate> new_tpl = v8::FunctionTemplate::New(isolate, 0);
985985

986986
new_tpl->SetClassName(V8JS_SYM("Array"));
987987
newobj = new_tpl->InstanceTemplate()->NewInstance();
@@ -1050,7 +1050,7 @@ static v8::Handle<v8::Value> php_v8js_hash_to_jsarr(zval *value, v8::Isolate *is
10501050
return V8JS_NULL;
10511051
}
10521052

1053-
newarr = V8JS_NEW(v8::Array, isolate, i);
1053+
newarr = v8::Array::New(isolate, i);
10541054

10551055
if (i > 0)
10561056
{

v8js_methods.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,9 @@ V8JS_METHOD(require)
302302

303303
// Create a template for the global object and set the built-in global functions
304304
v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
305-
global->Set(V8JS_SYM("print"), V8JS_NEW(v8::FunctionTemplate, isolate, V8JS_MN(print)), v8::ReadOnly);
306-
global->Set(V8JS_SYM("sleep"), V8JS_NEW(v8::FunctionTemplate, isolate, V8JS_MN(sleep)), v8::ReadOnly);
307-
global->Set(V8JS_SYM("require"), V8JS_NEW(v8::FunctionTemplate, isolate, V8JS_MN(require), V8JS_NEW(v8::External, isolate, c)), v8::ReadOnly);
305+
global->Set(V8JS_SYM("print"), v8::FunctionTemplate::New(isolate, V8JS_MN(print)), v8::ReadOnly);
306+
global->Set(V8JS_SYM("sleep"), v8::FunctionTemplate::New(isolate, V8JS_MN(sleep)), v8::ReadOnly);
307+
global->Set(V8JS_SYM("require"), v8::FunctionTemplate::New(isolate, V8JS_MN(require), v8::External::New(isolate, c)), v8::ReadOnly);
308308

309309
// Add the exports object in which the module can return its API
310310
v8::Local<v8::ObjectTemplate> exports_template = v8::ObjectTemplate::New();
@@ -396,13 +396,13 @@ V8JS_METHOD(require)
396396
void php_v8js_register_methods(v8::Handle<v8::ObjectTemplate> global, php_v8js_ctx *c) /* {{{ */
397397
{
398398
v8::Isolate *isolate = c->isolate;
399-
global->Set(V8JS_SYM("exit"), V8JS_NEW(v8::FunctionTemplate, isolate, V8JS_MN(exit)), v8::ReadOnly);
400-
global->Set(V8JS_SYM("sleep"), V8JS_NEW(v8::FunctionTemplate, isolate, V8JS_MN(sleep)), v8::ReadOnly);
401-
global->Set(V8JS_SYM("print"), V8JS_NEW(v8::FunctionTemplate, isolate, V8JS_MN(print)), v8::ReadOnly);
402-
global->Set(V8JS_SYM("var_dump"), V8JS_NEW(v8::FunctionTemplate, isolate, V8JS_MN(var_dump)), v8::ReadOnly);
399+
global->Set(V8JS_SYM("exit"), v8::FunctionTemplate::New(isolate, V8JS_MN(exit)), v8::ReadOnly);
400+
global->Set(V8JS_SYM("sleep"), v8::FunctionTemplate::New(isolate, V8JS_MN(sleep)), v8::ReadOnly);
401+
global->Set(V8JS_SYM("print"), v8::FunctionTemplate::New(isolate, V8JS_MN(print)), v8::ReadOnly);
402+
global->Set(V8JS_SYM("var_dump"), v8::FunctionTemplate::New(isolate, V8JS_MN(var_dump)), v8::ReadOnly);
403403

404404
c->modules_base.push_back("");
405-
global->Set(V8JS_SYM("require"), V8JS_NEW(v8::FunctionTemplate, isolate, V8JS_MN(require), V8JS_NEW(v8::External, isolate, c)), v8::ReadOnly);
405+
global->Set(V8JS_SYM("require"), v8::FunctionTemplate::New(isolate, V8JS_MN(require), v8::External::New(isolate, c)), v8::ReadOnly);
406406
}
407407
/* }}} */
408408

v8js_variables.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void php_v8js_register_accessors(std::vector<php_v8js_accessor_ctx*> *accessor_l
8686
ctx->isolate = isolate;
8787

8888
/* Set the variable fetch callback for given symbol on named property */
89-
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));
89+
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));
9090

9191
/* record the context so we can free it later */
9292
accessor_list->push_back(ctx);

0 commit comments

Comments
 (0)