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

Enable V8Generator support on V8 >= 3.30.0

This commit is contained in:
Stefan Siegl 2016-01-08 00:12:06 +01:00
parent a4b4934361
commit 38b9c053a1
15 changed files with 121 additions and 24 deletions

View File

@ -61,6 +61,10 @@ extern "C" {
#define V8JS_GET_CLASS_NAME(var, obj) \ #define V8JS_GET_CLASS_NAME(var, obj) \
v8::String::Utf8Value var(obj->GetConstructorName()); v8::String::Utf8Value var(obj->GetConstructorName());
#if PHP_V8_API_VERSION >= 3030000
#define V8JS_V8GENERATOR_SUPPORT 1
#endif
/* method signatures of zend_update_property and zend_read_property were /* method signatures of zend_update_property and zend_read_property were
* declared as 'char *' instead of 'const char *' before PHP 5.4 */ * declared as 'char *' instead of 'const char *' before PHP 5.4 */
#if ZEND_MODULE_API_NO >= 20100525 #if ZEND_MODULE_API_NO >= 20100525

View File

@ -1,7 +1,13 @@
--TEST-- --TEST--
Test V8::executeString() : Generators V8 -> PHP (foreach) Test V8::executeString() : Generators V8 -> PHP (foreach)
--SKIPIF-- --SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> <?php
require_once(dirname(__FILE__) . '/skipif.inc');
if (!class_exists('V8Generator')) {
die("skip Installed V8 version doesn't support generators");
}
?>
--FILE-- --FILE--
<?php <?php

View File

@ -1,7 +1,13 @@
--TEST-- --TEST--
Test V8::executeString() : Generators V8 -> PHP (direct) Test V8::executeString() : Generators V8 -> PHP (direct)
--SKIPIF-- --SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> <?php
require_once(dirname(__FILE__) . '/skipif.inc');
if (!class_exists('V8Generator')) {
die("skip Installed V8 version doesn't support generators");
}
?>
--FILE-- --FILE--
<?php <?php

View File

@ -1,7 +1,13 @@
--TEST-- --TEST--
Test V8::executeString() : Generators V8 -> PHP (rewind) Test V8::executeString() : Generators V8 -> PHP (rewind)
--SKIPIF-- --SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> <?php
require_once(dirname(__FILE__) . '/skipif.inc');
if (!class_exists('V8Generator')) {
die("skip Installed V8 version doesn't support generators");
}
?>
--FILE-- --FILE--
<?php <?php

View File

@ -1,7 +1,13 @@
--TEST-- --TEST--
Test V8::executeString() : Generators V8 -> PHP (instantiate in PHP + foreach) Test V8::executeString() : Generators V8 -> PHP (instantiate in PHP + foreach)
--SKIPIF-- --SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> <?php
require_once(dirname(__FILE__) . '/skipif.inc');
if (!class_exists('V8Generator')) {
die("skip Installed V8 version doesn't support generators");
}
?>
--FILE-- --FILE--
<?php <?php

View File

@ -1,7 +1,13 @@
--TEST-- --TEST--
Test V8::executeString() : Generators V8 -> PHP (instantiate in PHP + iterate in JS) Test V8::executeString() : Generators V8 -> PHP (instantiate in PHP + iterate in JS)
--SKIPIF-- --SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> <?php
require_once(dirname(__FILE__) . '/skipif.inc');
if (!class_exists('V8Generator')) {
die("skip Installed V8 version doesn't support generators");
}
?>
--FILE-- --FILE--
<?php <?php

View File

@ -1,7 +1,13 @@
--TEST-- --TEST--
Test V8::executeString() : Generators V8 -> PHP (yield from) Test V8::executeString() : Generators V8 -> PHP (yield from)
--SKIPIF-- --SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> <?php
require_once(dirname(__FILE__) . '/skipif.inc');
if (!class_exists('V8Generator')) {
die("skip Installed V8 version doesn't support generators");
}
?>
--FILE-- --FILE--
<?php <?php

View File

@ -1,7 +1,13 @@
--TEST-- --TEST--
Test V8::executeString() : Generators V8 -> PHP (throw JS) Test V8::executeString() : Generators V8 -> PHP (throw JS)
--SKIPIF-- --SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> <?php
require_once(dirname(__FILE__) . '/skipif.inc');
if (!class_exists('V8Generator')) {
die("skip Installed V8 version doesn't support generators");
}
?>
--FILE-- --FILE--
<?php <?php

View File

@ -1,7 +1,13 @@
--TEST-- --TEST--
Test V8::executeString() : Generators V8 -> PHP (throw PHP) Test V8::executeString() : Generators V8 -> PHP (throw PHP)
--SKIPIF-- --SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> <?php
require_once(dirname(__FILE__) . '/skipif.inc');
if (!class_exists('V8Generator')) {
die("skip Installed V8 version doesn't support generators");
}
?>
--FILE-- --FILE--
<?php <?php

View File

@ -1,7 +1,13 @@
--TEST-- --TEST--
Test V8::executeString() : Generators V8 -> PHP (fatal error) Test V8::executeString() : Generators V8 -> PHP (fatal error)
--SKIPIF-- --SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> <?php
require_once(dirname(__FILE__) . '/skipif.inc');
if (!class_exists('V8Generator')) {
die("skip Installed V8 version doesn't support generators");
}
?>
--FILE-- --FILE--
<?php <?php

View File

@ -1,7 +1,13 @@
--TEST-- --TEST--
Test V8::executeString() : Generators V8 -> PHP (properties) Test V8::executeString() : Generators V8 -> PHP (properties)
--SKIPIF-- --SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> <?php
require_once(dirname(__FILE__) . '/skipif.inc');
if (!class_exists('V8Generator')) {
die("skip Installed V8 version doesn't support generators");
}
?>
--FILE-- --FILE--
<?php <?php

View File

@ -1,7 +1,13 @@
--TEST-- --TEST--
Test V8::executeString() : Generators V8 -> PHP Test V8::executeString() : Generators V8 -> PHP
--SKIPIF-- --SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> <?php
require_once(dirname(__FILE__) . '/skipif.inc');
if (!class_exists('V8Generator')) {
die("skip Installed V8 version doesn't support generators");
}
?>
--FILE-- --FILE--
<?php <?php

View File

@ -938,7 +938,11 @@ v8::Handle<v8::Value> v8js_hash_to_jsobj(zval *value, v8::Isolate *isolate TSRML
} }
/* Special case, passing back object originating from JS to JS */ /* Special case, passing back object originating from JS to JS */
if (ce == php_ce_v8function || ce == php_ce_v8generator) { if (ce == php_ce_v8function
#ifdef V8JS_V8GENERATOR_SUPPORT
|| ce == php_ce_v8generator
#endif
) {
v8js_v8object *c = Z_V8JS_V8OBJECT_OBJ_P(value); v8js_v8object *c = Z_V8JS_V8OBJECT_OBJ_P(value);
if(isolate != c->ctx->isolate) { if(isolate != c->ctx->isolate) {

View File

@ -33,12 +33,18 @@ extern "C" {
/* {{{ Class Entries */ /* {{{ Class Entries */
zend_class_entry *php_ce_v8object; zend_class_entry *php_ce_v8object;
zend_class_entry *php_ce_v8function; zend_class_entry *php_ce_v8function;
#ifdef V8JS_V8GENERATOR_SUPPORT
zend_class_entry *php_ce_v8generator; zend_class_entry *php_ce_v8generator;
#endif
/* }}} */ /* }}} */
/* {{{ Object Handlers */ /* {{{ Object Handlers */
static zend_object_handlers v8js_v8object_handlers; static zend_object_handlers v8js_v8object_handlers;
#ifdef V8JS_V8GENERATOR_SUPPORT
static zend_object_handlers v8js_v8generator_handlers; static zend_object_handlers v8js_v8generator_handlers;
#endif
/* }}} */ /* }}} */
#define V8JS_V8_INVOKE_FUNC_NAME "V8Js::V8::Invoke" #define V8JS_V8_INVOKE_FUNC_NAME "V8Js::V8::Invoke"
@ -468,6 +474,7 @@ PHP_METHOD(V8Function, __wakeup)
/* }}} */ /* }}} */
#ifdef V8JS_V8GENERATOR_SUPPORT
static void v8js_v8generator_free_storage(zend_object *object) /* {{{ */ static void v8js_v8generator_free_storage(zend_object *object) /* {{{ */
{ {
v8js_v8generator *c = v8js_v8generator_fetch_object(object); v8js_v8generator *c = v8js_v8generator_fetch_object(object);
@ -646,16 +653,20 @@ PHP_METHOD(V8Generator, valid)
RETVAL_BOOL(!g->done); RETVAL_BOOL(!g->done);
} }
/* }}} */ /* }}} */
#endif /* /V8JS_V8GENERATOR_SUPPORT */
void v8js_v8object_create(zval *res, v8::Handle<v8::Value> value, int flags, v8::Isolate *isolate TSRMLS_DC) /* {{{ */ void v8js_v8object_create(zval *res, v8::Handle<v8::Value> value, int flags, v8::Isolate *isolate TSRMLS_DC) /* {{{ */
{ {
v8js_ctx *ctx = (v8js_ctx *) isolate->GetData(0); v8js_ctx *ctx = (v8js_ctx *) isolate->GetData(0);
#ifdef V8JS_V8GENERATOR_SUPPORT
if(value->IsGeneratorObject()) { if(value->IsGeneratorObject()) {
object_init_ex(res, php_ce_v8generator); object_init_ex(res, php_ce_v8generator);
} }
else if(value->IsFunction()) { else
#endif /* /V8JS_V8GENERATOR_SUPPORT */
if(value->IsFunction()) {
object_init_ex(res, php_ce_v8function); object_init_ex(res, php_ce_v8function);
} }
else { else {
@ -689,6 +700,7 @@ static const zend_function_entry v8js_v8function_methods[] = { /* {{{ */
}; };
/* }}} */ /* }}} */
#ifdef V8JS_V8GENERATOR_SUPPORT
ZEND_BEGIN_ARG_INFO(arginfo_v8generator_current, 0) ZEND_BEGIN_ARG_INFO(arginfo_v8generator_current, 0)
ZEND_END_ARG_INFO() ZEND_END_ARG_INFO()
@ -718,6 +730,7 @@ static const zend_function_entry v8js_v8generator_methods[] = { /* {{{ */
{NULL, NULL, NULL} {NULL, NULL, NULL}
}; };
/* }}} */ /* }}} */
#endif /* /V8JS_V8GENERATOR_SUPPORT */
PHP_MINIT_FUNCTION(v8js_v8object_class) /* {{{ */ PHP_MINIT_FUNCTION(v8js_v8object_class) /* {{{ */
@ -736,6 +749,7 @@ PHP_MINIT_FUNCTION(v8js_v8object_class) /* {{{ */
php_ce_v8function->ce_flags |= ZEND_ACC_FINAL; php_ce_v8function->ce_flags |= ZEND_ACC_FINAL;
php_ce_v8function->create_object = v8js_v8object_new; php_ce_v8function->create_object = v8js_v8object_new;
#ifdef V8JS_V8GENERATOR_SUPPORT
/* V8Generator Class */ /* V8Generator Class */
INIT_CLASS_ENTRY(ce, "V8Generator", v8js_v8generator_methods); INIT_CLASS_ENTRY(ce, "V8Generator", v8js_v8generator_methods);
php_ce_v8generator = zend_register_internal_class(&ce TSRMLS_CC); php_ce_v8generator = zend_register_internal_class(&ce TSRMLS_CC);
@ -743,6 +757,7 @@ PHP_MINIT_FUNCTION(v8js_v8object_class) /* {{{ */
php_ce_v8generator->create_object = v8js_v8generator_new; php_ce_v8generator->create_object = v8js_v8generator_new;
zend_class_implements(php_ce_v8generator, 1, zend_ce_iterator); zend_class_implements(php_ce_v8generator, 1, zend_ce_iterator);
#endif /* /V8JS_V8GENERATOR_SUPPORT */
/* V8<Object|Function> handlers */ /* V8<Object|Function> handlers */
@ -762,12 +777,13 @@ PHP_MINIT_FUNCTION(v8js_v8object_class) /* {{{ */
v8js_v8object_handlers.offset = XtOffsetOf(struct v8js_v8object, std); v8js_v8object_handlers.offset = XtOffsetOf(struct v8js_v8object, std);
v8js_v8object_handlers.free_obj = v8js_v8object_free_storage; v8js_v8object_handlers.free_obj = v8js_v8object_free_storage;
#ifdef V8JS_V8GENERATOR_SUPPORT
/* V8Generator handlers */ /* V8Generator handlers */
memcpy(&v8js_v8generator_handlers, &v8js_v8object_handlers, sizeof(zend_object_handlers)); memcpy(&v8js_v8generator_handlers, &v8js_v8object_handlers, sizeof(zend_object_handlers));
v8js_v8generator_handlers.get_method = v8js_v8generator_get_method; v8js_v8generator_handlers.get_method = v8js_v8generator_get_method;
v8js_v8generator_handlers.offset = XtOffsetOf(struct v8js_v8generator, v8obj.std); v8js_v8generator_handlers.offset = XtOffsetOf(struct v8js_v8generator, v8obj.std);
v8js_v8generator_handlers.free_obj = v8js_v8generator_free_storage; v8js_v8generator_handlers.free_obj = v8js_v8generator_free_storage;
#endif /* /V8JS_V8GENERATOR_SUPPORT */
return SUCCESS; return SUCCESS;
} /* }}} */ } /* }}} */

View File

@ -24,18 +24,8 @@ struct v8js_v8object {
}; };
/* }}} */ /* }}} */
/* {{{ Generator container */
struct v8js_v8generator {
zval value;
bool primed;
bool done;
struct v8js_v8object v8obj;
};
/* }}} */
extern zend_class_entry *php_ce_v8object; extern zend_class_entry *php_ce_v8object;
extern zend_class_entry *php_ce_v8function; extern zend_class_entry *php_ce_v8function;
extern zend_class_entry *php_ce_v8generator;
/* Create PHP V8 object */ /* Create PHP V8 object */
void v8js_v8object_create(zval *, v8::Handle<v8::Value>, int, v8::Isolate * TSRMLS_DC); void v8js_v8object_create(zval *, v8::Handle<v8::Value>, int, v8::Isolate * TSRMLS_DC);
@ -46,12 +36,29 @@ static inline v8js_v8object *v8js_v8object_fetch_object(zend_object *obj) {
#define Z_V8JS_V8OBJECT_OBJ_P(zv) v8js_v8object_fetch_object(Z_OBJ_P(zv)); #define Z_V8JS_V8OBJECT_OBJ_P(zv) v8js_v8object_fetch_object(Z_OBJ_P(zv));
#ifdef V8JS_V8GENERATOR_SUPPORT
/* {{{ Generator container */
struct v8js_v8generator {
zval value;
bool primed;
bool done;
struct v8js_v8object v8obj;
};
/* }}} */
extern zend_class_entry *php_ce_v8generator;
static inline v8js_v8generator *v8js_v8generator_fetch_object(zend_object *obj) { static inline v8js_v8generator *v8js_v8generator_fetch_object(zend_object *obj) {
return (v8js_v8generator *)((char *)obj - XtOffsetOf(struct v8js_v8generator, v8obj.std)); return (v8js_v8generator *)((char *)obj - XtOffsetOf(struct v8js_v8generator, v8obj.std));
} }
#define Z_V8JS_V8GENERATOR_OBJ_P(zv) v8js_v8generator_fetch_object(Z_OBJ_P(zv)); #define Z_V8JS_V8GENERATOR_OBJ_P(zv) v8js_v8generator_fetch_object(Z_OBJ_P(zv));
#endif /* /V8JS_V8GENERATOR_SUPPORT */
PHP_MINIT_FUNCTION(v8js_v8object_class); PHP_MINIT_FUNCTION(v8js_v8object_class);