0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-11-08 10: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) \
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
* declared as 'char *' instead of 'const char *' before PHP 5.4 */
#if ZEND_MODULE_API_NO >= 20100525

View File

@ -1,7 +1,13 @@
--TEST--
Test V8::executeString() : Generators V8 -> PHP (foreach)
--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--
<?php

View File

@ -1,7 +1,13 @@
--TEST--
Test V8::executeString() : Generators V8 -> PHP (direct)
--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--
<?php

View File

@ -1,7 +1,13 @@
--TEST--
Test V8::executeString() : Generators V8 -> PHP (rewind)
--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--
<?php

View File

@ -1,7 +1,13 @@
--TEST--
Test V8::executeString() : Generators V8 -> PHP (instantiate in PHP + foreach)
--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--
<?php

View File

@ -1,7 +1,13 @@
--TEST--
Test V8::executeString() : Generators V8 -> PHP (instantiate in PHP + iterate in JS)
--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--
<?php

View File

@ -1,7 +1,13 @@
--TEST--
Test V8::executeString() : Generators V8 -> PHP (yield from)
--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--
<?php

View File

@ -1,7 +1,13 @@
--TEST--
Test V8::executeString() : Generators V8 -> PHP (throw JS)
--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--
<?php

View File

@ -1,7 +1,13 @@
--TEST--
Test V8::executeString() : Generators V8 -> PHP (throw PHP)
--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--
<?php

View File

@ -1,7 +1,13 @@
--TEST--
Test V8::executeString() : Generators V8 -> PHP (fatal error)
--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--
<?php

View File

@ -1,7 +1,13 @@
--TEST--
Test V8::executeString() : Generators V8 -> PHP (properties)
--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--
<?php

View File

@ -1,7 +1,13 @@
--TEST--
Test V8::executeString() : Generators V8 -> PHP
--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--
<?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 */
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);
if(isolate != c->ctx->isolate) {

View File

@ -33,12 +33,18 @@ extern "C" {
/* {{{ Class Entries */
zend_class_entry *php_ce_v8object;
zend_class_entry *php_ce_v8function;
#ifdef V8JS_V8GENERATOR_SUPPORT
zend_class_entry *php_ce_v8generator;
#endif
/* }}} */
/* {{{ Object Handlers */
static zend_object_handlers v8js_v8object_handlers;
#ifdef V8JS_V8GENERATOR_SUPPORT
static zend_object_handlers v8js_v8generator_handlers;
#endif
/* }}} */
#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) /* {{{ */
{
v8js_v8generator *c = v8js_v8generator_fetch_object(object);
@ -646,16 +653,20 @@ PHP_METHOD(V8Generator, valid)
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) /* {{{ */
{
v8js_ctx *ctx = (v8js_ctx *) isolate->GetData(0);
#ifdef V8JS_V8GENERATOR_SUPPORT
if(value->IsGeneratorObject()) {
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);
}
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_END_ARG_INFO()
@ -718,6 +730,7 @@ static const zend_function_entry v8js_v8generator_methods[] = { /* {{{ */
{NULL, NULL, NULL}
};
/* }}} */
#endif /* /V8JS_V8GENERATOR_SUPPORT */
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->create_object = v8js_v8object_new;
#ifdef V8JS_V8GENERATOR_SUPPORT
/* V8Generator Class */
INIT_CLASS_ENTRY(ce, "V8Generator", v8js_v8generator_methods);
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;
zend_class_implements(php_ce_v8generator, 1, zend_ce_iterator);
#endif /* /V8JS_V8GENERATOR_SUPPORT */
/* 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.free_obj = v8js_v8object_free_storage;
#ifdef V8JS_V8GENERATOR_SUPPORT
/* V8Generator handlers */
memcpy(&v8js_v8generator_handlers, &v8js_v8object_handlers, sizeof(zend_object_handlers));
v8js_v8generator_handlers.get_method = v8js_v8generator_get_method;
v8js_v8generator_handlers.offset = XtOffsetOf(struct v8js_v8generator, v8obj.std);
v8js_v8generator_handlers.free_obj = v8js_v8generator_free_storage;
#endif /* /V8JS_V8GENERATOR_SUPPORT */
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_v8function;
extern zend_class_entry *php_ce_v8generator;
/* Create PHP V8 object */
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));
#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) {
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));
#endif /* /V8JS_V8GENERATOR_SUPPORT */
PHP_MINIT_FUNCTION(v8js_v8object_class);