[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pecl-cvs
Subject:    [PECL-CVS] com pecl/languages/v8js: Refactor PHP method call code: =?UTF-8?Q?v=38js=5Farray=5Faccess
From:       Stefan Siegl <stesie () php ! net>
Date:       2014-11-30 22:30:28
Message-ID: php-mail-94701dbf48c0e3edf5230877eed9f771877825730 () git ! php ! net
[Download RAW message or body]

Commit:    dba4da9b8bdcf418c6736338608f0aa55216fb9e
Author:    Stefan Siegl <stesie@brokenpipe.de>         Sun, 30 Nov 2014 23:30:28 \
                +0100
Parents:   901268994a260105c36a2f77eab730ad9792d73a
Branches:  master

Link:       http://git.php.net/?p=pecl/languages/v8js.git;a=commitdiff;h=dba4da9b8bdcf418c6736338608f0aa55216fb9e


Log:
Refactor PHP method call code

Changed paths:
  M  v8js_array_access.cc
  M  v8js_array_access.h


Diff:
diff --git a/v8js_array_access.cc b/v8js_array_access.cc
index 35d7713..2f95f33 100644
--- a/v8js_array_access.cc
+++ b/v8js_array_access.cc
@@ -26,15 +26,10 @@ extern "C" {
 #include "v8js_array_access.h"
 #include "v8js_object_export.h"
 
-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();
 
-	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());
+static zval *php_v8js_array_access_dispatch(zval *object, const char *method_name, \
int param_count, +											uint32_t index, zval *zvalue_ptr TSRMLS_DC) /* {{{ */
+{
 	zend_class_entry *ce = Z_OBJCE_P(object);
 
 	/* Okay, let's call offsetGet. */
@@ -43,7 +38,7 @@ void php_v8js_array_access_getter(uint32_t index, const \
v8::PropertyCallbackInfo  
 	zval fmember;
 	INIT_ZVAL(fmember);
-	ZVAL_STRING(&fmember, "offsetGet", 0);
+	ZVAL_STRING(&fmember, method_name, 0);
 
 	zval zindex;
 	INIT_ZVAL(zindex);
@@ -56,15 +51,32 @@ void php_v8js_array_access_getter(uint32_t index, const \
v8::PropertyCallbackInfo  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;
+	zval **params[2] = { &zindex_ptr, &zvalue_ptr };
+
+	fci.param_count = param_count;
+	fci.params = params;
 
 	fci.object_ptr = object;
 	fci.no_separation = 0;
 
 	zend_call_function(&fci, NULL TSRMLS_CC);
+	return php_value;
+}
+/* }}} */
+
 
+
+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();
+
+	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());
+
+	zval *php_value = php_v8js_array_access_dispatch(object, "offsetGet", 1, index, \
NULL);  v8::Local<v8::Value> ret_value = zval_to_v8js(php_value, isolate TSRMLS_CC);
 	zval_ptr_dtor(&php_value);
 
@@ -82,19 +94,6 @@ void php_v8js_array_access_setter(uint32_t index, \
v8::Local<v8::Value> value,  
 	v8::Local<v8::Value> php_object = self->GetHiddenValue(V8JS_SYM(PHPJS_OBJECT_KEY));
 	zval *object = reinterpret_cast<zval *>(v8::External::Cast(*php_object)->Value());
-	zend_class_entry *ce = Z_OBJCE_P(object);
-
-	/* Okay, let's call offsetSet. */
-	zend_fcall_info fci;
-	zval *php_value;
-
-	zval fmember;
-	INIT_ZVAL(fmember);
-	ZVAL_STRING(&fmember, "offsetSet", 0);
-
-	zval zindex;
-	INIT_ZVAL(zindex);
-	ZVAL_LONG(&zindex, index);
 
 	zval *zvalue_ptr;
 	MAKE_STD_ZVAL(zvalue_ptr);
@@ -103,22 +102,7 @@ void php_v8js_array_access_setter(uint32_t index, \
v8::Local<v8::Value> value,  return;
 	}
 
-	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 **params[2] = { &zindex_ptr, &zvalue_ptr };
-
-	fci.param_count = 2;
-	fci.params = params;
-
-	fci.object_ptr = object;
-	fci.no_separation = 0;
-
-	zend_call_function(&fci, NULL TSRMLS_CC);
+	zval *php_value = php_v8js_array_access_dispatch(object, "offsetSet", 2, index, \
zvalue_ptr);  zval_ptr_dtor(&php_value);
 
 	/* simply pass back the value to tell we intercepted the call
@@ -134,28 +118,7 @@ void php_v8js_array_access_setter(uint32_t index, \
v8::Local<v8::Value> value,  
 static int php_v8js_array_access_get_count_result(zval *object TSRMLS_DC) /* {{{ */
 {
-	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);
+	zval *php_value = php_v8js_array_access_dispatch(object, "count", 0, 0, NULL);
 
 	if(Z_TYPE_P(php_value) != IS_LONG) {
 		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Non-numeric return value from count() \
method"); @@ -171,35 +134,7 @@ static int php_v8js_array_access_get_count_result(zval \
*object TSRMLS_DC) /* {{{  
 static bool php_v8js_array_access_isset_p(zval *object, int index TSRMLS_DC) /* {{{ \
*/  {
-	zend_class_entry *ce = Z_OBJCE_P(object);
-
-	/* Okay, let's call offsetExists. */
-	zend_fcall_info fci;
-	zval *php_value;
-
-	zval fmember;
-	INIT_ZVAL(fmember);
-	ZVAL_STRING(&fmember, "offsetExists", 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);
+	zval *php_value = php_v8js_array_access_dispatch(object, "offsetExists", 1, index, \
NULL);  
 	if(Z_TYPE_P(php_value) != IS_BOOL) {
 		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Non-boolean return value from \
offsetExists() method"); @@ -214,7 +149,7 @@ static bool \
php_v8js_array_access_isset_p(zval *object, int index TSRMLS_DC) /*  /* }}} */
 
 
-void php_v8js_array_access_length(v8::Local<v8::String> property, const \
v8::PropertyCallbackInfo<v8::Value>& info) /* {{{ */ +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();
@@ -238,36 +173,10 @@ void php_v8js_array_access_deleter(uint32_t index, const \
v8::PropertyCallbackInf  
 	v8::Local<v8::Value> php_object = self->GetHiddenValue(V8JS_SYM(PHPJS_OBJECT_KEY));
 	zval *object = reinterpret_cast<zval *>(v8::External::Cast(*php_object)->Value());
-	zend_class_entry *ce = Z_OBJCE_P(object);
 
-	/* Okay, let's call offsetUnset. */
-	zend_fcall_info fci;
-	zval *php_value;
-
-	zval fmember;
-	INIT_ZVAL(fmember);
-	ZVAL_STRING(&fmember, "offsetUnset", 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);
+	zval *php_value = php_v8js_array_access_dispatch(object, "offsetUnset", 1, index, \
NULL);  zval_ptr_dtor(&php_value);
+
 	info.GetReturnValue().Set(V8JS_BOOL(true));
 }
 /* }}} */
diff --git a/v8js_array_access.h b/v8js_array_access.h
index 0d3f36d..58bd63e 100644
--- a/v8js_array_access.h
+++ b/v8js_array_access.h
@@ -18,8 +18,6 @@ void php_v8js_array_access_getter(uint32_t index,
 				  const v8::PropertyCallbackInfo<v8::Value>& info);
 void php_v8js_array_access_setter(uint32_t index, v8::Local<v8::Value> value,
 				  const v8::PropertyCallbackInfo<v8::Value>& info);
-void php_v8js_array_access_length(v8::Local<v8::String> property,
-				  const v8::PropertyCallbackInfo<v8::Value>& info);
 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);


--
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