mirror of
https://github.com/phpv8/v8js.git
synced 2024-11-09 16:28:41 +00:00
Implement isset behaviour on ArrayAccess objects
This commit is contained in:
parent
1b027a525f
commit
901268994a
56
tests/array_access_008.phpt
Normal file
56
tests/array_access_008.phpt
Normal file
@ -0,0 +1,56 @@
|
||||
--TEST--
|
||||
Test V8::executeString() : in array (isset) behaviour of ArrayAccess
|
||||
--SKIPIF--
|
||||
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
|
||||
--INI--
|
||||
v8js.use_array_access = 1
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
class MyArray implements ArrayAccess, Countable {
|
||||
private $data = Array('one', null, 'three');
|
||||
|
||||
public function offsetExists($offset) {
|
||||
return isset($this->data[$offset]);
|
||||
}
|
||||
|
||||
public function offsetGet($offset) {
|
||||
return $this->data[$offset];
|
||||
}
|
||||
|
||||
public function offsetSet($offset, $value) {
|
||||
$this->data[$offset] = $value;
|
||||
}
|
||||
|
||||
public function offsetUnset($offset) {
|
||||
unset($this->data[$offset]);
|
||||
}
|
||||
|
||||
public function count() {
|
||||
return max(array_keys($this->data)) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
$v8 = new V8Js();
|
||||
$v8->myarr = new MyArray();
|
||||
|
||||
$js = <<<EOF
|
||||
var jsarr = [ "one", , "three" ];
|
||||
var_dump(0 in jsarr);
|
||||
var_dump(1 in jsarr);
|
||||
|
||||
var_dump(0 in PHP.myarr);
|
||||
var_dump(1 in PHP.myarr);
|
||||
|
||||
EOF;
|
||||
|
||||
$v8->executeString($js);
|
||||
|
||||
?>
|
||||
===EOF===
|
||||
--EXPECT--
|
||||
bool(true)
|
||||
bool(false)
|
||||
bool(true)
|
||||
bool(false)
|
||||
===EOF===
|
@ -272,6 +272,24 @@ void php_v8js_array_access_deleter(uint32_t index, const v8::PropertyCallbackInf
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
void php_v8js_array_access_query(uint32_t index, const v8::PropertyCallbackInfo<v8::Integer>& info) /* {{{ */
|
||||
{
|
||||
v8::Isolate *isolate = info.GetIsolate();
|
||||
v8::Local<v8::Object> self = info.Holder();
|
||||
|
||||
V8JS_TSRMLS_FETCH();
|
||||
|
||||
v8::Local<v8::Value> php_object = self->GetHiddenValue(V8JS_SYM(PHPJS_OBJECT_KEY));
|
||||
zval *object = reinterpret_cast<zval *>(v8::External::Cast(*php_object)->Value());
|
||||
|
||||
/* If index is set, then return an integer encoding a v8::PropertyAttribute;
|
||||
* otherwise we're expected to return an empty handle. */
|
||||
if(php_v8js_array_access_isset_p(object, index TSRMLS_CC)) {
|
||||
info.GetReturnValue().Set(V8JS_UINT(v8::PropertyAttribute::None));
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
void php_v8js_array_access_enumerator(const v8::PropertyCallbackInfo<v8::Array>& info) /* {{{ */
|
||||
{
|
||||
|
@ -23,6 +23,8 @@ void php_v8js_array_access_length(v8::Local<v8::String> property,
|
||||
void php_v8js_array_access_enumerator(const v8::PropertyCallbackInfo<v8::Array>& info);
|
||||
void php_v8js_array_access_deleter(uint32_t index,
|
||||
const v8::PropertyCallbackInfo<v8::Boolean>& info);
|
||||
void php_v8js_array_access_query(uint32_t index,
|
||||
const v8::PropertyCallbackInfo<v8::Integer>& info);
|
||||
|
||||
/* Named Property Handlers */
|
||||
void php_v8js_array_access_named_getter(v8::Local<v8::String> property,
|
||||
|
@ -885,7 +885,7 @@ static v8::Handle<v8::Object> php_v8js_wrap_object(v8::Isolate *isolate, zend_cl
|
||||
if(has_array_access && has_countable) {
|
||||
inst_tpl->SetIndexedPropertyHandler(php_v8js_array_access_getter,
|
||||
php_v8js_array_access_setter,
|
||||
0, /* query */
|
||||
php_v8js_array_access_query,
|
||||
php_v8js_array_access_deleter,
|
||||
php_v8js_array_access_enumerator);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user