|
@@ -866,6 +866,105 @@ static void php_v8js_named_property_deleter(v8::Local<v8::String> property, cons
|
|
|
}
|
|
|
/* }}} */
|
|
|
|
|
|
+static void php_v8js_array_access_getter(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info) /* {{{ */
|
|
|
+{
|
|
|
+ v8::Isolate *isolate = info.GetIsolate();
|
|
|
+ v8::Local<v8::Object> self = info.Holder();
|
|
|
+
|
|
|
+ zval *object = reinterpret_cast<zval *>(self->GetAlignedPointerFromInternalField(0));
|
|
|
+ zend_class_entry *ce = Z_OBJCE_P(object);
|
|
|
+
|
|
|
+ /* Okay, let's call offsetGet. */
|
|
|
+ zend_fcall_info fci;
|
|
|
+ zval *php_value;
|
|
|
+
|
|
|
+ zval fmember;
|
|
|
+ INIT_ZVAL(fmember);
|
|
|
+ ZVAL_STRING(&fmember, "offsetGet", 0);
|
|
|
+
|
|
|
+ zval zindex;
|
|
|
+ INIT_ZVAL(zindex);
|
|
|
+ ZVAL_LONG(&zindex, index);
|
|
|
+
|
|
|
+ fci.size = sizeof(fci);
|
|
|
+ fci.function_table = &ce->function_table;
|
|
|
+ fci.function_name = &fmember;
|
|
|
+ fci.symbol_table = NULL;
|
|
|
+ fci.retval_ptr_ptr = &php_value;
|
|
|
+
|
|
|
+ zval *zindex_ptr = &zindex;
|
|
|
+ zval **zindex_ptr_ptr = &zindex_ptr;
|
|
|
+ fci.param_count = 1;
|
|
|
+ fci.params = &zindex_ptr_ptr;
|
|
|
+
|
|
|
+ fci.object_ptr = object;
|
|
|
+ fci.no_separation = 0;
|
|
|
+
|
|
|
+ zend_call_function(&fci, NULL TSRMLS_CC);
|
|
|
+
|
|
|
+ v8::Local<v8::Value> ret_value = zval_to_v8js(php_value, isolate TSRMLS_CC);
|
|
|
+ zval_ptr_dtor(&php_value);
|
|
|
+
|
|
|
+ info.GetReturnValue().Set(ret_value);
|
|
|
+}
|
|
|
+/* }}} */
|
|
|
+
|
|
|
+static void php_v8js_array_access_length(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& info) /* {{{ */
|
|
|
+{
|
|
|
+ v8::Isolate *isolate = info.GetIsolate();
|
|
|
+ v8::Local<v8::Object> self = info.Holder();
|
|
|
+
|
|
|
+ zval *object = reinterpret_cast<zval *>(self->GetAlignedPointerFromInternalField(0));
|
|
|
+ zend_class_entry *ce = Z_OBJCE_P(object);
|
|
|
+
|
|
|
+ zend_fcall_info fci;
|
|
|
+ zval *php_value;
|
|
|
+
|
|
|
+ zval fmember;
|
|
|
+ INIT_ZVAL(fmember);
|
|
|
+ ZVAL_STRING(&fmember, "count", 0);
|
|
|
+
|
|
|
+ fci.size = sizeof(fci);
|
|
|
+ fci.function_table = &ce->function_table;
|
|
|
+ fci.function_name = &fmember;
|
|
|
+ fci.symbol_table = NULL;
|
|
|
+ fci.retval_ptr_ptr = &php_value;
|
|
|
+
|
|
|
+ fci.param_count = 0;
|
|
|
+ fci.params = NULL;
|
|
|
+
|
|
|
+ fci.object_ptr = object;
|
|
|
+ fci.no_separation = 0;
|
|
|
+
|
|
|
+ zend_call_function(&fci, NULL TSRMLS_CC);
|
|
|
+
|
|
|
+ v8::Local<v8::Value> ret_value = zval_to_v8js(php_value, isolate TSRMLS_CC);
|
|
|
+ zval_ptr_dtor(&php_value);
|
|
|
+
|
|
|
+ info.GetReturnValue().Set(ret_value);
|
|
|
+}
|
|
|
+/* }}} */
|
|
|
+
|
|
|
+
|
|
|
+static v8::Handle<v8::Value> php_v8js_array_access_to_jsobj(zval *value, v8::Isolate *isolate TSRMLS_DC) /* {{{ */
|
|
|
+{
|
|
|
+ v8::Local<v8::FunctionTemplate> aa_tpl = v8::FunctionTemplate::New(isolate, 0);
|
|
|
+ aa_tpl->SetClassName(V8JS_SYM("ArrayAccess"));
|
|
|
+
|
|
|
+ v8::Local<v8::ObjectTemplate> inst_tpl = aa_tpl->InstanceTemplate();
|
|
|
+ inst_tpl->SetIndexedPropertyHandler(php_v8js_array_access_getter);
|
|
|
+ inst_tpl->SetAccessor(V8JS_STR("length"), php_v8js_array_access_length);
|
|
|
+ inst_tpl->SetInternalFieldCount(1);
|
|
|
+
|
|
|
+
|
|
|
+ v8::Handle<v8::Object> newobj = inst_tpl->NewInstance();
|
|
|
+ newobj->SetAlignedPointerInInternalField(0, value);
|
|
|
+
|
|
|
+ return newobj;
|
|
|
+}
|
|
|
+/* }}} */
|
|
|
+
|
|
|
+
|
|
|
static v8::Handle<v8::Value> php_v8js_hash_to_jsobj(zval *value, v8::Isolate *isolate TSRMLS_DC) /* {{{ */
|
|
|
{
|
|
|
v8::Handle<v8::Object> newobj;
|
|
@@ -889,6 +988,25 @@ static v8::Handle<v8::Value> php_v8js_hash_to_jsobj(zval *value, v8::Isolate *is
|
|
|
return V8JS_NULL;
|
|
|
}
|
|
|
|
|
|
+ /* Check for ArrayAccess object */
|
|
|
+ if (V8JSG(use_array_access) && ce) {
|
|
|
+ bool has_array_access = false;
|
|
|
+ bool has_countable = false;
|
|
|
+
|
|
|
+ for (int i = 0; i < ce->num_interfaces; i ++) {
|
|
|
+ if (strcmp (ce->interfaces[i]->name, "ArrayAccess") == 0) {
|
|
|
+ has_array_access = true;
|
|
|
+ }
|
|
|
+ else if (strcmp (ce->interfaces[i]->name, "Countable") == 0) {
|
|
|
+ has_countable = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(has_array_access && has_countable) {
|
|
|
+ return php_v8js_array_access_to_jsobj(value, isolate TSRMLS_CC);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/* Object methods */
|
|
|
if (ce == php_ce_v8_function) {
|
|
|
php_v8js_object *c = (php_v8js_object *) zend_object_store_get_object(value TSRMLS_CC);
|