mirror of
https://github.com/phpv8/v8js.git
synced 2025-01-05 11:41:52 +00:00
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.
This commit is contained in:
parent
879d1d54a2
commit
3f77a5a356
@ -143,7 +143,7 @@ v8::Handle<v8::Value> zval_to_v8js(zval *, v8::Isolate * TSRMLS_DC);
|
|||||||
int v8js_to_zval(v8::Handle<v8::Value>, zval *, int, v8::Isolate * TSRMLS_DC);
|
int v8js_to_zval(v8::Handle<v8::Value>, zval *, int, v8::Isolate * TSRMLS_DC);
|
||||||
|
|
||||||
/* Register accessors into passed object */
|
/* Register accessors into passed object */
|
||||||
void php_v8js_register_accessors(v8::Local<v8::ObjectTemplate>, zval *, v8::Isolate * TSRMLS_DC);
|
void php_v8js_register_accessors(v8::Local<v8::FunctionTemplate>, zval *, v8::Isolate * TSRMLS_DC);
|
||||||
|
|
||||||
/* {{{ Context container */
|
/* {{{ Context container */
|
||||||
struct php_v8js_ctx {
|
struct php_v8js_ctx {
|
||||||
|
2
v8js.cc
2
v8js.cc
@ -818,7 +818,7 @@ static PHP_METHOD(V8Js, __construct)
|
|||||||
|
|
||||||
/* Register Get accessor for passed variables */
|
/* Register Get accessor for passed variables */
|
||||||
if (vars_arr && zend_hash_num_elements(Z_ARRVAL_P(vars_arr)) > 0) {
|
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 */
|
/* Set name for the PHP JS object */
|
||||||
|
@ -50,12 +50,13 @@ static void php_v8js_fetch_php_variable(v8::Local<v8::String> name, const v8::Pr
|
|||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
void php_v8js_register_accessors(v8::Local<v8::ObjectTemplate> php_obj, zval *array, v8::Isolate *isolate TSRMLS_DC) /* {{{ */
|
void php_v8js_register_accessors(v8::Local<v8::FunctionTemplate> php_obj_t, zval *array, v8::Isolate *isolate TSRMLS_DC) /* {{{ */
|
||||||
{
|
{
|
||||||
char *property_name;
|
char *property_name;
|
||||||
uint property_name_len;
|
uint property_name_len;
|
||||||
ulong index;
|
ulong index;
|
||||||
zval **item;
|
zval **item;
|
||||||
|
v8::Local<v8::ObjectTemplate> php_obj = php_obj_t->InstanceTemplate();
|
||||||
|
|
||||||
for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(array));
|
for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(array));
|
||||||
zend_hash_get_current_data(Z_ARRVAL_P(array), (void **) &item) != FAILURE;
|
zend_hash_get_current_data(Z_ARRVAL_P(array), (void **) &item) != FAILURE;
|
||||||
@ -85,7 +86,7 @@ void php_v8js_register_accessors(v8::Local<v8::ObjectTemplate> php_obj, zval *ar
|
|||||||
ctx->isolate = isolate;
|
ctx->isolate = isolate;
|
||||||
|
|
||||||
/* Set the variable fetch callback for given symbol on named property */
|
/* 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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
Loading…
Reference in New Issue
Block a user