0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-11-08 14:48:40 +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
{
char *variable_name_string;
uint variable_name_string_len;
zend_string *variable_name;
v8::Isolate *isolate;
};
@ -128,11 +127,7 @@ extern zend_v8js_globals v8js_globals;
ZEND_EXTERN_MODULE_GLOBALS(v8js)
#ifdef ZTS
# define V8JSG(v) TSRMG(v8js_globals_id, zend_v8js_globals *, v)
#else
# define V8JSG(v) (v8js_globals.v)
#endif
#define V8JSG(v) ZEND_MODULE_GLOBALS_ACCESSOR(v8js, v)
/* Register builtin methods into passed object */
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 ZTS
ZEND_TSRMLS_CACHE_DEFINE();
#endif
ZEND_GET_MODULE(v8js)
#endif
@ -155,6 +159,10 @@ static PHP_MINFO_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
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) { /* {{{ */
#ifdef ZTS
TSRMLS_D = (void ***) data;
// @fixme
//TSRMLS_D = (void ***) data;
#endif
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 ... */
void *data = NULL;
#ifdef ZTS
data = (void *) TSRMLS_C;
// @fixme
//data = (void *) TSRMLS_C;
#endif
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 */
if (c->pending_exception) {
zend_throw_exception_object(c->pending_exception TSRMLS_CC);
c->pending_exception = NULL;
if (Z_TYPE(c->pending_exception) == IS_OBJECT) {
zend_throw_exception_object(&c->pending_exception TSRMLS_CC);
zval_dtor(&c->pending_exception);
ZVAL_NULL(&c->pending_exception);
}
/* 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 */
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;
}
}
@ -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::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_UNDEF(&value);
@ -235,21 +236,21 @@ int v8js_get_properties_hash(v8::Handle<v8::Value> jsValue, HashTable *retval, i
}
if (!php_object.IsEmpty()) {
/* 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);
Z_ADDREF_P(value);
Z_ADDREF_P(&value);
}
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);
return FAILURE;
}
}
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 {
zend_hash_update(retval, key, strlen(key) + 1, (void *) &value, sizeof(zval *), NULL);
zend_hash_update(retval, key, &value);
}
}
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());
v8js_accessor_ctx *ctx = static_cast<v8js_accessor_ctx *>(data->Value());
v8::Isolate *isolate = ctx->isolate;
zval **variable;
zval *variable;
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) {
info.GetReturnValue().Set(zval_to_v8js(*variable, isolate TSRMLS_CC));
if ((variable = zend_hash_find(&EG(symbol_table), ctx->variable_name))) {
info.GetReturnValue().Set(zval_to_v8js(variable, isolate TSRMLS_CC));
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) /* {{{ */
{
efree(ctx->variable_name_string);
zend_string_release(ctx->variable_name);
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) /* {{{ */
{
char *property_name;
uint property_name_len;
ulong index;
zval **item;
zend_string *property_name;
zval *item;
v8::Local<v8::ObjectTemplate> 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;
zend_hash_move_forward(Z_ARRVAL_P(array))
) {
switch (Z_TYPE_PP(item))
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(array), property_name, item) {
switch (Z_TYPE_P(item))
{
/*
case IS_OBJECT:
@ -75,22 +70,17 @@ void v8js_register_accessors(std::vector<v8js_accessor_ctx*> *accessor_list, v8:
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
v8js_accessor_ctx *ctx = (v8js_accessor_ctx *)emalloc(sizeof(v8js_accessor_ctx));
ctx->variable_name_string = estrdup(Z_STRVAL_PP(item));
ctx->variable_name_string_len = Z_STRLEN_PP(item);
ctx->variable_name = zend_string_copy(Z_STR_P(item));
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), 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 */
accessor_list->push_back(ctx);
}
} ZEND_HASH_FOREACH_END();
}
/* }}} */