diff --git a/php_v8js_macros.h b/php_v8js_macros.h index a578057..2503663 100644 --- a/php_v8js_macros.h +++ b/php_v8js_macros.h @@ -167,11 +167,15 @@ extern struct _v8js_process_globals v8js_process_globals; void v8js_register_methods(v8::Local, v8js_ctx *c); #ifdef ZEND_HASH_INC_APPLY_COUNT +#ifndef GC_PROTECT_RECURSION # define GC_PROTECT_RECURSION(ht) ZEND_HASH_INC_APPLY_COUNT(ht) #endif +#endif #ifdef ZEND_HASH_DEC_APPLY_COUNT +#ifndef GC_UNPROTECT_RECURSION # define GC_UNPROTECT_RECURSION(ht) ZEND_HASH_DEC_APPLY_COUNT(ht) #endif +#endif #endif /* PHP_V8JS_MACROS_H */ diff --git a/v8js_convert.cc b/v8js_convert.cc index da52980..2b62137 100644 --- a/v8js_convert.cc +++ b/v8js_convert.cc @@ -84,21 +84,18 @@ static v8::Local v8js_hash_to_jsarr(zval *value, v8::Isolate *isolate { zval *data; ulong index = 0; - HashTable *tmp_ht; + + if (myht && !(GC_FLAGS(myht) & GC_IMMUTABLE)) { + GC_PROTECT_RECURSION(myht); + } ZEND_HASH_FOREACH_VAL(myht, data) { - tmp_ht = HASH_OF(data); - - if (tmp_ht) { - GC_PROTECT_RECURSION(myht); - } - newarr->Set(index++, zval_to_v8js(data, isolate)); - - if (tmp_ht) { - GC_UNPROTECT_RECURSION(myht); - } } ZEND_HASH_FOREACH_END(); + + if (myht && !(GC_FLAGS(myht) & GC_IMMUTABLE)) { + GC_UNPROTECT_RECURSION(myht); + } } return newarr; } diff --git a/v8js_object_export.cc b/v8js_object_export.cc index 0092737..86ff6f6 100644 --- a/v8js_object_export.cc +++ b/v8js_object_export.cc @@ -955,21 +955,16 @@ static v8::Local v8js_wrap_array_to_object(v8::Isolate *isolate, zva if (i > 0) { zval *data; - HashTable *tmp_ht; + + if (myht && !(GC_FLAGS(myht) & GC_IMMUTABLE)) { + GC_PROTECT_RECURSION(myht); + } ZEND_HASH_FOREACH_KEY_VAL(myht, index, key, data) { - tmp_ht = HASH_OF(data); - - if (tmp_ht) { - GC_PROTECT_RECURSION(tmp_ht); - } if (key) { if (ZSTR_VAL(key)[0] == '\0' && Z_TYPE_P(value) == IS_OBJECT) { /* Skip protected and private members. */ - if (tmp_ht) { - GC_UNPROTECT_RECURSION(tmp_ht); - } continue; } @@ -991,10 +986,12 @@ static v8::Local v8js_wrap_array_to_object(v8::Isolate *isolate, zva newobj->Set(static_cast(index), zval_to_v8js(data, isolate)); } - if (tmp_ht) { - GC_UNPROTECT_RECURSION(tmp_ht); - } } ZEND_HASH_FOREACH_END(); + + if (myht && !(GC_FLAGS(myht) & GC_IMMUTABLE)) { + GC_UNPROTECT_RECURSION(myht); + } + } return newobj;