From 3f77a5a35699369ae162dc84303d85d47dbb4839 Mon Sep 17 00:00:00 2001 From: "C. Scott Ananian" Date: Sun, 27 Oct 2013 01:54:41 -0400 Subject: [PATCH] Make PHP object accessors typesafe using V8::AccessorSignature. This ensures that if you copy the accessor to another object you can't trigger a segfault. --- php_v8js_macros.h | 2 +- v8js.cc | 2 +- v8js_variables.cc | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/php_v8js_macros.h b/php_v8js_macros.h index 38e35e1..5f7a517 100644 --- a/php_v8js_macros.h +++ b/php_v8js_macros.h @@ -143,7 +143,7 @@ v8::Handle zval_to_v8js(zval *, v8::Isolate * TSRMLS_DC); int v8js_to_zval(v8::Handle, zval *, int, v8::Isolate * TSRMLS_DC); /* Register accessors into passed object */ -void php_v8js_register_accessors(v8::Local, zval *, v8::Isolate * TSRMLS_DC); +void php_v8js_register_accessors(v8::Local, zval *, v8::Isolate * TSRMLS_DC); /* {{{ Context container */ struct php_v8js_ctx { diff --git a/v8js.cc b/v8js.cc index d90e926..9aa9ba8 100644 --- a/v8js.cc +++ b/v8js.cc @@ -818,7 +818,7 @@ static PHP_METHOD(V8Js, __construct) /* Register Get accessor for passed variables */ if (vars_arr && zend_hash_num_elements(Z_ARRVAL_P(vars_arr)) > 0) { - php_v8js_register_accessors(php_obj_t->InstanceTemplate(), vars_arr, isolate TSRMLS_CC); + php_v8js_register_accessors(php_obj_t, vars_arr, isolate TSRMLS_CC); } /* Set name for the PHP JS object */ diff --git a/v8js_variables.cc b/v8js_variables.cc index fa81b64..a223f69 100644 --- a/v8js_variables.cc +++ b/v8js_variables.cc @@ -50,12 +50,13 @@ static void php_v8js_fetch_php_variable(v8::Local name, const v8::Pr } /* }}} */ -void php_v8js_register_accessors(v8::Local php_obj, zval *array, v8::Isolate *isolate TSRMLS_DC) /* {{{ */ +void php_v8js_register_accessors(v8::Local php_obj_t, zval *array, v8::Isolate *isolate TSRMLS_DC) /* {{{ */ { char *property_name; uint property_name_len; ulong index; zval **item; + v8::Local php_obj = php_obj_t->InstanceTemplate(); for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(array)); zend_hash_get_current_data(Z_ARRVAL_P(array), (void **) &item) != FAILURE; @@ -85,7 +86,7 @@ void php_v8js_register_accessors(v8::Local php_obj, zval *ar ctx->isolate = isolate; /* Set the variable fetch callback for given symbol on named property */ - php_obj->SetAccessor(V8JS_STRL(property_name, property_name_len - 1), php_v8js_fetch_php_variable, NULL, v8::External::New(ctx), v8::PROHIBITS_OVERWRITING, v8::ReadOnly); + php_obj->SetAccessor(V8JS_STRL(property_name, property_name_len - 1), php_v8js_fetch_php_variable, NULL, v8::External::New(ctx), v8::PROHIBITS_OVERWRITING, v8::ReadOnly, v8::AccessorSignature::New(php_obj_t)); } } /* }}} */