0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-11-09 23:08:41 +00:00

Make compatible with V8 3.24.10, fixes #83

This commit is contained in:
Stefan Siegl 2014-03-22 00:07:53 +01:00
parent 98d535b8b1
commit 4c64bc4ad9
4 changed files with 26 additions and 16 deletions

View File

@ -47,7 +47,15 @@ extern "C" {
#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)
#define V8JS_STR(v) v8::String::NewFromUtf8(isolate, v) #define V8JS_STR(v) v8::String::NewFromUtf8(isolate, v)
#define V8JS_STRL(v, l) v8::String::NewFromUtf8(isolate, v, v8::String::kNormalString, l) #define V8JS_STRL(v, l) v8::String::NewFromUtf8(isolate, v, v8::String::kNormalString, l)
#if PHP_V8_API_VERSION < 3024010
#define V8JS_INT(v) v8::Integer::New(v, isolate) #define V8JS_INT(v) v8::Integer::New(v, isolate)
#define V8JS_UINT(v) v8::Integer::NewFromUnsigned(v, isolate)
#else
#define V8JS_INT(v) v8::Integer::New(isolate, v)
#define V8JS_UINT(v) v8::Integer::NewFromUnsigned(isolate, v)
#endif
#define V8JS_FLOAT(v) v8::Number::New(isolate, v) #define V8JS_FLOAT(v) v8::Number::New(isolate, v)
#define V8JS_BOOL(v) ((v)?v8::True(isolate):v8::False(isolate)) #define V8JS_BOOL(v) ((v)?v8::True(isolate):v8::False(isolate))
#define V8JS_NULL v8::Null(isolate) #define V8JS_NULL v8::Null(isolate)

View File

@ -818,7 +818,8 @@ 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 = v8::FunctionTemplate::New(); v8::Local<v8::FunctionTemplate> tpl = V8JS_NEW(v8::FunctionTemplate, 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);
@ -845,7 +846,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 = v8::FunctionTemplate::New(); v8::Local<v8::FunctionTemplate> php_obj_t = V8JS_NEW(v8::FunctionTemplate, isolate, 0);
/* Set class name for PHP object */ /* Set class name for PHP object */
#if PHP_VERSION_ID >= 50400 #if PHP_VERSION_ID >= 50400

View File

@ -279,7 +279,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) \
v8::FunctionTemplate::New(php_v8js_php_callback, V8JS_NEW(v8::External, (isolate), mptr), V8JS_NEW(v8::Signature, (isolate), tmpl))->GetFunction() V8JS_NEW(v8::FunctionTemplate, (isolate), php_v8js_php_callback, V8JS_NEW(v8::External, (isolate), mptr), V8JS_NEW(v8::Signature, (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) /* {{{ */
@ -545,7 +545,7 @@ 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 =
v8::FunctionTemplate::New( V8JS_NEW(v8::FunctionTemplate, isolate,
php_v8js_fake_call_impl, V8JS_NULL, php_v8js_fake_call_impl, V8JS_NULL,
V8JS_NEW(v8::Signature, isolate, tmpl))->GetFunction(); V8JS_NEW(v8::Signature, isolate, tmpl))->GetFunction();
cb->SetName(property); cb->SetName(property);
@ -556,7 +556,7 @@ static inline v8::Local<v8::Value> php_v8js_named_property_callback(v8::Local<v8
} }
} else if (callback_type == V8JS_PROP_QUERY) { } else if (callback_type == V8JS_PROP_QUERY) {
// methods are not enumerable // methods are not enumerable
ret_value = v8::Integer::NewFromUnsigned(v8::ReadOnly|v8::DontEnum|v8::DontDelete, isolate); ret_value = V8JS_UINT(v8::ReadOnly|v8::DontEnum|v8::DontDelete);
} else if (callback_type == V8JS_PROP_SETTER) { } else if (callback_type == V8JS_PROP_SETTER) {
ret_value = set_value; // lie. this field is read-only. ret_value = set_value; // lie. this field is read-only.
} else if (callback_type == V8JS_PROP_DELETER) { } else if (callback_type == V8JS_PROP_DELETER) {
@ -606,7 +606,7 @@ static inline v8::Local<v8::Value> php_v8js_named_property_callback(v8::Local<v8
ZVAL_STRINGL(prop, name, name_len, 1); ZVAL_STRINGL(prop, name, name_len, 1);
if (callback_type == V8JS_PROP_QUERY) { if (callback_type == V8JS_PROP_QUERY) {
if (h->has_property(object, prop, 0 ZEND_HASH_KEY_NULL TSRMLS_CC)) { if (h->has_property(object, prop, 0 ZEND_HASH_KEY_NULL TSRMLS_CC)) {
ret_value = v8::Integer::NewFromUnsigned(v8::None); ret_value = V8JS_UINT(v8::None);
} else { } else {
ret_value = v8::Handle<v8::Value>(); // empty handle ret_value = v8::Handle<v8::Value>(); // empty handle
} }
@ -701,7 +701,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 = v8::FunctionTemplate::New(); new_tpl = V8JS_NEW(v8::FunctionTemplate, 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);
@ -750,7 +750,8 @@ static v8::Handle<v8::Value> php_v8js_hash_to_jsobj(zval *value, v8::Isolate *is
persist_newobj2.SetWeak(persist_tpl_, php_v8js_weak_closure_callback); persist_newobj2.SetWeak(persist_tpl_, php_v8js_weak_closure_callback);
} }
} else { } else {
v8::Local<v8::FunctionTemplate> new_tpl = v8::FunctionTemplate::New(); // @todo re-use template likewise // @todo re-use template likewise
v8::Local<v8::FunctionTemplate> new_tpl = V8JS_NEW(v8::FunctionTemplate, isolate, 0);
new_tpl->SetClassName(V8JS_SYM("Array")); new_tpl->SetClassName(V8JS_SYM("Array"));
newobj = new_tpl->InstanceTemplate()->NewInstance(); newobj = new_tpl->InstanceTemplate()->NewInstance();

View File

@ -298,9 +298,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"), v8::FunctionTemplate::New(V8JS_MN(print)), v8::ReadOnly); global->Set(V8JS_SYM("print"), V8JS_NEW(v8::FunctionTemplate, isolate, V8JS_MN(print)), v8::ReadOnly);
global->Set(V8JS_SYM("sleep"), v8::FunctionTemplate::New(V8JS_MN(sleep)), v8::ReadOnly); global->Set(V8JS_SYM("sleep"), V8JS_NEW(v8::FunctionTemplate, isolate, V8JS_MN(sleep)), v8::ReadOnly);
global->Set(V8JS_SYM("require"), v8::FunctionTemplate::New(V8JS_MN(require), V8JS_NEW(v8::External, isolate, c)), v8::ReadOnly); global->Set(V8JS_SYM("require"), V8JS_NEW(v8::FunctionTemplate, isolate, V8JS_MN(require), V8JS_NEW(v8::External, 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();
@ -387,13 +387,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"), v8::FunctionTemplate::New(V8JS_MN(exit)), v8::ReadOnly); global->Set(V8JS_SYM("exit"), V8JS_NEW(v8::FunctionTemplate, isolate, V8JS_MN(exit)), v8::ReadOnly);
global->Set(V8JS_SYM("sleep"), v8::FunctionTemplate::New(V8JS_MN(sleep)), v8::ReadOnly); global->Set(V8JS_SYM("sleep"), V8JS_NEW(v8::FunctionTemplate, isolate, V8JS_MN(sleep)), v8::ReadOnly);
global->Set(V8JS_SYM("print"), v8::FunctionTemplate::New(V8JS_MN(print)), v8::ReadOnly); global->Set(V8JS_SYM("print"), V8JS_NEW(v8::FunctionTemplate, isolate, V8JS_MN(print)), v8::ReadOnly);
global->Set(V8JS_SYM("var_dump"), v8::FunctionTemplate::New(V8JS_MN(var_dump)), v8::ReadOnly); global->Set(V8JS_SYM("var_dump"), V8JS_NEW(v8::FunctionTemplate, isolate, V8JS_MN(var_dump)), v8::ReadOnly);
c->modules_base.push_back(""); c->modules_base.push_back("");
global->Set(V8JS_SYM("require"), v8::FunctionTemplate::New(V8JS_MN(require), V8JS_NEW(v8::External, isolate, c)), v8::ReadOnly); global->Set(V8JS_SYM("require"), V8JS_NEW(v8::FunctionTemplate, isolate, V8JS_MN(require), V8JS_NEW(v8::External, isolate, c)), v8::ReadOnly);
} }
/* }}} */ /* }}} */