0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-11-08 18:58:41 +00:00

Adapt to PHP7

This commit is contained in:
Stefan Siegl 2015-08-29 17:48:26 +02:00
parent 5477d780a3
commit fd6eeddc52
5 changed files with 38 additions and 42 deletions

View File

@ -90,8 +90,7 @@ int v8js_to_zval(v8::Handle<v8::Value>, zval *, int, v8::Isolate * TSRMLS_DC);
struct v8js_accessor_ctx struct v8js_accessor_ctx
{ {
char *variable_name_string; zend_string *variable_name;
uint variable_name_string_len;
v8::Isolate *isolate; v8::Isolate *isolate;
}; };
@ -128,11 +127,7 @@ extern zend_v8js_globals v8js_globals;
ZEND_EXTERN_MODULE_GLOBALS(v8js) ZEND_EXTERN_MODULE_GLOBALS(v8js)
#ifdef ZTS #define V8JSG(v) ZEND_MODULE_GLOBALS_ACCESSOR(v8js, v)
# define V8JSG(v) TSRMG(v8js_globals_id, zend_v8js_globals *, v)
#else
# define V8JSG(v) (v8js_globals.v)
#endif
/* Register builtin methods into passed object */ /* Register builtin methods into passed object */
void v8js_register_methods(v8::Handle<v8::ObjectTemplate>, v8js_ctx *c); void v8js_register_methods(v8::Handle<v8::ObjectTemplate>, v8js_ctx *c);

View File

