0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-09-19 00:25:18 +00:00

Rename V8Object stuff to v8js_v8object_XXX

This commit is contained in:
Stefan Siegl 2014-12-13 00:28:09 +01:00
parent f987cc7b4c
commit 6869d318b3
7 changed files with 106 additions and 102 deletions

View File

@ -121,9 +121,6 @@ static inline const char * ToCString(const v8::String::Utf8Value &value) /* {{{
/* Create PHP V8 object */
void php_v8js_create_v8(zval *, v8::Handle<v8::Value>, int, v8::Isolate * TSRMLS_DC);
/* Fetch V8 object properties */
int php_v8js_v8_get_properties_hash(v8::Handle<v8::Value>, HashTable *, int, v8::Isolate * TSRMLS_DC);
/* Convert zval into V8 value */
v8::Handle<v8::Value> zval_to_v8js(zval *, v8::Isolate * TSRMLS_DC);

View File

@ -27,6 +27,7 @@ extern "C" {
#include "php_v8js_macros.h"
#include "v8js_object_export.h"
#include "v8js_v8.h"
#include <stdexcept>
#include <limits>
@ -246,7 +247,7 @@ int v8js_to_zval(v8::Handle<v8::Value> jsValue, zval *return_value, int flags, v
}
if ((flags & V8JS_FLAG_FORCE_ARRAY) || jsValue->IsArray()) {
array_init(return_value);
return php_v8js_v8_get_properties_hash(jsValue, Z_ARRVAL_P(return_value), flags, isolate TSRMLS_CC);
return v8js_get_properties_hash(jsValue, Z_ARRVAL_P(return_value), flags, isolate TSRMLS_CC);
} else {
php_v8js_create_v8(return_value, jsValue, flags, isolate TSRMLS_CC);
return SUCCESS;

View File

@ -954,7 +954,7 @@ v8::Handle<v8::Value> php_v8js_hash_to_jsobj(zval *value, v8::Isolate *isolate T
}
/* Special case, passing back object originating from JS to JS */
if (ce == php_ce_v8_function) {
if (ce == php_ce_v8function) {
v8js_v8object *c = (v8js_v8object *) zend_object_store_get_object(value TSRMLS_CC);
if(isolate != c->ctx->isolate) {

View File

@ -205,6 +205,61 @@ void v8js_terminate_execution(php_v8js_ctx *c TSRMLS_DC) /* {{{ */
}
/* }}} */
int v8js_get_properties_hash(v8::Handle<v8::Value> jsValue, HashTable *retval, int flags, v8::Isolate *isolate TSRMLS_DC) /* {{{ */
{
v8::Local<v8::Object> jsObj = jsValue->ToObject();
if (!jsObj.IsEmpty()) {
v8::Local<v8::Array> jsKeys = jsObj->GetPropertyNames();
for (unsigned i = 0; i < jsKeys->Length(); i++)
{
v8::Local<v8::String> jsKey = jsKeys->Get(i)->ToString();
/* Skip any prototype properties */
if (!jsObj->HasOwnProperty(jsKey) && !jsObj->HasRealNamedProperty(jsKey) && !jsObj->HasRealNamedCallbackProperty(jsKey)) {
continue;
}
v8::Local<v8::Value> jsVal = jsObj->Get(jsKey);
v8::String::Utf8Value cstr(jsKey);
const char *key = ToCString(cstr);
zval *value = NULL;
v8::Local<v8::Value> php_object;
if (jsVal->IsObject()) {
php_object = v8::Local<v8::Object>::Cast(jsVal)->GetHiddenValue(V8JS_SYM(PHPJS_OBJECT_KEY));
}
if (!php_object.IsEmpty()) {
/* This is a PHP object, passed to JS and back. */
value = reinterpret_cast<zval *>(v8::External::Cast(*php_object)->Value());
Z_ADDREF_P(value);
}
else {
MAKE_STD_ZVAL(value);
if (v8js_to_zval(jsVal, value, flags, isolate TSRMLS_CC) == FAILURE) {
zval_ptr_dtor(&value);
return FAILURE;
}
}
if ((flags & V8JS_FLAG_FORCE_ARRAY) || jsValue->IsArray()) {
zend_symtable_update(retval, key, strlen(key) + 1, (void *)&value, sizeof(zval *), NULL);
} else {
zend_hash_update(retval, key, strlen(key) + 1, (void *) &value, sizeof(zval *), NULL);
}
}
return SUCCESS;
}
return FAILURE;
}
/* }}} */
/*
* Local variables:
* tab-width: 4

View File

@ -20,6 +20,8 @@ void v8js_v8_call(php_v8js_ctx *c, zval **return_value,
std::function< v8::Local<v8::Value>(v8::Isolate *) >& v8_call TSRMLS_DC);
void v8js_terminate_execution(php_v8js_ctx *c TSRMLS_DC);
/* Fetch V8 object properties */
int v8js_get_properties_hash(v8::Handle<v8::Value> jsValue, HashTable *retval, int flags, v8::Isolate *isolate TSRMLS_DC);
#define V8JS_CTX_PROLOGUE(ctx) \
if (!V8JSG(v8_initialized)) { \

View File

@ -30,12 +30,12 @@ extern "C" {
#include "v8js_v8.h"
/* {{{ Class Entries */
zend_class_entry *php_ce_v8_object;
zend_class_entry *php_ce_v8_function;
zend_class_entry *php_ce_v8object;
zend_class_entry *php_ce_v8function;
/* }}} */
/* {{{ Object Handlers */
static zend_object_handlers v8_object_handlers;
static zend_object_handlers v8js_v8object_handlers;
/* }}} */
#define V8JS_V8_INVOKE_FUNC_NAME "V8Js::V8::Invoke"
@ -43,7 +43,7 @@ static zend_object_handlers v8_object_handlers;
/* V8 Object handlers */
static int php_v8js_v8_has_property(zval *object, zval *member, int has_set_exists ZEND_HASH_KEY_DC TSRMLS_DC) /* {{{ */
static int v8js_v8object_has_property(zval *object, zval *member, int has_set_exists ZEND_HASH_KEY_DC TSRMLS_DC) /* {{{ */
{
/* param has_set_exists:
* 0 (has) whether property exists and is not NULL - isset()
@ -113,7 +113,7 @@ static int php_v8js_v8_has_property(zval *object, zval *member, int has_set_exis
}
/* }}} */
static zval *php_v8js_v8_read_property(zval *object, zval *member, int type ZEND_HASH_KEY_DC TSRMLS_DC) /* {{{ */
static zval *v8js_v8object_read_property(zval *object, zval *member, int type ZEND_HASH_KEY_DC TSRMLS_DC) /* {{{ */
{
zval *retval = NULL;
v8js_v8object *obj = (v8js_v8object *) zend_object_store_get_object(object TSRMLS_CC);
@ -164,7 +164,7 @@ static zval *php_v8js_v8_read_property(zval *object, zval *member, int type ZEND
}
/* }}} */
static void php_v8js_v8_write_property(zval *object, zval *member, zval *value ZEND_HASH_KEY_DC TSRMLS_DC) /* {{{ */
static void v8js_v8object_write_property(zval *object, zval *member, zval *value ZEND_HASH_KEY_DC TSRMLS_DC) /* {{{ */
{
v8js_v8object *obj = (v8js_v8object *) zend_object_store_get_object(object TSRMLS_CC);
@ -189,7 +189,7 @@ static void php_v8js_v8_write_property(zval *object, zval *member, zval *value Z
}
/* }}} */
static void php_v8js_v8_unset_property(zval *object, zval *member ZEND_HASH_KEY_DC TSRMLS_DC) /* {{{ */
static void v8js_v8object_unset_property(zval *object, zval *member ZEND_HASH_KEY_DC TSRMLS_DC) /* {{{ */
{
v8js_v8object *obj = (v8js_v8object *) zend_object_store_get_object(object TSRMLS_CC);
@ -214,58 +214,7 @@ static void php_v8js_v8_unset_property(zval *object, zval *member ZEND_HASH_KEY_
}
/* }}} */
int php_v8js_v8_get_properties_hash(v8::Handle<v8::Value> jsValue, HashTable *retval, int flags, v8::Isolate *isolate TSRMLS_DC) /* {{{ */
{
v8::Local<v8::Object> jsObj = jsValue->ToObject();
if (!jsObj.IsEmpty()) {
v8::Local<v8::Array> jsKeys = jsObj->GetPropertyNames();
for (unsigned i = 0; i < jsKeys->Length(); i++)
{
v8::Local<v8::String> jsKey = jsKeys->Get(i)->ToString();
/* Skip any prototype properties */
if (!jsObj->HasOwnProperty(jsKey) && !jsObj->HasRealNamedProperty(jsKey) && !jsObj->HasRealNamedCallbackProperty(jsKey)) {
continue;
}
v8::Local<v8::Value> jsVal = jsObj->Get(jsKey);
v8::String::Utf8Value cstr(jsKey);
const char *key = ToCString(cstr);
zval *value = NULL;
v8::Local<v8::Value> php_object;
if (jsVal->IsObject()) {
php_object = v8::Local<v8::Object>::Cast(jsVal)->GetHiddenValue(V8JS_SYM(PHPJS_OBJECT_KEY));
}
if (!php_object.IsEmpty()) {
/* This is a PHP object, passed to JS and back. */
value = reinterpret_cast<zval *>(v8::External::Cast(*php_object)->Value());
Z_ADDREF_P(value);
}
else {
MAKE_STD_ZVAL(value);
if (v8js_to_zval(jsVal, value, flags, isolate TSRMLS_CC) == FAILURE) {
zval_ptr_dtor(&value);
return FAILURE;
}
}
if ((flags & V8JS_FLAG_FORCE_ARRAY) || jsValue->IsArray()) {
zend_symtable_update(retval, key, strlen(key) + 1, (void *)&value, sizeof(zval *), NULL);
} else {
zend_hash_update(retval, key, strlen(key) + 1, (void *) &value, sizeof(zval *), NULL);
}
}
return SUCCESS;
}
return FAILURE;
}
/* }}} */
static HashTable *php_v8js_v8_get_properties(zval *object TSRMLS_DC) /* {{{ */
static HashTable *v8js_v8object_get_properties(zval *object TSRMLS_DC) /* {{{ */
{
v8js_v8object *obj = (v8js_v8object *) zend_object_store_get_object(object TSRMLS_CC);
HashTable *retval;
@ -303,7 +252,7 @@ static HashTable *php_v8js_v8_get_properties(zval *object TSRMLS_DC) /* {{{ */
v8::Context::Scope temp_scope(temp_context);
v8::Local<v8::Value> v8obj = v8::Local<v8::Value>::New(isolate, obj->v8obj);
if (php_v8js_v8_get_properties_hash(v8obj, obj->properties, obj->flags, isolate TSRMLS_CC) == SUCCESS) {
if (v8js_get_properties_hash(v8obj, obj->properties, obj->flags, isolate TSRMLS_CC) == SUCCESS) {
return obj->properties;
}
@ -311,14 +260,14 @@ static HashTable *php_v8js_v8_get_properties(zval *object TSRMLS_DC) /* {{{ */
}
/* }}} */
static HashTable *php_v8js_v8_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
static HashTable *v8js_v8object_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
{
*is_temp = 0;
return php_v8js_v8_get_properties(object TSRMLS_CC);
return v8js_v8object_get_properties(object TSRMLS_CC);
}
/* }}} */
static zend_function *php_v8js_v8_get_method(zval **object_ptr, char *method, int method_len ZEND_HASH_KEY_DC TSRMLS_DC) /* {{{ */
static zend_function *v8js_v8object_get_method(zval **object_ptr, char *method, int method_len ZEND_HASH_KEY_DC TSRMLS_DC) /* {{{ */
{
v8js_v8object *obj = (v8js_v8object *) zend_object_store_get_object(*object_ptr TSRMLS_CC);
zend_function *f;
@ -354,9 +303,9 @@ static zend_function *php_v8js_v8_get_method(zval **object_ptr, char *method, in
/* }}} */
#if PHP_VERSION_ID >= 50400
static int php_v8js_v8_call_method(const char *method, INTERNAL_FUNCTION_PARAMETERS) /* {{{ */
static int v8js_v8object_call_method(const char *method, INTERNAL_FUNCTION_PARAMETERS) /* {{{ */
#else
static int php_v8js_v8_call_method(char *method, INTERNAL_FUNCTION_PARAMETERS) /* {{{ */
static int v8js_v8object_call_method(char *method, INTERNAL_FUNCTION_PARAMETERS) /* {{{ */
#endif
{
zval *object = this_ptr, ***argv = NULL;
@ -416,7 +365,7 @@ static int php_v8js_v8_call_method(char *method, INTERNAL_FUNCTION_PARAMETERS) /
}
/* }}} */
static int php_v8js_v8_get_closure(zval *object, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zval **zobj_ptr TSRMLS_DC) /* {{{ */
static int v8js_v8object_get_closure(zval *object, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zval **zobj_ptr TSRMLS_DC) /* {{{ */
{
zend_function *invoke;
@ -456,7 +405,7 @@ static int php_v8js_v8_get_closure(zval *object, zend_class_entry **ce_ptr, zend
}
/* }}} */
static void php_v8js_v8_free_storage(void *object, zend_object_handle handle TSRMLS_DC) /* {{{ */
static void v8js_v8object_free_storage(void *object, zend_object_handle handle TSRMLS_DC) /* {{{ */
{
v8js_v8object *c = (v8js_v8object *) object;
@ -477,7 +426,7 @@ static void php_v8js_v8_free_storage(void *object, zend_object_handle handle TSR
}
/* }}} */
static zend_object_value php_v8js_v8_new(zend_class_entry *ce TSRMLS_DC) /* {{{ */
static zend_object_value v8js_v8object_new(zend_class_entry *ce TSRMLS_DC) /* {{{ */
{
zend_object_value retval;
v8js_v8object *c;
@ -487,14 +436,14 @@ static zend_object_value php_v8js_v8_new(zend_class_entry *ce TSRMLS_DC) /* {{{
zend_object_std_init(&c->std, ce TSRMLS_CC);
new(&c->v8obj) v8::Persistent<v8::Value>();
retval.handle = zend_objects_store_put(c, NULL, (zend_objects_free_object_storage_t) php_v8js_v8_free_storage, NULL TSRMLS_CC);
retval.handlers = &v8_object_handlers;
retval.handle = zend_objects_store_put(c, NULL, (zend_objects_free_object_storage_t) v8js_v8object_free_storage, NULL TSRMLS_CC);
retval.handlers = &v8js_v8object_handlers;
return retval;
}
/* }}} */
/* NOTE: We could also override v8_object_handlers.get_constructor to throw
/* NOTE: We could also override v8js_v8object_handlers.get_constructor to throw
* an exception when invoked, but doing so causes the half-constructed object
* to leak -- this seems to be a PHP bug. So we'll define magic __construct
* methods instead. */
@ -564,7 +513,7 @@ void php_v8js_create_v8(zval *res, v8::Handle<v8::Value> value, int flags, v8::I
php_v8js_ctx *ctx = (php_v8js_ctx *) isolate->GetData(0);
v8js_v8object *c;
object_init_ex(res, value->IsFunction() ? php_ce_v8_function : php_ce_v8_object);
object_init_ex(res, value->IsFunction() ? php_ce_v8function : php_ce_v8object);
c = (v8js_v8object *) zend_object_store_get_object(res TSRMLS_CC);
@ -578,7 +527,7 @@ void php_v8js_create_v8(zval *res, v8::Handle<v8::Value> value, int flags, v8::I
/* }}} */
static const zend_function_entry v8_object_methods[] = { /* {{{ */
static const zend_function_entry v8js_v8object_methods[] = { /* {{{ */
PHP_ME(V8Object, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(V8Object, __sleep, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(V8Object, __wakeup, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
@ -586,7 +535,7 @@ static const zend_function_entry v8_object_methods[] = { /* {{{ */
};
/* }}} */
static const zend_function_entry v8_function_methods[] = { /* {{{ */
static const zend_function_entry v8js_v8function_methods[] = { /* {{{ */
PHP_ME(V8Function, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(V8Function, __sleep, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(V8Function, __wakeup, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
@ -600,31 +549,31 @@ PHP_MINIT_FUNCTION(v8js_v8object_class) /* {{{ */
zend_class_entry ce;
/* V8Object Class */
INIT_CLASS_ENTRY(ce, "V8Object", v8_object_methods);
php_ce_v8_object = zend_register_internal_class(&ce TSRMLS_CC);
php_ce_v8_object->ce_flags |= ZEND_ACC_FINAL;
php_ce_v8_object->create_object = php_v8js_v8_new;
INIT_CLASS_ENTRY(ce, "V8Object", v8js_v8object_methods);
php_ce_v8object = zend_register_internal_class(&ce TSRMLS_CC);
php_ce_v8object->ce_flags |= ZEND_ACC_FINAL;
php_ce_v8object->create_object = v8js_v8object_new;
/* V8Function Class */
INIT_CLASS_ENTRY(ce, "V8Function", v8_function_methods);
php_ce_v8_function = zend_register_internal_class(&ce TSRMLS_CC);
php_ce_v8_function->ce_flags |= ZEND_ACC_FINAL;
php_ce_v8_function->create_object = php_v8js_v8_new;
INIT_CLASS_ENTRY(ce, "V8Function", v8js_v8function_methods);
php_ce_v8function = zend_register_internal_class(&ce TSRMLS_CC);
php_ce_v8function->ce_flags |= ZEND_ACC_FINAL;
php_ce_v8function->create_object = v8js_v8object_new;
/* V8<Object|Function> handlers */
memcpy(&v8_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
v8_object_handlers.clone_obj = NULL;
v8_object_handlers.cast_object = NULL;
v8_object_handlers.get_property_ptr_ptr = NULL;
v8_object_handlers.has_property = php_v8js_v8_has_property;
v8_object_handlers.read_property = php_v8js_v8_read_property;
v8_object_handlers.write_property = php_v8js_v8_write_property;
v8_object_handlers.unset_property = php_v8js_v8_unset_property;
v8_object_handlers.get_properties = php_v8js_v8_get_properties;
v8_object_handlers.get_method = php_v8js_v8_get_method;
v8_object_handlers.call_method = php_v8js_v8_call_method;
v8_object_handlers.get_debug_info = php_v8js_v8_get_debug_info;
v8_object_handlers.get_closure = php_v8js_v8_get_closure;
memcpy(&v8js_v8object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
v8js_v8object_handlers.clone_obj = NULL;
v8js_v8object_handlers.cast_object = NULL;
v8js_v8object_handlers.get_property_ptr_ptr = NULL;
v8js_v8object_handlers.has_property = v8js_v8object_has_property;
v8js_v8object_handlers.read_property = v8js_v8object_read_property;
v8js_v8object_handlers.write_property = v8js_v8object_write_property;
v8js_v8object_handlers.unset_property = v8js_v8object_unset_property;
v8js_v8object_handlers.get_properties = v8js_v8object_get_properties;
v8js_v8object_handlers.get_method = v8js_v8object_get_method;
v8js_v8object_handlers.call_method = v8js_v8object_call_method;
v8js_v8object_handlers.get_debug_info = v8js_v8object_get_debug_info;
v8js_v8object_handlers.get_closure = v8js_v8object_get_closure;
} /* }}} */

View File

@ -14,8 +14,8 @@
#ifndef V8JS_V8OBJECT_CLASS_H
#define V8JS_V8OBJECT_CLASS_H
extern zend_class_entry *php_ce_v8_object;
extern zend_class_entry *php_ce_v8_function;
extern zend_class_entry *php_ce_v8object;
extern zend_class_entry *php_ce_v8function;
PHP_MINIT_FUNCTION(v8js_v8object_class);