22 +----------------------------------------------------------------------+
33 | PHP Version 5 |
44 +----------------------------------------------------------------------+
5- | Copyright (c) 1997-2013 The PHP Group |
5+ | Copyright (c) 1997-2016 The PHP Group |
66 +----------------------------------------------------------------------+
77 | http://www.opensource.org/licenses/mit-license.php MIT License |
88 +----------------------------------------------------------------------+
99 | Author: Jani Taskinen <jani.taskinen@iki.fi> |
1010 | Author: Patrick Reilly <preilly@php.net> |
11+ | Author: Stefan Siegl <stesie@php.net> |
1112 +----------------------------------------------------------------------+
1213*/
1314
@@ -88,13 +89,9 @@ static void v8js_call_php_func(zval *value, zend_class_entry *ce, zend_function
8889 fci.params = (zval ***) safe_emalloc (argc, sizeof (zval **), 0 );
8990 argv = (zval **) safe_emalloc (argc, sizeof (zval *), 0 );
9091 for (i = 0 ; i < argc; i++) {
91- v8::Local<v8::Value> php_object;
92- if (info[i]->IsObject ()) {
93- php_object = v8::Local<v8::Object>::Cast (info[i])->GetHiddenValue (V8JS_SYM (PHPJS_OBJECT_KEY));
94- }
95- if (!php_object.IsEmpty ()) {
92+ if (info[i]->IsObject () && info[i]->ToObject ()->InternalFieldCount ()) {
9693 /* This is a PHP object, passed to JS and back. */
97- argv[i] = reinterpret_cast <zval *>(v8::External::Cast (*php_object )->Value ( ));
94+ argv[i] = reinterpret_cast <zval *>(info[i]-> ToObject ( )->GetAlignedPointerFromInternalField ( 1 ));
9895 Z_ADDREF_P (argv[i]);
9996 } else {
10097 MAKE_STD_ZVAL (argv[i]);
@@ -178,7 +175,7 @@ void v8js_php_callback(const v8::FunctionCallbackInfo<v8::Value>& info) /* {{{ *
178175 v8::Local<v8::Object> self = info.Holder ();
179176
180177 V8JS_TSRMLS_FETCH ();
181- zval *value = reinterpret_cast <zval *>(v8::External::Cast (* self->GetHiddenValue ( V8JS_SYM (PHPJS_OBJECT_KEY)))-> Value ( ));
178+ zval *value = reinterpret_cast <zval *>(self->GetAlignedPointerFromInternalField ( 1 ));
182179 zend_function *method_ptr;
183180 zend_class_entry *ce = Z_OBJCE_P (value);
184181
@@ -198,9 +195,7 @@ static void v8js_construct_callback(const v8::FunctionCallbackInfo<v8::Value>& i
198195 v8::Isolate *isolate = info.GetIsolate ();
199196 info.GetReturnValue ().Set (V8JS_UNDEFINED);
200197
201- // @todo assert constructor call
202198 v8::Handle<v8::Object> newobj = info.This ();
203- v8::Local<v8::External> php_object;
204199 zval *value;
205200
206201 if (!info.IsConstructCall ()) {
@@ -215,14 +210,14 @@ static void v8js_construct_callback(const v8::FunctionCallbackInfo<v8::Value>& i
215210
216211 if (info[0 ]->IsExternal ()) {
217212 // Object created by v8js in v8js_hash_to_jsobj, PHP object passed as v8::External.
218- php_object = v8::Local<v8::External>::Cast (info[0 ]);
213+ v8::Local<v8::External> php_object = v8::Local<v8::External>::Cast (info[0 ]);
219214 value = reinterpret_cast <zval *>(php_object->Value ());
220215
221216 if (ctx->weak_objects .count (value)) {
222217 // We already exported this object, hence no need to add another
223218 // ref, v8 won't give us a second weak-object callback anyways.
224219 newobj->SetAlignedPointerInInternalField (0 , ext_tmpl->Value ());
225- newobj->SetHiddenValue ( V8JS_SYM (PHPJS_OBJECT_KEY), php_object );
220+ newobj->SetAlignedPointerInInternalField ( 1 , value );
226221 return ;
227222 }
228223
@@ -248,11 +243,10 @@ static void v8js_construct_callback(const v8::FunctionCallbackInfo<v8::Value>& i
248243 if (ctor_ptr != NULL ) {
249244 v8js_call_php_func (value, ce, ctor_ptr, isolate, info TSRMLS_CC);
250245 }
251- php_object = v8::External::New (isolate, value);
252246 }
253247
254248 newobj->SetAlignedPointerInInternalField (0 , ext_tmpl->Value ());
255- newobj->SetHiddenValue ( V8JS_SYM (PHPJS_OBJECT_KEY), php_object );
249+ newobj->SetAlignedPointerInInternalField ( 1 , value );
256250
257251 // Since we got to decrease the reference count again, in case v8 garbage collector
258252 // decides to dispose the JS object, we add a weak persistent handle and register
@@ -319,7 +313,7 @@ static void v8js_named_property_enumerator(const v8::PropertyCallbackInfo<v8::Ar
319313 uint key_len;
320314 ulong index;
321315
322- zval *object = reinterpret_cast <zval *>(v8::External::Cast (* self->GetHiddenValue ( V8JS_SYM (PHPJS_OBJECT_KEY)))-> Value ( ));
316+ zval *object = reinterpret_cast <zval *>(self->GetAlignedPointerFromInternalField ( 1 ));
323317 ce = Z_OBJCE_P (object);
324318
325319 /* enumerate all methods */
@@ -449,7 +443,7 @@ static void v8js_fake_call_impl(const v8::FunctionCallbackInfo<v8::Value>& info)
449443
450444 V8JS_TSRMLS_FETCH ();
451445 zend_class_entry *ce;
452- zval *object = reinterpret_cast <zval *>(v8::External::Cast (* self->GetHiddenValue ( V8JS_SYM (PHPJS_OBJECT_KEY)))-> Value ( ));
446+ zval *object = reinterpret_cast <zval *>(self->GetAlignedPointerFromInternalField ( 1 ));
453447 ce = Z_OBJCE_P (object);
454448
455449 // first arg is method name, second arg is array of args.
@@ -541,7 +535,7 @@ inline v8::Local<v8::Value> v8js_named_property_callback(v8::Local<v8::String> p
541535 zend_function *method_ptr = NULL ;
542536 zval *php_value;
543537
544- zval *object = reinterpret_cast <zval *>(v8::External::Cast (* self->GetHiddenValue ( V8JS_SYM (PHPJS_OBJECT_KEY)))-> Value ( ));
538+ zval *object = reinterpret_cast <zval *>(self->GetAlignedPointerFromInternalField ( 1 ));
545539 v8js_tmpl_t *tmpl_ptr = reinterpret_cast <v8js_tmpl_t *>(self->GetAlignedPointerFromInternalField (0 ));
546540 v8::Local<v8::FunctionTemplate> tmpl = v8::Local<v8::FunctionTemplate>::New (isolate, *tmpl_ptr);
547541 ce = scope = Z_OBJCE_P (object);
@@ -809,7 +803,7 @@ static v8::Handle<v8::Object> v8js_wrap_object(v8::Isolate *isolate, zend_class_
809803 new_tpl = v8::FunctionTemplate::New (isolate, 0 );
810804
811805 new_tpl->SetClassName (V8JS_STRL (ce->name , ce->name_length ));
812- new_tpl->InstanceTemplate ()->SetInternalFieldCount (1 );
806+ new_tpl->InstanceTemplate ()->SetInternalFieldCount (2 );
813807
814808 if (ce == zend_ce_closure) {
815809 /* Got a closure, mustn't cache ... */
0 commit comments