0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-09-19 01:35:18 +00:00

Adapt to PHP7: v8js_convert.cc, v8js_exception.cc, v8js_methods.cc

This commit is contained in:
Stefan Siegl 2015-08-28 21:05:16 +02:00
parent b8c9badddb
commit 909e3f004d
4 changed files with 56 additions and 59 deletions

View File

@ -33,22 +33,24 @@ extern "C" {
static int v8js_is_assoc_array(HashTable *myht TSRMLS_DC) /* {{{ */
{
int i;
char *key;
zend_string *key;
ulong index, idx = 0;
uint key_len;
HashPosition pos;
zend_hash_internal_pointer_reset_ex(myht, &pos);
for (;; zend_hash_move_forward_ex(myht, &pos)) {
i = zend_hash_get_current_key_ex(myht, &key, &key_len, &index, 0, &pos);
if (i == HASH_KEY_NON_EXISTANT)
break;
if (i == HASH_KEY_IS_STRING || index != idx) {
ZEND_HASH_FOREACH_KEY(myht, index, key) {
if(key) {
// HASH_KEY_IS_STRING
return 1;
}
idx++;
}
if(index != idx) {
return 1;
}
idx ++;
} ZEND_HASH_FOREACH_END();
return 0;
}
/* }}} */
@ -67,7 +69,7 @@ static v8::Handle<v8::Value> v8js_hash_to_jsarr(zval *value, v8::Isolate *isolat
v8::Local<v8::Array> newarr;
/* Prevent recursion */
if (myht && myht->nApplyCount > 1) {
if (myht && ZEND_HASH_GET_APPLY_COUNT(myht) > 1) {
return V8JS_NULL;
}
@ -75,27 +77,23 @@ static v8::Handle<v8::Value> v8js_hash_to_jsarr(zval *value, v8::Isolate *isolat
if (i > 0)
{
zval **data;
zval *data;
ulong index = 0;
HashTable *tmp_ht;
HashPosition pos;
for (zend_hash_internal_pointer_reset_ex(myht, &pos);
SUCCESS == zend_hash_get_current_data_ex(myht, (void **) &data, &pos);
zend_hash_move_forward_ex(myht, &pos)
) {
tmp_ht = HASH_OF(*data);
ZEND_HASH_FOREACH_VAL(myht, data) {
tmp_ht = HASH_OF(data);
if (tmp_ht) {
tmp_ht->nApplyCount++;
ZEND_HASH_INC_APPLY_COUNT(myht);
}
newarr->Set(index++, zval_to_v8js(*data, isolate TSRMLS_CC));
newarr->Set(index++, zval_to_v8js(data, isolate TSRMLS_CC));
if (tmp_ht) {
tmp_ht->nApplyCount--;
ZEND_HASH_DEC_APPLY_COUNT(myht);
}
}
} ZEND_HASH_FOREACH_END();
}
return newarr;
}
@ -117,14 +115,10 @@ v8::Handle<v8::Value> zval_to_v8js(zval *value, v8::Isolate *isolate TSRMLS_DC)
if (V8JSG(use_date)) {
ce = php_date_get_date_ce();
if (instanceof_function(Z_OBJCE_P(value), ce TSRMLS_CC)) {
zval *dtval;
zend_call_method_with_0_params(&value, NULL, NULL, "getTimestamp", &dtval);
if (dtval) {
jsValue = V8JS_DATE(((double)Z_LVAL_P(dtval) * 1000.0));
zval_ptr_dtor(&dtval);
}
else
jsValue = V8JS_NULL;
zval dtval;
zend_call_method_with_0_params(value, NULL, NULL, "getTimestamp", &dtval);
jsValue = V8JS_DATE(((double)Z_LVAL(dtval) * 1000.0));
zval_dtor(&dtval);
} else
jsValue = v8js_hash_to_jsobj(value, isolate TSRMLS_CC);
} else
@ -152,8 +146,12 @@ v8::Handle<v8::Value> zval_to_v8js(zval *value, v8::Isolate *isolate TSRMLS_DC)
jsValue = V8JS_FLOAT(Z_DVAL_P(value));
break;
case IS_BOOL:
jsValue = V8JS_BOOL(Z_BVAL_P(value));
case IS_TRUE:
jsValue = V8JS_TRUE();
break;
case IS_FALSE:
jsValue = V8JS_FALSE();
break;
default:
@ -211,7 +209,7 @@ int v8js_to_zval(v8::Handle<v8::Value> jsValue, zval *return_value, int flags, v
zend_class_entry *ce = php_date_get_date_ce();
php_date_instantiate(ce, return_value TSRMLS_CC);
if (!php_date_initialize((php_date_obj *) zend_object_store_get_object(return_value TSRMLS_CC), date_str, strlen(date_str), NULL, NULL, 0 TSRMLS_CC)) {
if (!php_date_initialize(Z_PHPDATE_P(return_value), date_str, strlen(date_str), NULL, NULL, 0 TSRMLS_CC)) {
efree(date_str);
return FAILURE;
}
@ -226,8 +224,8 @@ int v8js_to_zval(v8::Handle<v8::Value> jsValue, zval *return_value, int flags, v
if (!php_object.IsEmpty()) {
zend_object *object = reinterpret_cast<zend_object *>(v8::External::Cast(*php_object)->Value());
zval zval_object;
ZVAL_OBJ(&zval_object, object)
RETVAL_ZVAL(zval_object, 1, 0);
ZVAL_OBJ(&zval_object, object);
RETVAL_ZVAL(&zval_object, 1, 0);
return SUCCESS;
}
if ((flags & V8JS_FLAG_FORCE_ARRAY) || jsValue->IsArray()) {

View File

@ -93,14 +93,13 @@ void v8js_throw_script_exception(v8::TryCatch *try_catch TSRMLS_DC) /* {{{ */
{
v8::String::Utf8Value exception(try_catch->Exception());
const char *exception_string = ToCString(exception);
zval *zexception = NULL;
zval zexception;
if (try_catch->Message().IsEmpty()) {
zend_throw_exception(php_ce_v8js_script_exception, (char *) exception_string, 0 TSRMLS_CC);
} else {
MAKE_STD_ZVAL(zexception);
v8js_create_script_exception(zexception, try_catch TSRMLS_CC);
zend_throw_exception_object(zexception TSRMLS_CC);
v8js_create_script_exception(&zexception, try_catch TSRMLS_CC);
zend_throw_exception_object(&zexception TSRMLS_CC);
}
}
/* }}} */
@ -113,10 +112,10 @@ void v8js_throw_script_exception(v8::TryCatch *try_catch TSRMLS_DC) /* {{{ */
if (zend_parse_parameters_none() == FAILURE) { \
return; \
} \
value = zend_read_property(php_ce_v8js_script_exception, getThis(), #property, sizeof(#property) - 1, 0 TSRMLS_CC); \
zend_read_property(php_ce_v8js_script_exception, getThis(), #property, sizeof(#property) - 1, 0, value TSRMLS_CC); \
*return_value = *value; \
zval_copy_ctor(return_value); \
INIT_PZVAL(return_value); \
/* ?? INIT_PZVAL(return_value); */ \
}
/* {{{ proto string V8JsEScriptxception::getJsFileName()
@ -207,11 +206,11 @@ PHP_MINIT_FUNCTION(v8js_exceptions) /* {{{ */
/* V8JsException Class */
INIT_CLASS_ENTRY(ce, "V8JsException", v8js_exception_methods);
php_ce_v8js_exception = zend_register_internal_class_ex(&ce, spl_ce_RuntimeException, NULL TSRMLS_CC);
php_ce_v8js_exception = zend_register_internal_class_ex(&ce, spl_ce_RuntimeException TSRMLS_CC);
/* V8JsScriptException Class */
INIT_CLASS_ENTRY(ce, "V8JsScriptException", v8js_script_exception_methods);
php_ce_v8js_script_exception = zend_register_internal_class_ex(&ce, php_ce_v8js_exception, NULL TSRMLS_CC);
php_ce_v8js_script_exception = zend_register_internal_class_ex(&ce, php_ce_v8js_exception TSRMLS_CC);
php_ce_v8js_script_exception->ce_flags |= ZEND_ACC_FINAL;
/* Add custom JS specific properties */
@ -224,12 +223,12 @@ PHP_MINIT_FUNCTION(v8js_exceptions) /* {{{ */
/* V8JsTimeLimitException Class */
INIT_CLASS_ENTRY(ce, "V8JsTimeLimitException", v8js_time_limit_exception_methods);
php_ce_v8js_time_limit_exception = zend_register_internal_class_ex(&ce, php_ce_v8js_exception, NULL TSRMLS_CC);
php_ce_v8js_time_limit_exception = zend_register_internal_class_ex(&ce, php_ce_v8js_exception TSRMLS_CC);
php_ce_v8js_time_limit_exception->ce_flags |= ZEND_ACC_FINAL;
/* V8JsMemoryLimitException Class */
INIT_CLASS_ENTRY(ce, "V8JsMemoryLimitException", v8js_memory_limit_exception_methods);
php_ce_v8js_memory_limit_exception = zend_register_internal_class_ex(&ce, php_ce_v8js_exception, NULL TSRMLS_CC);
php_ce_v8js_memory_limit_exception = zend_register_internal_class_ex(&ce, php_ce_v8js_exception TSRMLS_CC);
php_ce_v8js_memory_limit_exception->ce_flags |= ZEND_ACC_FINAL;
return SUCCESS;

View File

@ -214,7 +214,7 @@ V8JS_METHOD(require)
v8js_ctx *c = static_cast<v8js_ctx*>(data->Value());
// Check that we have a module loader
if (c->module_loader == NULL) {
if(Z_TYPE(c->module_loader) == IS_NULL) {
info.GetReturnValue().Set(isolate->ThrowException(V8JS_SYM("No module loader")));
return;
}
@ -264,22 +264,20 @@ V8JS_METHOD(require)
// Callback to PHP to load the module code
zval *module_code;
zval *normalised_path_zend;
zval module_code;
MAKE_STD_ZVAL(normalised_path_zend);
ZVAL_STRING(normalised_path_zend, normalised_module_id);
zval params[1];
ZVAL_STRING(&params[0], normalised_module_id);
zval **params[1] = {&normalised_path_zend};
if (FAILURE == call_user_function_ex(EG(function_table), NULL, c->module_loader, &module_code, 1, params, 0, NULL TSRMLS_CC)) {
zval_ptr_dtor(&normalised_path_zend);
if (FAILURE == call_user_function_ex(EG(function_table), NULL, &c->module_loader, &module_code, 1, params, 0, NULL TSRMLS_CC)) {
zval_dtor(&params[0]);
efree(normalised_module_id);
efree(normalised_path);
info.GetReturnValue().Set(isolate->ThrowException(V8JS_SYM("Module loader callback failed")));
return;
}
zval_ptr_dtor(&normalised_path_zend);
zval_dtor(&params[0]);
// Check if an exception was thrown
if (EG(exception)) {
@ -293,13 +291,13 @@ V8JS_METHOD(require)
}
// Convert the return value to string
if (Z_TYPE_P(module_code) != IS_STRING) {
convert_to_string(module_code);
if (Z_TYPE(module_code) != IS_STRING) {
convert_to_string(&module_code);
}
// Check that some code has been returned
if (Z_STRLEN_P(module_code)==0) {
zval_ptr_dtor(&module_code);
if (Z_STRLEN(module_code) == 0) {
zval_dtor(&module_code);
efree(normalised_module_id);
efree(normalised_path);
@ -340,7 +338,7 @@ V8JS_METHOD(require)
// Set script identifier
v8::Local<v8::String> sname = V8JS_SYM("require");
v8::Local<v8::String> source = V8JS_STRL(Z_STRVAL_P(module_code), Z_STRLEN_P(module_code));
v8::Local<v8::String> source = V8JS_STRL(Z_STRVAL(module_code), Z_STRLEN(module_code));
zval_ptr_dtor(&module_code);
// Create and compile script

View File

@ -23,6 +23,8 @@
#define V8JS_UINT(v) v8::Integer::NewFromUnsigned(isolate, v)
#define V8JS_FLOAT(v) v8::Number::New(isolate, v)
#define V8JS_BOOL(v) ((v)?v8::True(isolate):v8::False(isolate))
#define V8JS_TRUE() v8::True(isolate)
#define V8JS_FALSE() v8::False(isolate)
#define V8JS_DATE(v) v8::Date::New(isolate, v)
#define V8JS_NULL v8::Null(isolate)
#define V8JS_UNDEFINED v8::Undefined(isolate)