[prev in list] [next in list] [prev in thread] [next in thread]
List: pecl-cvs
Subject: [PECL-CVS] com pecl/languages/v8js: Implement isset behaviour on ArrayAccess objects: =?UTF-8?Q?test
From: Stefan Siegl <stesie () php ! net>
Date: 2014-11-30 21:43:56
Message-ID: php-mail-2172d4a5cdaa40cad70f4cfa38392142492070296 () git ! php ! net
[Download RAW message or body]
Commit: 901268994a260105c36a2f77eab730ad9792d73a
Author: Stefan Siegl <stesie@brokenpipe.de> Sun, 30 Nov 2014 22:43:56 \
+0100
Parents: 1b027a525f65aea0e721c792b6d8bea7ebf351f5
Branches: master
Link: http://git.php.net/?p=pecl/languages/v8js.git;a=commitdiff;h=901268994a260105c36a2f77eab730ad9792d73a
Log:
Implement isset behaviour on ArrayAccess objects
Changed paths:
A tests/array_access_008.phpt
M v8js_array_access.cc
M v8js_array_access.h
M v8js_object_export.cc
Diff:
diff --git a/tests/array_access_008.phpt b/tests/array_access_008.phpt
new file mode 100644
index 0000000..23507eb
--- /dev/null
+++ b/tests/array_access_008.phpt
@@ -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===
diff --git a/v8js_array_access.cc b/v8js_array_access.cc
index 5af4a01..35d7713 100644
--- a/v8js_array_access.cc
+++ b/v8js_array_access.cc
@@ -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) /* {{{ */ {
diff --git a/v8js_array_access.h b/v8js_array_access.h
index df76cbd..0d3f36d 100644
--- a/v8js_array_access.h
+++ b/v8js_array_access.h
@@ -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,
diff --git a/v8js_object_export.cc b/v8js_object_export.cc
index dbfa05c..014673c 100644
--- a/v8js_object_export.cc
+++ b/v8js_object_export.cc
@@ -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);
--
PECL CVS Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic