mirror of
https://github.com/phpv8/v8js.git
synced 2024-11-09 15:18:41 +00:00
Support PHP8.1+
This commit is contained in:
parent
3d64f08536
commit
1db8f8de5e
@ -8,23 +8,23 @@ v8js.use_array_access = 1
|
||||
<?php
|
||||
|
||||
class MyArray implements ArrayAccess, Countable {
|
||||
public function offsetExists($offset) {
|
||||
public function offsetExists($offset): bool {
|
||||
return $offset >= 0 && $offset <= 20;
|
||||
}
|
||||
|
||||
public function offsetGet($offset) {
|
||||
public function offsetGet($offset): mixed {
|
||||
return 19 - $offset;
|
||||
}
|
||||
|
||||
public function offsetSet($offset, $value) {
|
||||
public function offsetSet($offset, $value): void {
|
||||
throw new Exception('Not implemented');
|
||||
}
|
||||
|
||||
public function offsetUnset($offset) {
|
||||
public function offsetUnset($offset): void {
|
||||
throw new Exception('Not implemented');
|
||||
}
|
||||
|
||||
public function count() {
|
||||
public function count(): int {
|
||||
return 20;
|
||||
}
|
||||
}
|
||||
|
@ -10,23 +10,23 @@ v8js.use_array_access = 1
|
||||
class MyArray implements ArrayAccess, Countable {
|
||||
private $data = Array('one', 'two', 'three');
|
||||
|
||||
public function offsetExists($offset) {
|
||||
public function offsetExists($offset): bool {
|
||||
return isset($this->data[$offset]);
|
||||
}
|
||||
|
||||
public function offsetGet($offset) {
|
||||
public function offsetGet($offset): mixed {
|
||||
return $this->data[$offset];
|
||||
}
|
||||
|
||||
public function offsetSet($offset, $value) {
|
||||
public function offsetSet($offset, $value): void {
|
||||
$this->data[$offset] = $value;
|
||||
}
|
||||
|
||||
public function offsetUnset($offset) {
|
||||
public function offsetUnset($offset): void {
|
||||
throw new Exception('Not implemented');
|
||||
}
|
||||
|
||||
public function count() {
|
||||
public function count(): int {
|
||||
return count($this->data);
|
||||
}
|
||||
|
||||
|
@ -10,24 +10,24 @@ v8js.use_array_access = 1
|
||||
class MyArray implements ArrayAccess, Countable {
|
||||
private $data = Array('one', 'two', 'three');
|
||||
|
||||
public function offsetExists($offset) {
|
||||
public function offsetExists($offset): bool {
|
||||
return isset($this->data[$offset]);
|
||||
}
|
||||
|
||||
public function offsetGet($offset) {
|
||||
public function offsetGet($offset): mixed {
|
||||
return $this->data[$offset];
|
||||
}
|
||||
|
||||
public function offsetSet($offset, $value) {
|
||||
public function offsetSet($offset, $value): void {
|
||||
echo "set[$offset] = $value\n";
|
||||
$this->data[$offset] = $value;
|
||||
}
|
||||
|
||||
public function offsetUnset($offset) {
|
||||
public function offsetUnset($offset): void {
|
||||
throw new Exception('Not implemented');
|
||||
}
|
||||
|
||||
public function count() {
|
||||
public function count(): int {
|
||||
return count($this->data);
|
||||
}
|
||||
}
|
||||
|
@ -10,24 +10,24 @@ v8js.use_array_access = 1
|
||||
class MyArray implements ArrayAccess, Countable {
|
||||
private $data = Array('one', 'two', 'three');
|
||||
|
||||
public function offsetExists($offset) {
|
||||
public function offsetExists($offset): bool {
|
||||
return isset($this->data[$offset]);
|
||||
}
|
||||
|
||||
public function offsetGet($offset) {
|
||||
public function offsetGet($offset): mixed {
|
||||
return $this->data[$offset];
|
||||
}
|
||||
|
||||
public function offsetSet($offset, $value) {
|
||||
public function offsetSet($offset, $value): void {
|
||||
echo "set[$offset] = $value\n";
|
||||
$this->data[$offset] = $value;
|
||||
}
|
||||
|
||||
public function offsetUnset($offset) {
|
||||
public function offsetUnset($offset): void {
|
||||
throw new Exception('Not implemented');
|
||||
}
|
||||
|
||||
public function count() {
|
||||
public function count(): int {
|
||||
echo 'count() = ', count($this->data), "\n";
|
||||
return count($this->data);
|
||||
}
|
||||
|
@ -19,24 +19,24 @@ class MyArray implements ArrayAccess, Countable {
|
||||
* accessibly as $length. */
|
||||
public $length = 42;
|
||||
|
||||
public function offsetExists($offset) {
|
||||
public function offsetExists($offset): bool {
|
||||
return isset($this->data[$offset]);
|
||||
}
|
||||
|
||||
public function offsetGet($offset) {
|
||||
public function offsetGet($offset): mixed {
|
||||
return $this->data[$offset];
|
||||
}
|
||||
|
||||
public function offsetSet($offset, $value) {
|
||||
public function offsetSet($offset, $value): void {
|
||||
echo "set[$offset] = $value\n";
|
||||
$this->data[$offset] = $value;
|
||||
}
|
||||
|
||||
public function offsetUnset($offset) {
|
||||
public function offsetUnset($offset): void {
|
||||
throw new Exception('Not implemented');
|
||||
}
|
||||
|
||||
public function count() {
|
||||
public function count(): int {
|
||||
return count($this->data);
|
||||
}
|
||||
}
|
||||
|
@ -10,24 +10,24 @@ v8js.use_array_access = 1
|
||||
class MyArray implements ArrayAccess, Countable {
|
||||
private $data = Array('one', 'two', 'three');
|
||||
|
||||
public function offsetExists($offset) {
|
||||
public function offsetExists($offset): bool {
|
||||
return isset($this->data[$offset]);
|
||||
}
|
||||
|
||||
public function offsetGet($offset) {
|
||||
public function offsetGet($offset): mixed {
|
||||
return $this->data[$offset];
|
||||
}
|
||||
|
||||
public function offsetSet($offset, $value) {
|
||||
public function offsetSet($offset, $value): void {
|
||||
echo "set[$offset] = $value\n";
|
||||
$this->data[$offset] = $value;
|
||||
}
|
||||
|
||||
public function offsetUnset($offset) {
|
||||
public function offsetUnset($offset): void {
|
||||
throw new Exception('Not implemented');
|
||||
}
|
||||
|
||||
public function count() {
|
||||
public function count(): int {
|
||||
return count($this->data);
|
||||
}
|
||||
|
||||
|
@ -10,24 +10,24 @@ v8js.use_array_access = 1
|
||||
class MyArray implements ArrayAccess, Countable {
|
||||
private $data = Array('one', 'two', 'three', null, 'five');
|
||||
|
||||
public function offsetExists($offset) {
|
||||
public function offsetExists($offset): bool {
|
||||
return isset($this->data[$offset]);
|
||||
}
|
||||
|
||||
public function offsetGet($offset) {
|
||||
public function offsetGet($offset): mixed {
|
||||
return $this->data[$offset];
|
||||
}
|
||||
|
||||
public function offsetSet($offset, $value) {
|
||||
public function offsetSet($offset, $value): void {
|
||||
echo "set[$offset] = $value\n";
|
||||
$this->data[$offset] = $value;
|
||||
}
|
||||
|
||||
public function offsetUnset($offset) {
|
||||
public function offsetUnset($offset): void {
|
||||
throw new Exception('Not implemented');
|
||||
}
|
||||
|
||||
public function count() {
|
||||
public function count(): int {
|
||||
return count($this->data);
|
||||
}
|
||||
}
|
||||
|
@ -10,26 +10,26 @@ v8js.use_array_access = 1
|
||||
class MyArray implements ArrayAccess, Countable {
|
||||
private $data = Array('one', 'two', 'three');
|
||||
|
||||
public function offsetExists($offset) {
|
||||
public function offsetExists($offset): bool {
|
||||
return isset($this->data[$offset]);
|
||||
}
|
||||
|
||||
public function offsetGet($offset) {
|
||||
public function offsetGet($offset): mixed {
|
||||
if(!$this->offsetExists($offset)) {
|
||||
return null;
|
||||
}
|
||||
return $this->data[$offset];
|
||||
}
|
||||
|
||||
public function offsetSet($offset, $value) {
|
||||
public function offsetSet($offset, $value): void {
|
||||
$this->data[$offset] = $value;
|
||||
}
|
||||
|
||||
public function offsetUnset($offset) {
|
||||
public function offsetUnset($offset): void {
|
||||
unset($this->data[$offset]);
|
||||
}
|
||||
|
||||
public function count() {
|
||||
public function count(): int {
|
||||
return max(array_keys($this->data)) + 1;
|
||||
}
|
||||
}
|
||||
|
@ -10,23 +10,23 @@ v8js.use_array_access = 1
|
||||
class MyArray implements ArrayAccess, Countable {
|
||||
private $data = Array('one', null, 'three');
|
||||
|
||||
public function offsetExists($offset) {
|
||||
public function offsetExists($offset): bool {
|
||||
return isset($this->data[$offset]);
|
||||
}
|
||||
|
||||
public function offsetGet($offset) {
|
||||
public function offsetGet($offset): mixed {
|
||||
return $this->data[$offset];
|
||||
}
|
||||
|
||||
public function offsetSet($offset, $value) {
|
||||
public function offsetSet($offset, $value): void {
|
||||
$this->data[$offset] = $value;
|
||||
}
|
||||
|
||||
public function offsetUnset($offset) {
|
||||
public function offsetUnset($offset): void {
|
||||
unset($this->data[$offset]);
|
||||
}
|
||||
|
||||
public function count() {
|
||||
public function count(): int {
|
||||
return max(array_keys($this->data)) + 1;
|
||||
}
|
||||
}
|
||||
|
@ -10,23 +10,23 @@ v8js.use_array_access = 1
|
||||
class MyArray implements ArrayAccess, Countable {
|
||||
private $data = array('one', 'two', 'three');
|
||||
|
||||
public function offsetExists($offset) {
|
||||
public function offsetExists($offset): bool {
|
||||
return isset($this->data[$offset]);
|
||||
}
|
||||
|
||||
public function offsetGet($offset) {
|
||||
public function offsetGet($offset): mixed {
|
||||
return $this->data[$offset];
|
||||
}
|
||||
|
||||
public function offsetSet($offset, $value) {
|
||||
public function offsetSet($offset, $value): void {
|
||||
$this->data[$offset] = $value;
|
||||
}
|
||||
|
||||
public function offsetUnset($offset) {
|
||||
public function offsetUnset($offset): void {
|
||||
throw new Exception('Not implemented');
|
||||
}
|
||||
|
||||
public function count() {
|
||||
public function count(): int {
|
||||
return count($this->data);
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ Test V8::executeString() : Exception clearing test
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$v8 = new V8Js(null, array(), array(), false);
|
||||
$v8 = new V8Js('', array(), array(), false);
|
||||
|
||||
var_dump($v8->getPendingException());
|
||||
|
||||
|
@ -10,7 +10,7 @@ class Foo {
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->v8 = new V8Js(null, array(), array(), false);
|
||||
$this->v8 = new V8Js('', array(), array(), false);
|
||||
$this->v8->foo = $this;
|
||||
$this->v8->executeString('fooobar', 'throw_0');
|
||||
var_dump($this->v8->getPendingException());
|
||||
|
@ -10,7 +10,7 @@ class Foo {
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->v8 = new V8Js(null, array(), array(), false);
|
||||
$this->v8 = new V8Js('', array(), array(), false);
|
||||
$this->v8->foo = $this;
|
||||
$this->v8->executeString('function foobar() { throw new SyntaxError(); }', 'throw_1');
|
||||
$this->v8->executeString('try { foobar(); } catch (e) { print(e + " caught in JS!\n"); }', 'trycatch1');
|
||||
|
@ -158,6 +158,10 @@ static void v8js_call_php_func(zend_object *object, zend_function *method_ptr, c
|
||||
fcc.called_scope = object->ce;
|
||||
fcc.object = object;
|
||||
|
||||
if (!EG(current_execute_data) || !EG(current_execute_data)->func) {
|
||||
EG(current_execute_data) = NULL;
|
||||
}
|
||||
|
||||
zend_call_function(&fci, &fcc);
|
||||
}
|
||||
zend_catch {
|
||||
|
@ -178,6 +178,10 @@ void v8js_v8_call(v8js_ctx *c, zval **return_value,
|
||||
efree(timer_ctx);
|
||||
|
||||
if(!V8JSG(fatal_error_abort)) {
|
||||
if (!EG(current_execute_data) || !EG(current_execute_data)->func) {
|
||||
EG(current_execute_data) = NULL;
|
||||
}
|
||||
|
||||
char exception_string[64];
|
||||
|
||||
if (c->time_limit_hit) {
|
||||
|
39
v8js_v8.h
39
v8js_v8.h
@ -100,6 +100,45 @@ int v8js_get_properties_hash(v8::Local<v8::Value> jsValue, HashTable *retval, in
|
||||
#define SINCE80(x,y) x
|
||||
#endif
|
||||
|
||||
#if PHP_VERSION_ID < 70200
|
||||
#define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(name, return_reference, required_num_args, class_name, allow_null) \
|
||||
ZEND_BEGIN_ARG_INFO_EX(name, return_reference, required_num_args, allow_null)
|
||||
#endif
|
||||
|
||||
// polyfill for ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX, which changes between 7.1 and 7.2
|
||||
#if PHP_VERSION_ID < 70200
|
||||
#define V8_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, /*class_name*/ 0, allow_null)
|
||||
#else
|
||||
#define V8_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null)
|
||||
#endif
|
||||
|
||||
// In PHP 8.1, mismatched tentative return types emit a deprecation notice.
|
||||
// https://wiki.php.net/rfc/internal_method_return_types
|
||||
//
|
||||
// When compiling for earlier php versions, the return type is dropped.
|
||||
#if PHP_VERSION_ID < 80100
|
||||
#define ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \
|
||||
ZEND_BEGIN_ARG_INFO_EX(name, return_reference, required_num_args, allow_null)
|
||||
#endif
|
||||
|
||||
#ifndef IS_VOID
|
||||
#define IS_VOID 99
|
||||
#endif
|
||||
|
||||
#ifndef IS_MIXED
|
||||
#define IS_MIXED 99
|
||||
#endif
|
||||
|
||||
#ifndef _IS_BOOL
|
||||
#define _IS_BOOL 99
|
||||
#endif
|
||||
|
||||
#ifndef IS_LONG
|
||||
#define IS_LONG 99
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* V8JS_V8_H */
|
||||
|
||||
|
@ -853,7 +853,7 @@ PHP_METHOD(V8Generator, __wakeup)
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ mixed V8Generator::current()
|
||||
/* {{{ mixed V8Generator::current(): mixed
|
||||
*/
|
||||
PHP_METHOD(V8Generator, current)
|
||||
{
|
||||
@ -868,7 +868,7 @@ PHP_METHOD(V8Generator, current)
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ scalar V8Generator::key()
|
||||
/* {{{ scalar V8Generator::key(): mixed
|
||||
*/
|
||||
PHP_METHOD(V8Generator, key)
|
||||
{
|
||||
@ -876,7 +876,7 @@ PHP_METHOD(V8Generator, key)
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ void V8Generator::next()
|
||||
/* {{{ void V8Generator::next(): void
|
||||
*/
|
||||
PHP_METHOD(V8Generator, next)
|
||||
{
|
||||
@ -885,7 +885,7 @@ PHP_METHOD(V8Generator, next)
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ void V8Generator::rewind()
|
||||
/* {{{ void V8Generator::rewind(): void
|
||||
*/
|
||||
PHP_METHOD(V8Generator, rewind)
|
||||
{
|
||||
@ -901,7 +901,7 @@ PHP_METHOD(V8Generator, rewind)
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ boolean V8Generator::valid()
|
||||
/* {{{ boolean V8Generator::valid(): bool
|
||||
*/
|
||||
PHP_METHOD(V8Generator, valid)
|
||||
{
|
||||
@ -982,19 +982,19 @@ ZEND_END_ARG_INFO()
|
||||
ZEND_BEGIN_ARG_INFO(arginfo_v8generator_wakeup, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_INFO(arginfo_v8generator_current, 0)
|
||||
V8_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_v8generator_current, 0, 0, IS_MIXED, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_INFO(arginfo_v8generator_key, 0)
|
||||
V8_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_v8generator_key, 0, 0, IS_MIXED, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_INFO(arginfo_v8generator_next, 0)
|
||||
V8_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_v8generator_next, 0, 0, IS_VOID, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_INFO(arginfo_v8generator_rewind, 0)
|
||||
V8_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_v8generator_rewind, 0, 0, IS_VOID, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_INFO(arginfo_v8generator_valid, 0)
|
||||
V8_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_v8generator_valid, 0, 0, _IS_BOOL, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
static const zend_function_entry v8js_v8generator_methods[] = {/* {{{ */
|
||||
|
Loading…
Reference in New Issue
Block a user