@ -92,6 +92,10 @@ ZEND_INI_END()
#ifdef COMPILE_DL_V8JS #ifdef COMPILE_DL_V8JS
#ifdef ZTS
ZEND_TSRMLS_CACHE_DEFINE();
#endif
ZEND_GET_MODULE(v8js) ZEND_GET_MODULE(v8js)
#endif #endif
@ -155,6 +159,10 @@ static PHP_MINFO_FUNCTION(v8js)
*/ */
static PHP_GINIT_FUNCTION(v8js) static PHP_GINIT_FUNCTION(v8js)
{ {
#if defined(COMPILE_DL_MYSQLI) && defined(ZTS)
ZEND_TSRMLS_CACHE_UPDATE();
#endif
/* /*
If ZTS is disabled, the v8js_globals instance is declared right If ZTS is disabled, the v8js_globals instance is declared right
in the BSS and hence automatically initialized by C++ compiler. in the BSS and hence automatically initialized by C++ compiler.

View File

@ -31,7 +31,8 @@ extern "C" {
static void v8js_timer_interrupt_handler(v8::Isolate *isolate, void *data) { /* {{{ */ static void v8js_timer_interrupt_handler(v8::Isolate *isolate, void *data) { /* {{{ */
#ifdef ZTS #ifdef ZTS
TSRMLS_D = (void ***) data; // @fixme
//TSRMLS_D = (void ***) data;
#endif #endif
if (!V8JSG(timer_stack).size()) { if (!V8JSG(timer_stack).size()) {
@ -91,7 +92,8 @@ void v8js_timer_thread(TSRMLS_D) /* {{{ */
* and cannot aquire it as v8 is executing the script ... */ * and cannot aquire it as v8 is executing the script ... */
void *data = NULL; void *data = NULL;
#ifdef ZTS #ifdef ZTS
data = (void *) TSRMLS_C; // @fixme
//data = (void *) TSRMLS_C;
#endif #endif
c->isolate->RequestInterrupt(v8js_timer_interrupt_handler, data); c->isolate->RequestInterrupt(v8js_timer_interrupt_handler, data);
} }

View File

@ -162,9 +162,10 @@ void v8js_v8_call(v8js_ctx *c, zval **return_value,
} }
/* There was pending exception left from earlier executions -> throw to PHP */ /* There was pending exception left from earlier executions -> throw to PHP */
if (c->pending_exception) { if (Z_TYPE(c->pending_exception) == IS_OBJECT) {
zend_throw_exception_object(c->pending_exception TSRMLS_CC); zend_throw_exception_object(&c->pending_exception TSRMLS_CC);
c->pending_exception = NULL; zval_dtor(&c->pending_exception);
ZVAL_NULL(&c->pending_exception);
} }
/* Handle runtime JS exceptions */ /* Handle runtime JS exceptions */
@ -181,8 +182,7 @@ void v8js_v8_call(v8js_ctx *c, zval **return_value,
/* Exception thrown from JS, preserve it for future execution */ /* Exception thrown from JS, preserve it for future execution */
if (result.IsEmpty()) { if (result.IsEmpty()) {
MAKE_STD_ZVAL(c->pending_exception); v8js_create_script_exception(&c->pending_exception, &try_catch TSRMLS_CC);
v8js_create_script_exception(c->pending_exception, &try_catch TSRMLS_CC);
return; return;
} }
} }
@ -225,7 +225,8 @@ int v8js_get_properties_hash(v8::Handle<v8::Value> jsValue, HashTable *retval, i
v8::Local<v8::Value> jsVal = jsObj->Get(jsKey); v8::Local<v8::Value> jsVal = jsObj->Get(jsKey);
v8::String::Utf8Value cstr(jsKey); v8::String::Utf8Value cstr(jsKey);
const char *key = ToCString(cstr); const char *c_key = ToCString(cstr);
zend_string *key = zend_string_init(c_key, jsKey->ToString()->Utf8Length(), 0);
zval value; zval value;
ZVAL_UNDEF(&value); ZVAL_UNDEF(&value);
@ -235,21 +236,21 @@ int v8js_get_properties_hash(v8::Handle<v8::Value> jsValue, HashTable *retval, i
} }
if (!php_object.IsEmpty()) { if (!php_object.IsEmpty()) {
/* This is a PHP object, passed to JS and back. */ /* This is a PHP object, passed to JS and back. */
zend_object object = reinterpret_cast<zend_object *>(v8::External::Cast(*php_object)->Value()); zend_object *object = reinterpret_cast<zend_object *>(v8::External::Cast(*php_object)->Value());
ZVAL_OBJ(&value, object); ZVAL_OBJ(&value, object);
Z_ADDREF_P(value); Z_ADDREF_P(&value);
} }
else { else {
if (v8js_to_zval(jsVal, value, flags, isolate TSRMLS_CC) == FAILURE) { if (v8js_to_zval(jsVal, &value, flags, isolate TSRMLS_CC) == FAILURE) {
zval_dtor(&value); zval_dtor(&value);
return FAILURE; return FAILURE;
} }
} }
if ((flags & V8JS_FLAG_FORCE_ARRAY) || jsValue->IsArray()) { if ((flags & V8JS_FLAG_FORCE_ARRAY) || jsValue->IsArray()) {
zend_symtable_update(retval, key, strlen(key) + 1, (void *)&value, sizeof(zval *), NULL); zend_symtable_update(retval, key, &value);
} else { } else {
zend_hash_update(retval, key, strlen(key) + 1, (void *) &value, sizeof(zval *), NULL); zend_hash_update(retval, key, &value);
} }
} }
return SUCCESS; return SUCCESS;

View File

