0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-12-22 14:01:53 +00:00

Add GC_(UN)PROTECT_RECURSION, move (un)protecting outside loops

This commit is contained in:
Jan-E 2018-07-05 11:41:32 +02:00
parent 826aaa689c
commit 0c2b55d802
3 changed files with 44 additions and 23 deletions

View File

@ -166,6 +166,17 @@ extern struct _v8js_process_globals v8js_process_globals;
/* Register builtin methods into passed object */
void v8js_register_methods(v8::Local<v8::ObjectTemplate>, 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 */
/*

View File

@ -84,21 +84,26 @@ static v8::Local<v8::Value> v8js_hash_to_jsarr(zval *value, v8::Isolate *isolate
{
zval *data;
ulong index = 0;
HashTable *tmp_ht;
#if PHP_VERSION_ID >= 70300
if (myht && !(GC_FLAGS(myht) & GC_IMMUTABLE)) {
#else
if (myht) {
#endif
GC_PROTECT_RECURSION(myht);
}
ZEND_HASH_FOREACH_VAL(myht, data) {
tmp_ht = HASH_OF(data);
if (tmp_ht) {
ZEND_HASH_INC_APPLY_COUNT(myht);
}
newarr->Set(index++, zval_to_v8js(data, isolate));
if (tmp_ht) {
ZEND_HASH_DEC_APPLY_COUNT(myht);
}
} ZEND_HASH_FOREACH_END();
#if PHP_VERSION_ID >= 70300
if (myht && !(GC_FLAGS(myht) & GC_IMMUTABLE)) {
#else
if (myht) {
#endif
GC_UNPROTECT_RECURSION(myht);
}
}
return newarr;
}

View File

@ -955,21 +955,20 @@ static v8::Local<v8::Object> v8js_wrap_array_to_object(v8::Isolate *isolate, zva
if (i > 0)
{
zval *data;
HashTable *tmp_ht;
#if PHP_VERSION_ID >= 70300
if (myht && !(GC_FLAGS(myht) & GC_IMMUTABLE)) {
#else
if (myht) {
#endif
GC_PROTECT_RECURSION(myht);
}
ZEND_HASH_FOREACH_KEY_VAL(myht, index, key, data) {
tmp_ht = HASH_OF(data);
if (tmp_ht) {
ZEND_HASH_INC_APPLY_COUNT(tmp_ht);
}
if (key) {
if (ZSTR_VAL(key)[0] == '\0' && Z_TYPE_P(value) == IS_OBJECT) {
/* Skip protected and private members. */
if (tmp_ht) {
ZEND_HASH_DEC_APPLY_COUNT(tmp_ht);
}
continue;
}
@ -991,10 +990,16 @@ static v8::Local<v8::Object> v8js_wrap_array_to_object(v8::Isolate *isolate, zva
newobj->Set(static_cast<uint32_t>(index), zval_to_v8js(data, isolate));
}
if (tmp_ht) {
ZEND_HASH_DEC_APPLY_COUNT(tmp_ht);
}
} ZEND_HASH_FOREACH_END();
#if PHP_VERSION_ID >= 70300
if (myht && !(GC_FLAGS(myht) & GC_IMMUTABLE)) {
#else
if (myht) {
#endif
GC_UNPROTECT_RECURSION(myht);
}
}
return newobj;