@ -30,14 +30,14 @@ static void v8js_fetch_php_variable(v8::Local<v8::String> name, const v8::Proper
v8::Handle<v8::External> data = v8::Handle<v8::External>::Cast(info.Data()); v8::Handle<v8::External> data = v8::Handle<v8::External>::Cast(info.Data());
v8js_accessor_ctx *ctx = static_cast<v8js_accessor_ctx *>(data->Value()); v8js_accessor_ctx *ctx = static_cast<v8js_accessor_ctx *>(data->Value());
v8::Isolate *isolate = ctx->isolate; v8::Isolate *isolate = ctx->isolate;
zval **variable; zval *variable;
V8JS_TSRMLS_FETCH(); V8JS_TSRMLS_FETCH();
zend_is_auto_global(ctx->variable_name_string, ctx->variable_name_string_len TSRMLS_CC); zend_is_auto_global(ctx->variable_name TSRMLS_CC);
if (zend_hash_find(&EG(symbol_table), ctx->variable_name_string, ctx->variable_name_string_len + 1, (void **) &variable) == SUCCESS) { if ((variable = zend_hash_find(&EG(symbol_table), ctx->variable_name))) {
info.GetReturnValue().Set(zval_to_v8js(*variable, isolate TSRMLS_CC)); info.GetReturnValue().Set(zval_to_v8js(variable, isolate TSRMLS_CC));
return; return;
} }
} }
@ -45,24 +45,19 @@ static void v8js_fetch_php_variable(v8::Local<v8::String> name, const v8::Proper
void v8js_accessor_ctx_dtor(v8js_accessor_ctx *ctx TSRMLS_DC) /* {{{ */ void v8js_accessor_ctx_dtor(v8js_accessor_ctx *ctx TSRMLS_DC) /* {{{ */
{ {
efree(ctx->variable_name_string); zend_string_release(ctx->variable_name);
efree(ctx); efree(ctx);
} }
/* }}} */ /* }}} */
void v8js_register_accessors(std::vector<v8js_accessor_ctx*> *accessor_list, v8::Local<v8::FunctionTemplate> php_obj_t, zval *array, v8::Isolate *isolate TSRMLS_DC) /* {{{ */ void v8js_register_accessors(std::vector<v8js_accessor_ctx*> *accessor_list, v8::Local<v8::FunctionTemplate> php_obj_t, zval *array, v8::Isolate *isolate TSRMLS_DC) /* {{{ */
{ {
char *property_name; zend_string *property_name;
uint property_name_len; zval *item;
ulong index;
zval **item;
v8::Local<v8::ObjectTemplate> php_obj = php_obj_t->InstanceTemplate(); v8::Local<v8::ObjectTemplate> php_obj = php_obj_t->InstanceTemplate();
for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(array)); ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(array), property_name, item) {
zend_hash_get_current_data(Z_ARRVAL_P(array), (void **) &item) != FAILURE; switch (Z_TYPE_P(item))
zend_hash_move_forward(Z_ARRVAL_P(array))
) {
switch (Z_TYPE_PP(item))
{ {
/* /*
case IS_OBJECT: case IS_OBJECT:
@ -75,22 +70,17 @@ void v8js_register_accessors(std::vector<v8js_accessor_ctx*> *accessor_list, v8:
continue; /* Ignore invalid values */ continue; /* Ignore invalid values */
} }
if (zend_hash_get_current_key_ex(Z_ARRVAL_P(array), &property_name, &property_name_len, &index, 0, NULL) != HASH_KEY_IS_STRING) {
continue; /* Ignore invalid property names */
}
// Create context to store accessor data // Create context to store accessor data
v8js_accessor_ctx *ctx = (v8js_accessor_ctx *)emalloc(sizeof(v8js_accessor_ctx)); v8js_accessor_ctx *ctx = (v8js_accessor_ctx *)emalloc(sizeof(v8js_accessor_ctx));
ctx->variable_name_string = estrdup(Z_STRVAL_PP(item)); ctx->variable_name = zend_string_copy(Z_STR_P(item));
ctx->variable_name_string_len = Z_STRLEN_PP(item);
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), v8js_fetch_php_variable, NULL, v8::External::New(isolate, ctx), v8::PROHIBITS_OVERWRITING, v8::ReadOnly, v8::AccessorSignature::New(isolate, php_obj_t)); php_obj->SetAccessor(V8JS_ZSTR(property_name), v8js_fetch_php_variable, NULL, v8::External::New(isolate, ctx), v8::PROHIBITS_OVERWRITING, v8::ReadOnly, v8::AccessorSignature::New(isolate, php_obj_t));
/* record the context so we can free it later */ /* record the context so we can free it later */
accessor_list->push_back(ctx); accessor_list->push_back(ctx);
} } ZEND_HASH_FOREACH_END();
} }
/* }}} */ /* }}} */