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

More php_v8js_ prefix cleanup

This commit is contained in:
Stefan Siegl 2014-12-13 01:30:23 +01:00
parent 294a5c8d1f
commit 5b4aaa64f1
13 changed files with 157 additions and 157 deletions

View File

@ -108,7 +108,7 @@ struct v8js_accessor_ctx
void v8js_accessor_ctx_dtor(v8js_accessor_ctx * TSRMLS_DC); void v8js_accessor_ctx_dtor(v8js_accessor_ctx * TSRMLS_DC);
/* Register accessors into passed object */ /* Register accessors into passed object */
void php_v8js_register_accessors(std::vector<v8js_accessor_ctx*> *accessor_list, v8::Local<v8::FunctionTemplate>, zval *, v8::Isolate * TSRMLS_DC); void v8js_register_accessors(std::vector<v8js_accessor_ctx*> *accessor_list, v8::Local<v8::FunctionTemplate>, zval *, v8::Isolate * TSRMLS_DC);
/* Resource declaration */ /* Resource declaration */
@ -142,15 +142,7 @@ ZEND_EXTERN_MODULE_GLOBALS(v8js)
#endif #endif
/* Register builtin methods into passed object */ /* Register builtin methods into passed object */
void php_v8js_register_methods(v8::Handle<v8::ObjectTemplate>, v8js_ctx *c); void v8js_register_methods(v8::Handle<v8::ObjectTemplate>, v8js_ctx *c);
typedef struct _v8js_script {
char *name;
v8::Isolate *isolate;
v8::Persistent<v8::Script, v8::CopyablePersistentTraits<v8::Script>> *script;
} v8js_script;
static void v8js_script_free(v8js_script *res, bool dispose_persistent);
#endif /* PHP_V8JS_MACROS_H */ #endif /* PHP_V8JS_MACROS_H */

View File

@ -27,7 +27,7 @@ extern "C" {
#include "v8js_object_export.h" #include "v8js_object_export.h"
static zval *php_v8js_array_access_dispatch(zval *object, const char *method_name, int param_count, static zval *v8js_array_access_dispatch(zval *object, const char *method_name, int param_count,
uint32_t index, zval *zvalue_ptr TSRMLS_DC) /* {{{ */ uint32_t index, zval *zvalue_ptr TSRMLS_DC) /* {{{ */
{ {
zend_class_entry *ce = Z_OBJCE_P(object); zend_class_entry *ce = Z_OBJCE_P(object);
@ -66,7 +66,7 @@ static zval *php_v8js_array_access_dispatch(zval *object, const char *method_nam
void php_v8js_array_access_getter(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info) /* {{{ */ void v8js_array_access_getter(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info) /* {{{ */
{ {
v8::Isolate *isolate = info.GetIsolate(); v8::Isolate *isolate = info.GetIsolate();
v8::Local<v8::Object> self = info.Holder(); v8::Local<v8::Object> self = info.Holder();
@ -76,7 +76,7 @@ void php_v8js_array_access_getter(uint32_t index, const v8::PropertyCallbackInfo
v8::Local<v8::Value> php_object = self->GetHiddenValue(V8JS_SYM(PHPJS_OBJECT_KEY)); 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 *object = reinterpret_cast<zval *>(v8::External::Cast(*php_object)->Value());
zval *php_value = php_v8js_array_access_dispatch(object, "offsetGet", 1, index, NULL TSRMLS_CC); zval *php_value = v8js_array_access_dispatch(object, "offsetGet", 1, index, NULL TSRMLS_CC);
v8::Local<v8::Value> ret_value = zval_to_v8js(php_value, isolate TSRMLS_CC); v8::Local<v8::Value> ret_value = zval_to_v8js(php_value, isolate TSRMLS_CC);
zval_ptr_dtor(&php_value); zval_ptr_dtor(&php_value);
@ -84,7 +84,7 @@ void php_v8js_array_access_getter(uint32_t index, const v8::PropertyCallbackInfo
} }
/* }}} */ /* }}} */
void php_v8js_array_access_setter(uint32_t index, v8::Local<v8::Value> value, void v8js_array_access_setter(uint32_t index, v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<v8::Value>& info) /* {{{ */ const v8::PropertyCallbackInfo<v8::Value>& info) /* {{{ */
{ {
v8::Isolate *isolate = info.GetIsolate(); v8::Isolate *isolate = info.GetIsolate();
@ -102,7 +102,7 @@ void php_v8js_array_access_setter(uint32_t index, v8::Local<v8::Value> value,
return; return;
} }
zval *php_value = php_v8js_array_access_dispatch(object, "offsetSet", 2, index, zvalue_ptr TSRMLS_CC); zval *php_value = v8js_array_access_dispatch(object, "offsetSet", 2, index, zvalue_ptr TSRMLS_CC);
zval_ptr_dtor(&php_value); zval_ptr_dtor(&php_value);
/* simply pass back the value to tell we intercepted the call /* simply pass back the value to tell we intercepted the call
@ -116,9 +116,9 @@ 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) /* {{{ */ static int v8js_array_access_get_count_result(zval *object TSRMLS_DC) /* {{{ */
{ {
zval *php_value = php_v8js_array_access_dispatch(object, "count", 0, 0, NULL TSRMLS_CC); zval *php_value = v8js_array_access_dispatch(object, "count", 0, 0, NULL TSRMLS_CC);
if(Z_TYPE_P(php_value) != IS_LONG) { if(Z_TYPE_P(php_value) != IS_LONG) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Non-numeric return value from count() method"); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Non-numeric return value from count() method");
@ -132,9 +132,9 @@ 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) /* {{{ */ static bool v8js_array_access_isset_p(zval *object, int index TSRMLS_DC) /* {{{ */
{ {
zval *php_value = php_v8js_array_access_dispatch(object, "offsetExists", 1, index, NULL TSRMLS_CC); zval *php_value = v8js_array_access_dispatch(object, "offsetExists", 1, index, NULL TSRMLS_CC);
if(Z_TYPE_P(php_value) != IS_BOOL) { if(Z_TYPE_P(php_value) != IS_BOOL) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Non-boolean return value from offsetExists() method"); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Non-boolean return value from offsetExists() method");
@ -149,7 +149,7 @@ static bool php_v8js_array_access_isset_p(zval *object, int index TSRMLS_DC) /*
/* }}} */ /* }}} */
static void php_v8js_array_access_length(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& info) /* {{{ */ static void v8js_array_access_length(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& info) /* {{{ */
{ {
v8::Isolate *isolate = info.GetIsolate(); v8::Isolate *isolate = info.GetIsolate();
v8::Local<v8::Object> self = info.Holder(); v8::Local<v8::Object> self = info.Holder();
@ -159,12 +159,12 @@ static void php_v8js_array_access_length(v8::Local<v8::String> property, const v
v8::Local<v8::Value> php_object = self->GetHiddenValue(V8JS_SYM(PHPJS_OBJECT_KEY)); 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 *object = reinterpret_cast<zval *>(v8::External::Cast(*php_object)->Value());
int length = php_v8js_array_access_get_count_result(object TSRMLS_CC); int length = v8js_array_access_get_count_result(object TSRMLS_CC);
info.GetReturnValue().Set(V8JS_INT(length)); info.GetReturnValue().Set(V8JS_INT(length));
} }
/* }}} */ /* }}} */
void php_v8js_array_access_deleter(uint32_t index, const v8::PropertyCallbackInfo<v8::Boolean>& info) /* {{{ */ void v8js_array_access_deleter(uint32_t index, const v8::PropertyCallbackInfo<v8::Boolean>& info) /* {{{ */
{ {
v8::Isolate *isolate = info.GetIsolate(); v8::Isolate *isolate = info.GetIsolate();
v8::Local<v8::Object> self = info.Holder(); v8::Local<v8::Object> self = info.Holder();
@ -174,14 +174,14 @@ 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)); 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 *object = reinterpret_cast<zval *>(v8::External::Cast(*php_object)->Value());
zval *php_value = php_v8js_array_access_dispatch(object, "offsetUnset", 1, index, NULL TSRMLS_CC); zval *php_value = v8js_array_access_dispatch(object, "offsetUnset", 1, index, NULL TSRMLS_CC);
zval_ptr_dtor(&php_value); zval_ptr_dtor(&php_value);
info.GetReturnValue().Set(V8JS_BOOL(true)); info.GetReturnValue().Set(V8JS_BOOL(true));
} }
/* }}} */ /* }}} */
void php_v8js_array_access_query(uint32_t index, const v8::PropertyCallbackInfo<v8::Integer>& info) /* {{{ */ void v8js_array_access_query(uint32_t index, const v8::PropertyCallbackInfo<v8::Integer>& info) /* {{{ */
{ {
v8::Isolate *isolate = info.GetIsolate(); v8::Isolate *isolate = info.GetIsolate();
v8::Local<v8::Object> self = info.Holder(); v8::Local<v8::Object> self = info.Holder();
@ -193,14 +193,14 @@ void php_v8js_array_access_query(uint32_t index, const v8::PropertyCallbackInfo<
/* If index is set, then return an integer encoding a v8::PropertyAttribute; /* If index is set, then return an integer encoding a v8::PropertyAttribute;
* otherwise we're expected to return an empty handle. */ * otherwise we're expected to return an empty handle. */
if(php_v8js_array_access_isset_p(object, index TSRMLS_CC)) { if(v8js_array_access_isset_p(object, index TSRMLS_CC)) {
info.GetReturnValue().Set(V8JS_UINT(v8::PropertyAttribute::None)); info.GetReturnValue().Set(V8JS_UINT(v8::PropertyAttribute::None));
} }
} }
/* }}} */ /* }}} */
void php_v8js_array_access_enumerator(const v8::PropertyCallbackInfo<v8::Array>& info) /* {{{ */ void v8js_array_access_enumerator(const v8::PropertyCallbackInfo<v8::Array>& info) /* {{{ */
{ {
v8::Isolate *isolate = info.GetIsolate(); v8::Isolate *isolate = info.GetIsolate();
v8::Local<v8::Object> self = info.Holder(); v8::Local<v8::Object> self = info.Holder();
@ -210,13 +210,13 @@ void php_v8js_array_access_enumerator(const v8::PropertyCallbackInfo<v8::Array>&
v8::Local<v8::Value> php_object = self->GetHiddenValue(V8JS_SYM(PHPJS_OBJECT_KEY)); 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 *object = reinterpret_cast<zval *>(v8::External::Cast(*php_object)->Value());
int length = php_v8js_array_access_get_count_result(object TSRMLS_CC); int length = v8js_array_access_get_count_result(object TSRMLS_CC);
v8::Local<v8::Array> result = v8::Array::New(isolate, length); v8::Local<v8::Array> result = v8::Array::New(isolate, length);
int i = 0; int i = 0;
for(int j = 0; j < length; j ++) { for(int j = 0; j < length; j ++) {
if(php_v8js_array_access_isset_p(object, j TSRMLS_CC)) { if(v8js_array_access_isset_p(object, j TSRMLS_CC)) {
result->Set(i ++, V8JS_INT(j)); result->Set(i ++, V8JS_INT(j));
} }
} }
@ -228,17 +228,17 @@ void php_v8js_array_access_enumerator(const v8::PropertyCallbackInfo<v8::Array>&
void php_v8js_array_access_named_getter(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value> &info) /* {{{ */ void v8js_array_access_named_getter(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value> &info) /* {{{ */
{ {
v8::String::Utf8Value cstr(property); v8::String::Utf8Value cstr(property);
const char *name = ToCString(cstr); const char *name = ToCString(cstr);
if(strcmp(name, "length") == 0) { if(strcmp(name, "length") == 0) {
php_v8js_array_access_length(property, info); v8js_array_access_length(property, info);
return; return;
} }
v8::Local<v8::Value> ret_value = php_v8js_named_property_callback(property, info, V8JS_PROP_GETTER); v8::Local<v8::Value> ret_value = v8js_named_property_callback(property, info, V8JS_PROP_GETTER);
if(ret_value.IsEmpty()) { if(ret_value.IsEmpty()) {
v8::Isolate *isolate = info.GetIsolate(); v8::Isolate *isolate = info.GetIsolate();

View File

@ -14,18 +14,18 @@
#define V8JS_ARRAY_ACCESS_H #define V8JS_ARRAY_ACCESS_H
/* Indexed Property Handlers */ /* Indexed Property Handlers */
void php_v8js_array_access_getter(uint32_t index, void v8js_array_access_getter(uint32_t index,
const v8::PropertyCallbackInfo<v8::Value>& info); const v8::PropertyCallbackInfo<v8::Value>& info);
void php_v8js_array_access_setter(uint32_t index, v8::Local<v8::Value> value, void v8js_array_access_setter(uint32_t index, v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<v8::Value>& info); const v8::PropertyCallbackInfo<v8::Value>& info);
void php_v8js_array_access_enumerator(const v8::PropertyCallbackInfo<v8::Array>& info); void v8js_array_access_enumerator(const v8::PropertyCallbackInfo<v8::Array>& info);
void php_v8js_array_access_deleter(uint32_t index, void v8js_array_access_deleter(uint32_t index,
const v8::PropertyCallbackInfo<v8::Boolean>& info); const v8::PropertyCallbackInfo<v8::Boolean>& info);
void php_v8js_array_access_query(uint32_t index, void v8js_array_access_query(uint32_t index,
const v8::PropertyCallbackInfo<v8::Integer>& info); const v8::PropertyCallbackInfo<v8::Integer>& info);
/* Named Property Handlers */ /* Named Property Handlers */
void php_v8js_array_access_named_getter(v8::Local<v8::String> property, void v8js_array_access_named_getter(v8::Local<v8::String> property,
const v8::PropertyCallbackInfo<v8::Value> &info); const v8::PropertyCallbackInfo<v8::Value> &info);
#endif /* V8JS_ARRAY_ACCESS_H */ #endif /* V8JS_ARRAY_ACCESS_H */

View File

@ -43,10 +43,18 @@ static zend_class_entry *php_ce_v8js;
static zend_object_handlers v8js_object_handlers; static zend_object_handlers v8js_object_handlers;
/* }}} */ /* }}} */
typedef struct _v8js_script {
char *name;
v8::Isolate *isolate;
v8::Persistent<v8::Script, v8::CopyablePersistentTraits<v8::Script>> *script;
} v8js_script;
static void v8js_script_free(v8js_script *res, bool dispose_persistent);
int le_v8js_script; int le_v8js_script;
/* {{{ Extension container */ /* {{{ Extension container */
struct php_v8js_jsext { struct v8js_jsext {
zend_bool auto_enable; zend_bool auto_enable;
HashTable *deps_ht; HashTable *deps_ht;
const char **deps; const char **deps;
@ -61,7 +69,7 @@ static v8js_ctx *v8js_debug_context;
static int v8js_debug_auto_break_mode; static int v8js_debug_auto_break_mode;
#endif #endif
static void php_v8js_free_storage(void *object TSRMLS_DC) /* {{{ */ static void v8js_free_storage(void *object TSRMLS_DC) /* {{{ */
{ {
v8js_ctx *c = (v8js_ctx *) object; v8js_ctx *c = (v8js_ctx *) object;
@ -161,7 +169,7 @@ static void php_v8js_free_storage(void *object TSRMLS_DC) /* {{{ */
} }
/* }}} */ /* }}} */
static zend_object_value php_v8js_new(zend_class_entry *ce TSRMLS_DC) /* {{{ */ static zend_object_value v8js_new(zend_class_entry *ce TSRMLS_DC) /* {{{ */
{ {
zend_object_value retval; zend_object_value retval;
v8js_ctx *c; v8js_ctx *c;
@ -194,14 +202,14 @@ static zend_object_value php_v8js_new(zend_class_entry *ce TSRMLS_DC) /* {{{ */
new(&c->v8js_v8objects) std::list<v8js_v8object *>(); new(&c->v8js_v8objects) std::list<v8js_v8object *>();
retval.handle = zend_objects_store_put(c, NULL, (zend_objects_free_object_storage_t) php_v8js_free_storage, NULL TSRMLS_CC); retval.handle = zend_objects_store_put(c, NULL, (zend_objects_free_object_storage_t) v8js_free_storage, NULL TSRMLS_CC);
retval.handlers = &v8js_object_handlers; retval.handlers = &v8js_object_handlers;
return retval; return retval;
} }
/* }}} */ /* }}} */
static void _php_v8js_free_ext_strarr(const char **arr, int count) /* {{{ */ static void v8js_free_ext_strarr(const char **arr, int count) /* {{{ */
{ {
int i; int i;
@ -216,21 +224,21 @@ static void _php_v8js_free_ext_strarr(const char **arr, int count) /* {{{ */
} }
/* }}} */ /* }}} */
static void php_v8js_jsext_dtor(php_v8js_jsext *jsext) /* {{{ */ static void v8js_jsext_dtor(v8js_jsext *jsext) /* {{{ */
{ {
if (jsext->deps_ht) { if (jsext->deps_ht) {
zend_hash_destroy(jsext->deps_ht); zend_hash_destroy(jsext->deps_ht);
free(jsext->deps_ht); free(jsext->deps_ht);
} }
if (jsext->deps) { if (jsext->deps) {
_php_v8js_free_ext_strarr(jsext->deps, jsext->deps_count); v8js_free_ext_strarr(jsext->deps, jsext->deps_count);
} }
free(jsext->name); free(jsext->name);
free(jsext->source); free(jsext->source);
} }
/* }}} */ /* }}} */
static int _php_v8js_create_ext_strarr(const char ***retval, int count, HashTable *ht) /* {{{ */ static int v8js_create_ext_strarr(const char ***retval, int count, HashTable *ht) /* {{{ */
{ {
const char **exts = NULL; const char **exts = NULL;
HashPosition pos; HashPosition pos;
@ -243,7 +251,7 @@ static int _php_v8js_create_ext_strarr(const char ***retval, int count, HashTabl
if (Z_TYPE_PP(tmp) == IS_STRING) { if (Z_TYPE_PP(tmp) == IS_STRING) {
exts[i++] = zend_strndup(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp)); exts[i++] = zend_strndup(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp));
} else { } else {
_php_v8js_free_ext_strarr(exts, i); v8js_free_ext_strarr(exts, i);
return FAILURE; return FAILURE;
} }
zend_hash_move_forward_ex(ht, &pos); zend_hash_move_forward_ex(ht, &pos);
@ -254,7 +262,7 @@ static int _php_v8js_create_ext_strarr(const char ***retval, int count, HashTabl
} }
/* }}} */ /* }}} */
static void php_v8js_fatal_error_handler(const char *location, const char *message) /* {{{ */ static void v8js_fatal_error_handler(const char *location, const char *message) /* {{{ */
{ {
v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::Isolate *isolate = v8::Isolate::GetCurrent();
if (isolate) { if (isolate) {
@ -332,7 +340,7 @@ static PHP_METHOD(V8Js, __construct)
if (exts_arr) if (exts_arr)
{ {
exts_count = zend_hash_num_elements(Z_ARRVAL_P(exts_arr)); exts_count = zend_hash_num_elements(Z_ARRVAL_P(exts_arr));
if (_php_v8js_create_ext_strarr(&exts, exts_count, Z_ARRVAL_P(exts_arr)) == FAILURE) { if (v8js_create_ext_strarr(&exts, exts_count, Z_ARRVAL_P(exts_arr)) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid extensions array passed"); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid extensions array passed");
return; return;
} }
@ -351,7 +359,7 @@ static PHP_METHOD(V8Js, __construct)
/* Redirect fatal errors to PHP error handler */ /* Redirect fatal errors to PHP error handler */
// This needs to be done within the context isolate // This needs to be done within the context isolate
v8::V8::SetFatalErrorHandler(php_v8js_fatal_error_handler); v8::V8::SetFatalErrorHandler(v8js_fatal_error_handler);
/* Create global template for global object */ /* Create global template for global object */
// Now we are using multiple isolates this needs to be created for every context // Now we are using multiple isolates this needs to be created for every context
@ -362,7 +370,7 @@ static PHP_METHOD(V8Js, __construct)
c->global_template.Reset(isolate, tpl); c->global_template.Reset(isolate, tpl);
/* Register builtin methods */ /* Register builtin methods */
php_v8js_register_methods(tpl->InstanceTemplate(), c); v8js_register_methods(tpl->InstanceTemplate(), c);
/* Create context */ /* Create context */
v8::Local<v8::Context> context = v8::Context::New(isolate, &extension_conf, tpl->InstanceTemplate()); v8::Local<v8::Context> context = v8::Context::New(isolate, &extension_conf, tpl->InstanceTemplate());
@ -370,7 +378,7 @@ static PHP_METHOD(V8Js, __construct)
c->context.Reset(isolate, context); c->context.Reset(isolate, context);
if (exts) { if (exts) {
_php_v8js_free_ext_strarr(exts, exts_count); v8js_free_ext_strarr(exts, exts_count);
} }
/* If extensions have errors, context will be empty. (NOTE: This is V8 stuff, they expect the passed sources to compile :) */ /* If extensions have errors, context will be empty. (NOTE: This is V8 stuff, they expect the passed sources to compile :) */
@ -400,7 +408,7 @@ static PHP_METHOD(V8Js, __construct)
/* Register Get accessor for passed variables */ /* Register Get accessor for passed variables */
if (vars_arr && zend_hash_num_elements(Z_ARRVAL_P(vars_arr)) > 0) { if (vars_arr && zend_hash_num_elements(Z_ARRVAL_P(vars_arr)) > 0) {
php_v8js_register_accessors(&c->accessor_list, php_obj_t, vars_arr, isolate TSRMLS_CC); v8js_register_accessors(&c->accessor_list, php_obj_t, vars_arr, isolate TSRMLS_CC);
} }
/* Set name for the PHP JS object */ /* Set name for the PHP JS object */
@ -461,7 +469,7 @@ PHP_METHOD(V8Js, __wakeup)
} }
/* }}} */ /* }}} */
static void php_v8js_compile_script(zval *this_ptr, const char *str, int str_len, const char *identifier, int identifier_len, v8js_script **ret TSRMLS_DC) static void v8js_compile_script(zval *this_ptr, const char *str, int str_len, const char *identifier, int identifier_len, v8js_script **ret TSRMLS_DC)
{ {
v8js_script *res = NULL; v8js_script *res = NULL;
@ -479,7 +487,7 @@ static void php_v8js_compile_script(zval *this_ptr, const char *str, int str_len
/* Compile errors? */ /* Compile errors? */
if (script.IsEmpty()) { if (script.IsEmpty()) {
php_v8js_throw_script_exception(&try_catch TSRMLS_CC); v8js_throw_script_exception(&try_catch TSRMLS_CC);
return; return;
} }
res = (v8js_script *)emalloc(sizeof(v8js_script)); res = (v8js_script *)emalloc(sizeof(v8js_script));
@ -492,7 +500,7 @@ static void php_v8js_compile_script(zval *this_ptr, const char *str, int str_len
return; return;
} }
static void php_v8js_execute_script(zval *this_ptr, v8js_script *res, long flags, long time_limit, long memory_limit, zval **return_value TSRMLS_DC) static void v8js_execute_script(zval *this_ptr, v8js_script *res, long flags, long time_limit, long memory_limit, zval **return_value TSRMLS_DC)
{ {
v8js_ctx *c = (v8js_ctx *) zend_object_store_get_object(getThis() TSRMLS_CC); v8js_ctx *c = (v8js_ctx *) zend_object_store_get_object(getThis() TSRMLS_CC);
@ -531,11 +539,11 @@ static PHP_METHOD(V8Js, executeString)
return; return;
} }
php_v8js_compile_script(getThis(), str, str_len, identifier, identifier_len, &res TSRMLS_CC); v8js_compile_script(getThis(), str, str_len, identifier, identifier_len, &res TSRMLS_CC);
if (!res) { if (!res) {
RETURN_FALSE; RETURN_FALSE;
} }
php_v8js_execute_script(getThis(), res, flags, time_limit, memory_limit, &return_value TSRMLS_CC); v8js_execute_script(getThis(), res, flags, time_limit, memory_limit, &return_value TSRMLS_CC);
v8js_script_free(res, true); v8js_script_free(res, true);
efree(res); efree(res);
} }
@ -554,7 +562,7 @@ static PHP_METHOD(V8Js, compileString)
return; return;
} }
php_v8js_compile_script(getThis(), str, str_len, identifier, identifier_len, &res TSRMLS_CC); v8js_compile_script(getThis(), str, str_len, identifier, identifier_len, &res TSRMLS_CC);
if (res) { if (res) {
ZEND_REGISTER_RESOURCE(return_value, res, le_v8js_script); ZEND_REGISTER_RESOURCE(return_value, res, le_v8js_script);
} }
@ -578,7 +586,7 @@ static PHP_METHOD(V8Js, executeScript)
ZEND_FETCH_RESOURCE(res, v8js_script*, &zscript, -1, PHP_V8JS_SCRIPT_RES_NAME, le_v8js_script); ZEND_FETCH_RESOURCE(res, v8js_script*, &zscript, -1, PHP_V8JS_SCRIPT_RES_NAME, le_v8js_script);
ZEND_VERIFY_RESOURCE(res); ZEND_VERIFY_RESOURCE(res);
php_v8js_execute_script(getThis(), res, flags, time_limit, memory_limit, &return_value TSRMLS_CC); v8js_execute_script(getThis(), res, flags, time_limit, memory_limit, &return_value TSRMLS_CC);
} }
/* }}} */ /* }}} */
@ -597,7 +605,7 @@ static PHP_METHOD(V8Js, checkString)
return; return;
} }
php_v8js_compile_script(getThis(), str, str_len, identifier, identifier_len, &res TSRMLS_CC); v8js_compile_script(getThis(), str, str_len, identifier, identifier_len, &res TSRMLS_CC);
if (!res) { if (!res) {
RETURN_FALSE; RETURN_FALSE;
} }
@ -798,7 +806,7 @@ static PHP_METHOD(V8Js, setMemoryLimit)
} }
/* }}} */ /* }}} */
static void php_v8js_persistent_zval_ctor(zval **p) /* {{{ */ static void v8js_persistent_zval_ctor(zval **p) /* {{{ */
{ {
zval *orig_ptr = *p; zval *orig_ptr = *p;
*p = (zval *) malloc(sizeof(zval)); *p = (zval *) malloc(sizeof(zval));
@ -814,7 +822,7 @@ static void php_v8js_persistent_zval_ctor(zval **p) /* {{{ */
} }
/* }}} */ /* }}} */
static void php_v8js_persistent_zval_dtor(zval **p) /* {{{ */ static void v8js_persistent_zval_dtor(zval **p) /* {{{ */
{ {
switch (Z_TYPE_P(*p)) { switch (Z_TYPE_P(*p)) {
case IS_STRING: case IS_STRING:
@ -849,25 +857,25 @@ static void v8js_script_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ */
} }
/* }}} */ /* }}} */
static int php_v8js_register_extension(char *name, uint name_len, char *source, uint source_len, zval *deps_arr, zend_bool auto_enable TSRMLS_DC) /* {{{ */ static int v8js_register_extension(char *name, uint name_len, char *source, uint source_len, zval *deps_arr, zend_bool auto_enable TSRMLS_DC) /* {{{ */
{ {
php_v8js_jsext *jsext = NULL; v8js_jsext *jsext = NULL;
if (!V8JSG(extensions)) { if (!V8JSG(extensions)) {
V8JSG(extensions) = (HashTable *) malloc(sizeof(HashTable)); V8JSG(extensions) = (HashTable *) malloc(sizeof(HashTable));
zend_hash_init(V8JSG(extensions), 1, NULL, (dtor_func_t) php_v8js_jsext_dtor, 1); zend_hash_init(V8JSG(extensions), 1, NULL, (dtor_func_t) v8js_jsext_dtor, 1);
} else if (zend_hash_exists(V8JSG(extensions), name, name_len + 1)) { } else if (zend_hash_exists(V8JSG(extensions), name, name_len + 1)) {
return FAILURE; return FAILURE;
} }
jsext = (php_v8js_jsext *) calloc(1, sizeof(php_v8js_jsext)); jsext = (v8js_jsext *) calloc(1, sizeof(v8js_jsext));
if (deps_arr) { if (deps_arr) {
jsext->deps_count = zend_hash_num_elements(Z_ARRVAL_P(deps_arr)); jsext->deps_count = zend_hash_num_elements(Z_ARRVAL_P(deps_arr));
if (_php_v8js_create_ext_strarr(&jsext->deps, jsext->deps_count, Z_ARRVAL_P(deps_arr)) == FAILURE) { if (v8js_create_ext_strarr(&jsext->deps, jsext->deps_count, Z_ARRVAL_P(deps_arr)) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid dependency array passed"); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid dependency array passed");
php_v8js_jsext_dtor(jsext); v8js_jsext_dtor(jsext);
free(jsext); free(jsext);
return FAILURE; return FAILURE;
} }
@ -879,12 +887,12 @@ static int php_v8js_register_extension(char *name, uint name_len, char *source,
if (jsext->deps) { if (jsext->deps) {
jsext->deps_ht = (HashTable *) malloc(sizeof(HashTable)); jsext->deps_ht = (HashTable *) malloc(sizeof(HashTable));
zend_hash_init(jsext->deps_ht, jsext->deps_count, NULL, (dtor_func_t) php_v8js_persistent_zval_dtor, 1); zend_hash_init(jsext->deps_ht, jsext->deps_count, NULL, (dtor_func_t) v8js_persistent_zval_dtor, 1);
zend_hash_copy(jsext->deps_ht, Z_ARRVAL_P(deps_arr), (copy_ctor_func_t) php_v8js_persistent_zval_ctor, NULL, sizeof(zval *)); zend_hash_copy(jsext->deps_ht, Z_ARRVAL_P(deps_arr), (copy_ctor_func_t) v8js_persistent_zval_ctor, NULL, sizeof(zval *));
} }
if (zend_hash_add(V8JSG(extensions), name, name_len + 1, jsext, sizeof(php_v8js_jsext), NULL) == FAILURE) { if (zend_hash_add(V8JSG(extensions), name, name_len + 1, jsext, sizeof(v8js_jsext), NULL) == FAILURE) {
php_v8js_jsext_dtor(jsext); v8js_jsext_dtor(jsext);
free(jsext); free(jsext);
return FAILURE; return FAILURE;
} }
@ -916,7 +924,7 @@ static PHP_METHOD(V8Js, registerExtension)
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Extension name cannot be empty"); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Extension name cannot be empty");
} else if (!script_len) { } else if (!script_len) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Script cannot be empty"); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Script cannot be empty");
} else if (php_v8js_register_extension(ext_name, ext_name_len, script, script_len, deps_arr, auto_enable TSRMLS_CC) == SUCCESS) { } else if (v8js_register_extension(ext_name, ext_name_len, script, script_len, deps_arr, auto_enable TSRMLS_CC) == SUCCESS) {
RETURN_TRUE; RETURN_TRUE;
} }
RETURN_FALSE; RETURN_FALSE;
@ -929,7 +937,7 @@ static PHP_METHOD(V8Js, registerExtension)
*/ */
static PHP_METHOD(V8Js, getExtensions) static PHP_METHOD(V8Js, getExtensions)
{ {
php_v8js_jsext *jsext; v8js_jsext *jsext;
zval *ext, *deps_arr; zval *ext, *deps_arr;
HashPosition pos; HashPosition pos;
ulong index; ulong index;
@ -1067,7 +1075,7 @@ static const zend_function_entry v8js_methods[] = { /* {{{ */
/* V8Js object handlers */ /* V8Js object handlers */
static void php_v8js_write_property(zval *object, zval *member, zval *value ZEND_HASH_KEY_DC TSRMLS_DC) /* {{{ */ static void v8js_write_property(zval *object, zval *member, zval *value ZEND_HASH_KEY_DC TSRMLS_DC) /* {{{ */
{ {
V8JS_BEGIN_CTX(c, object) V8JS_BEGIN_CTX(c, object)
@ -1087,7 +1095,7 @@ static void php_v8js_write_property(zval *object, zval *member, zval *value ZEND
} }
/* }}} */ /* }}} */
static void php_v8js_unset_property(zval *object, zval *member ZEND_HASH_KEY_DC TSRMLS_DC) /* {{{ */ static void v8js_unset_property(zval *object, zval *member ZEND_HASH_KEY_DC TSRMLS_DC) /* {{{ */
{ {
V8JS_BEGIN_CTX(c, object) V8JS_BEGIN_CTX(c, object)
@ -1110,13 +1118,13 @@ PHP_MINIT_FUNCTION(v8js_class) /* {{{ */
/* V8Js Class */ /* V8Js Class */
INIT_CLASS_ENTRY(ce, "V8Js", v8js_methods); INIT_CLASS_ENTRY(ce, "V8Js", v8js_methods);
php_ce_v8js = zend_register_internal_class(&ce TSRMLS_CC); php_ce_v8js = zend_register_internal_class(&ce TSRMLS_CC);
php_ce_v8js->create_object = php_v8js_new; php_ce_v8js->create_object = v8js_new;
/* V8Js handlers */ /* V8Js handlers */
memcpy(&v8js_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); memcpy(&v8js_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
v8js_object_handlers.clone_obj = NULL; v8js_object_handlers.clone_obj = NULL;
v8js_object_handlers.write_property = php_v8js_write_property; v8js_object_handlers.write_property = v8js_write_property;
v8js_object_handlers.unset_property = php_v8js_unset_property; v8js_object_handlers.unset_property = v8js_unset_property;
/* V8Js Class Constants */ /* V8Js Class Constants */
zend_declare_class_constant_string(php_ce_v8js, ZEND_STRL("V8_VERSION"), PHP_V8_VERSION TSRMLS_CC); zend_declare_class_constant_string(php_ce_v8js, ZEND_STRL("V8_VERSION"), PHP_V8_VERSION TSRMLS_CC);

View File

@ -22,7 +22,7 @@ extern "C" {
#include "php_v8js_macros.h" #include "php_v8js_macros.h"
void php_v8js_commonjs_split_terms(char *identifier, std::vector<char *> &terms) void v8js_commonjs_split_terms(char *identifier, std::vector<char *> &terms)
{ {
char *term = (char *)malloc(PATH_MAX), *ptr = term; char *term = (char *)malloc(PATH_MAX), *ptr = term;
@ -58,14 +58,14 @@ void php_v8js_commonjs_split_terms(char *identifier, std::vector<char *> &terms)
} }
} }
void php_v8js_commonjs_normalise_identifier(char *base, char *identifier, char *normalised_path, char *module_name) void v8js_commonjs_normalise_identifier(char *base, char *identifier, char *normalised_path, char *module_name)
{ {
std::vector<char *> id_terms, terms; std::vector<char *> id_terms, terms;
php_v8js_commonjs_split_terms(identifier, id_terms); v8js_commonjs_split_terms(identifier, id_terms);
// If we have a relative module identifier then include the base terms // If we have a relative module identifier then include the base terms
if (!strcmp(id_terms.front(), ".") || !strcmp(id_terms.front(), "..")) { if (!strcmp(id_terms.front(), ".") || !strcmp(id_terms.front(), "..")) {
php_v8js_commonjs_split_terms(base, terms); v8js_commonjs_split_terms(base, terms);
} }
terms.insert(terms.end(), id_terms.begin(), id_terms.end()); terms.insert(terms.end(), id_terms.begin(), id_terms.end());

View File

@ -31,7 +31,7 @@ extern "C" {
#include <stdexcept> #include <stdexcept>
#include <limits> #include <limits>
static int _php_v8js_is_assoc_array(HashTable *myht TSRMLS_DC) /* {{{ */ static int v8js_is_assoc_array(HashTable *myht TSRMLS_DC) /* {{{ */
{ {
int i; int i;
char *key; char *key;
@ -54,14 +54,14 @@ static int _php_v8js_is_assoc_array(HashTable *myht TSRMLS_DC) /* {{{ */
/* }}} */ /* }}} */
static v8::Handle<v8::Value> php_v8js_hash_to_jsarr(zval *value, v8::Isolate *isolate TSRMLS_DC) /* {{{ */ static v8::Handle<v8::Value> v8js_hash_to_jsarr(zval *value, v8::Isolate *isolate TSRMLS_DC) /* {{{ */
{ {
HashTable *myht = HASH_OF(value); HashTable *myht = HASH_OF(value);
int i = myht ? zend_hash_num_elements(myht) : 0; int i = myht ? zend_hash_num_elements(myht) : 0;
/* Return object if dealing with assoc array */ /* Return object if dealing with assoc array */
if (i > 0 && _php_v8js_is_assoc_array(myht TSRMLS_CC)) { if (i > 0 && v8js_is_assoc_array(myht TSRMLS_CC)) {
return php_v8js_hash_to_jsobj(value, isolate TSRMLS_CC); return v8js_hash_to_jsobj(value, isolate TSRMLS_CC);
} }
v8::Local<v8::Array> newarr; v8::Local<v8::Array> newarr;
@ -110,7 +110,7 @@ v8::Handle<v8::Value> zval_to_v8js(zval *value, v8::Isolate *isolate TSRMLS_DC)
switch (Z_TYPE_P(value)) switch (Z_TYPE_P(value))
{ {
case IS_ARRAY: case IS_ARRAY:
jsValue = php_v8js_hash_to_jsarr(value, isolate TSRMLS_CC); jsValue = v8js_hash_to_jsarr(value, isolate TSRMLS_CC);
break; break;
case IS_OBJECT: case IS_OBJECT:
@ -126,9 +126,9 @@ v8::Handle<v8::Value> zval_to_v8js(zval *value, v8::Isolate *isolate TSRMLS_DC)
else else
jsValue = V8JS_NULL; jsValue = V8JS_NULL;
} else } else
jsValue = php_v8js_hash_to_jsobj(value, isolate TSRMLS_CC); jsValue = v8js_hash_to_jsobj(value, isolate TSRMLS_CC);
} else } else
jsValue = php_v8js_hash_to_jsobj(value, isolate TSRMLS_CC); jsValue = v8js_hash_to_jsobj(value, isolate TSRMLS_CC);
break; break;
case IS_STRING: case IS_STRING:

View File

@ -38,7 +38,7 @@ zend_class_entry *php_ce_v8js_memory_limit_exception;
/* {{{ Class: V8JsScriptException */ /* {{{ Class: V8JsScriptException */
void php_v8js_create_script_exception(zval *return_value, v8::TryCatch *try_catch TSRMLS_DC) /* {{{ */ void v8js_create_script_exception(zval *return_value, v8::TryCatch *try_catch TSRMLS_DC) /* {{{ */
{ {
v8::String::Utf8Value exception(try_catch->Exception()); v8::String::Utf8Value exception(try_catch->Exception());
const char *exception_string = ToCString(exception); const char *exception_string = ToCString(exception);
@ -89,7 +89,7 @@ void php_v8js_create_script_exception(zval *return_value, v8::TryCatch *try_catc
} }
/* }}} */ /* }}} */
void php_v8js_throw_script_exception(v8::TryCatch *try_catch TSRMLS_DC) /* {{{ */ void v8js_throw_script_exception(v8::TryCatch *try_catch TSRMLS_DC) /* {{{ */
{ {
v8::String::Utf8Value exception(try_catch->Exception()); v8::String::Utf8Value exception(try_catch->Exception());
const char *exception_string = ToCString(exception); const char *exception_string = ToCString(exception);
@ -99,7 +99,7 @@ void php_v8js_throw_script_exception(v8::TryCatch *try_catch TSRMLS_DC) /* {{{ *
zend_throw_exception(php_ce_v8js_script_exception, (char *) exception_string, 0 TSRMLS_CC); zend_throw_exception(php_ce_v8js_script_exception, (char *) exception_string, 0 TSRMLS_CC);
} else { } else {
MAKE_STD_ZVAL(zexception); MAKE_STD_ZVAL(zexception);
php_v8js_create_script_exception(zexception, try_catch TSRMLS_CC); v8js_create_script_exception(zexception, try_catch TSRMLS_CC);
zend_throw_exception_object(zexception TSRMLS_CC); zend_throw_exception_object(zexception TSRMLS_CC);
} }
} }

View File

@ -19,8 +19,8 @@ extern zend_class_entry *php_ce_v8js_script_exception;
extern zend_class_entry *php_ce_v8js_time_limit_exception; extern zend_class_entry *php_ce_v8js_time_limit_exception;
extern zend_class_entry *php_ce_v8js_memory_limit_exception; extern zend_class_entry *php_ce_v8js_memory_limit_exception;
void php_v8js_create_script_exception(zval *return_value, v8::TryCatch *try_catch TSRMLS_DC); void v8js_create_script_exception(zval *return_value, v8::TryCatch *try_catch TSRMLS_DC);
void php_v8js_throw_script_exception(v8::TryCatch *try_catch TSRMLS_DC); void v8js_throw_script_exception(v8::TryCatch *try_catch TSRMLS_DC);
PHP_MINIT_FUNCTION(v8js_exceptions); PHP_MINIT_FUNCTION(v8js_exceptions);

View File

@ -22,7 +22,7 @@ extern "C" {
} }
/* Forward declarations */ /* Forward declarations */
void php_v8js_commonjs_normalise_identifier(char *base, char *identifier, char *normalised_path, char *module_name); void v8js_commonjs_normalise_identifier(char *base, char *identifier, char *normalised_path, char *module_name);
/* global.exit - terminate execution */ /* global.exit - terminate execution */
V8JS_METHOD(exit) /* {{{ */ V8JS_METHOD(exit) /* {{{ */
@ -54,7 +54,7 @@ V8JS_METHOD(print) /* {{{ */
} }
/* }}} */ /* }}} */
static void _php_v8js_dumper(v8::Isolate *isolate, v8::Local<v8::Value> var, int level TSRMLS_DC) /* {{{ */ static void v8js_dumper(v8::Isolate *isolate, v8::Local<v8::Value> var, int level TSRMLS_DC) /* {{{ */
{ {
if (level > 1) { if (level > 1) {
php_printf("%*c", (level - 1) * 2, ' '); php_printf("%*c", (level - 1) * 2, ' ');
@ -124,7 +124,7 @@ static void _php_v8js_dumper(v8::Isolate *isolate, v8::Local<v8::Value> var, int
for (unsigned i = 0; i < length; i++) { for (unsigned i = 0; i < length; i++) {
php_printf("%*c[%d] =>\n", level * 2, ' ', i); php_printf("%*c[%d] =>\n", level * 2, ' ', i);
_php_v8js_dumper(isolate, array->Get(i), level + 1 TSRMLS_CC); v8js_dumper(isolate, array->Get(i), level + 1 TSRMLS_CC);
} }
if (level > 1) { if (level > 1) {
@ -161,7 +161,7 @@ static void _php_v8js_dumper(v8::Isolate *isolate, v8::Local<v8::Value> var, int
v8::Local<v8::String> key = keys->Get(i)->ToString(); v8::Local<v8::String> key = keys->Get(i)->ToString();
v8::String::Utf8Value kname(key); v8::String::Utf8Value kname(key);
php_printf("%*c[\"%s\"] =>\n", level * 2, ' ', ToCString(kname)); php_printf("%*c[\"%s\"] =>\n", level * 2, ' ', ToCString(kname));
_php_v8js_dumper(isolate, object->Get(key), level + 1 TSRMLS_CC); v8js_dumper(isolate, object->Get(key), level + 1 TSRMLS_CC);
} }
} }
@ -185,7 +185,7 @@ V8JS_METHOD(var_dump) /* {{{ */
V8JS_TSRMLS_FETCH(); V8JS_TSRMLS_FETCH();
for (int i = 0; i < info.Length(); i++) { for (int i = 0; i < info.Length(); i++) {
_php_v8js_dumper(isolate, info[i], 1 TSRMLS_CC); v8js_dumper(isolate, info[i], 1 TSRMLS_CC);
} }
info.GetReturnValue().Set(V8JS_NULL); info.GetReturnValue().Set(V8JS_NULL);
@ -214,7 +214,7 @@ V8JS_METHOD(require)
char *normalised_path = (char *)emalloc(PATH_MAX); char *normalised_path = (char *)emalloc(PATH_MAX);
char *module_name = (char *)emalloc(PATH_MAX); char *module_name = (char *)emalloc(PATH_MAX);
php_v8js_commonjs_normalise_identifier(c->modules_base.back(), module_id, normalised_path, module_name); v8js_commonjs_normalise_identifier(c->modules_base.back(), module_id, normalised_path, module_name);
efree(module_id); efree(module_id);
char *normalised_module_id = (char *)emalloc(strlen(normalised_path)+1+strlen(module_name)+1); char *normalised_module_id = (char *)emalloc(strlen(normalised_path)+1+strlen(module_name)+1);
@ -389,7 +389,7 @@ V8JS_METHOD(require)
efree(normalised_module_id); efree(normalised_module_id);
} }
void php_v8js_register_methods(v8::Handle<v8::ObjectTemplate> global, v8js_ctx *c) /* {{{ */ void v8js_register_methods(v8::Handle<v8::ObjectTemplate> global, v8js_ctx *c) /* {{{ */
{ {
v8::Isolate *isolate = c->isolate; v8::Isolate *isolate = c->isolate;
global->Set(V8JS_SYM("exit"), v8::FunctionTemplate::New(isolate, V8JS_MN(exit)), v8::ReadOnly); global->Set(V8JS_SYM("exit"), v8::FunctionTemplate::New(isolate, V8JS_MN(exit)), v8::ReadOnly);

View File

@ -28,10 +28,10 @@ extern "C" {
#include "v8js_object_export.h" #include "v8js_object_export.h"
#include "v8js_v8object_class.h" #include "v8js_v8object_class.h"
static void php_v8js_weak_object_callback(const v8::WeakCallbackData<v8::Object, zval> &data); static void v8js_weak_object_callback(const v8::WeakCallbackData<v8::Object, zval> &data);
/* Callback for PHP methods and functions */ /* Callback for PHP methods and functions */
static void php_v8js_call_php_func(zval *value, zend_class_entry *ce, zend_function *method_ptr, v8::Isolate *isolate, const v8::FunctionCallbackInfo<v8::Value>& info TSRMLS_DC) /* {{{ */ static void v8js_call_php_func(zval *value, zend_class_entry *ce, zend_function *method_ptr, v8::Isolate *isolate, const v8::FunctionCallbackInfo<v8::Value>& info TSRMLS_DC) /* {{{ */
{ {
v8::Handle<v8::Value> return_value; v8::Handle<v8::Value> return_value;
zend_fcall_info fci; zend_fcall_info fci;
@ -161,7 +161,7 @@ failure:
/* }}} */ /* }}} */
/* Callback for PHP methods and functions */ /* Callback for PHP methods and functions */
static void php_v8js_php_callback(const v8::FunctionCallbackInfo<v8::Value>& info) /* {{{ */ static void v8js_php_callback(const v8::FunctionCallbackInfo<v8::Value>& info) /* {{{ */
{ {
v8::Isolate *isolate = info.GetIsolate(); v8::Isolate *isolate = info.GetIsolate();
v8::Local<v8::Object> self = info.Holder(); v8::Local<v8::Object> self = info.Holder();
@ -178,11 +178,11 @@ static void php_v8js_php_callback(const v8::FunctionCallbackInfo<v8::Value>& inf
method_ptr = zend_get_closure_invoke_method(value TSRMLS_CC); method_ptr = zend_get_closure_invoke_method(value TSRMLS_CC);
} }
return php_v8js_call_php_func(value, ce, method_ptr, isolate, info TSRMLS_CC); return v8js_call_php_func(value, ce, method_ptr, isolate, info TSRMLS_CC);
} }
/* Callback for PHP constructor calls */ /* Callback for PHP constructor calls */
static void php_v8js_construct_callback(const v8::FunctionCallbackInfo<v8::Value>& info) /* {{{ */ static void v8js_construct_callback(const v8::FunctionCallbackInfo<v8::Value>& info) /* {{{ */
{ {
v8::Isolate *isolate = info.GetIsolate(); v8::Isolate *isolate = info.GetIsolate();
info.GetReturnValue().Set(V8JS_UNDEFINED); info.GetReturnValue().Set(V8JS_UNDEFINED);
@ -203,7 +203,7 @@ static void php_v8js_construct_callback(const v8::FunctionCallbackInfo<v8::Value
v8js_ctx *ctx = (v8js_ctx *) isolate->GetData(0); v8js_ctx *ctx = (v8js_ctx *) isolate->GetData(0);
if (info[0]->IsExternal()) { if (info[0]->IsExternal()) {
// Object created by v8js in php_v8js_hash_to_jsobj, PHP object passed as v8::External. // Object created by v8js in v8js_hash_to_jsobj, PHP object passed as v8::External.
php_object = v8::Local<v8::External>::Cast(info[0]); php_object = v8::Local<v8::External>::Cast(info[0]);
value = reinterpret_cast<zval *>(php_object->Value()); value = reinterpret_cast<zval *>(php_object->Value());
@ -235,7 +235,7 @@ static void php_v8js_construct_callback(const v8::FunctionCallbackInfo<v8::Value
// Call __construct function // Call __construct function
if (ctor_ptr != NULL) { if (ctor_ptr != NULL) {
php_v8js_call_php_func(value, ce, ctor_ptr, isolate, info TSRMLS_CC); v8js_call_php_func(value, ce, ctor_ptr, isolate, info TSRMLS_CC);
} }
php_object = v8::External::New(isolate, value); php_object = v8::External::New(isolate, value);
} }
@ -247,7 +247,7 @@ static void php_v8js_construct_callback(const v8::FunctionCallbackInfo<v8::Value
// decides to dispose the JS object, we add a weak persistent handle and register // decides to dispose the JS object, we add a weak persistent handle and register
// a callback function that removes the reference. // a callback function that removes the reference.
ctx->weak_objects[value].Reset(isolate, newobj); ctx->weak_objects[value].Reset(isolate, newobj);
ctx->weak_objects[value].SetWeak(value, php_v8js_weak_object_callback); ctx->weak_objects[value].SetWeak(value, v8js_weak_object_callback);
// Just tell v8 that we're allocating some external memory // Just tell v8 that we're allocating some external memory
// (for the moment we just always tell 1k instead of trying to find out actual values) // (for the moment we just always tell 1k instead of trying to find out actual values)
@ -256,7 +256,7 @@ static void php_v8js_construct_callback(const v8::FunctionCallbackInfo<v8::Value
/* }}} */ /* }}} */
static void php_v8js_weak_object_callback(const v8::WeakCallbackData<v8::Object, zval> &data) { static void v8js_weak_object_callback(const v8::WeakCallbackData<v8::Object, zval> &data) {
v8::Isolate *isolate = data.GetIsolate(); v8::Isolate *isolate = data.GetIsolate();
zval *value = data.GetParameter(); zval *value = data.GetParameter();
@ -270,7 +270,7 @@ static void php_v8js_weak_object_callback(const v8::WeakCallbackData<v8::Object,
isolate->AdjustAmountOfExternalAllocatedMemory(-1024); isolate->AdjustAmountOfExternalAllocatedMemory(-1024);
} }
static void php_v8js_weak_closure_callback(const v8::WeakCallbackData<v8::Object, v8js_tmpl_t> &data) { static void v8js_weak_closure_callback(const v8::WeakCallbackData<v8::Object, v8js_tmpl_t> &data) {
v8::Isolate *isolate = data.GetIsolate(); v8::Isolate *isolate = data.GetIsolate();
v8js_tmpl_t *persist_tpl_ = data.GetParameter(); v8js_tmpl_t *persist_tpl_ = data.GetParameter();
@ -293,10 +293,10 @@ static void php_v8js_weak_closure_callback(const v8::WeakCallbackData<v8::Object
!strncasecmp(key, mname, key_len - 1)) !strncasecmp(key, mname, key_len - 1))
#define PHP_V8JS_CALLBACK(isolate, mptr, tmpl) \ #define PHP_V8JS_CALLBACK(isolate, mptr, tmpl) \
v8::FunctionTemplate::New((isolate), php_v8js_php_callback, v8::External::New((isolate), mptr), v8::Signature::New((isolate), tmpl))->GetFunction() v8::FunctionTemplate::New((isolate), v8js_php_callback, v8::External::New((isolate), mptr), v8::Signature::New((isolate), tmpl))->GetFunction()
static void php_v8js_named_property_enumerator(const v8::PropertyCallbackInfo<v8::Array> &info) /* {{{ */ static void v8js_named_property_enumerator(const v8::PropertyCallbackInfo<v8::Array> &info) /* {{{ */
{ {
// note: 'special' properties like 'constructor' are not enumerated. // note: 'special' properties like 'constructor' are not enumerated.
v8::Isolate *isolate = info.GetIsolate(); v8::Isolate *isolate = info.GetIsolate();
@ -393,7 +393,7 @@ static void php_v8js_named_property_enumerator(const v8::PropertyCallbackInfo<v8
} }
/* }}} */ /* }}} */
static void php_v8js_invoke_callback(const v8::FunctionCallbackInfo<v8::Value>& info) /* {{{ */ static void v8js_invoke_callback(const v8::FunctionCallbackInfo<v8::Value>& info) /* {{{ */
{ {
v8::Isolate *isolate = info.GetIsolate(); v8::Isolate *isolate = info.GetIsolate();
v8::Local<v8::Object> self = info.Holder(); v8::Local<v8::Object> self = info.Holder();
@ -432,7 +432,7 @@ static void php_v8js_invoke_callback(const v8::FunctionCallbackInfo<v8::Value>&
// this is a magic '__call' implementation for PHP classes which don't actually // this is a magic '__call' implementation for PHP classes which don't actually
// have a '__call' magic function. This way we can always force a method // have a '__call' magic function. This way we can always force a method
// call (as opposed to a property get) from JavaScript using __call. // call (as opposed to a property get) from JavaScript using __call.
static void php_v8js_fake_call_impl(const v8::FunctionCallbackInfo<v8::Value>& info) /* {{{ */ static void v8js_fake_call_impl(const v8::FunctionCallbackInfo<v8::Value>& info) /* {{{ */
{ {
v8::Isolate *isolate = info.GetIsolate(); v8::Isolate *isolate = info.GetIsolate();
v8::Local<v8::Object> self = info.Holder(); v8::Local<v8::Object> self = info.Holder();
@ -500,7 +500,7 @@ static void php_v8js_fake_call_impl(const v8::FunctionCallbackInfo<v8::Value>& i
v8::Local<v8::FunctionTemplate> tmpl = v8::Local<v8::FunctionTemplate> tmpl =
v8::Local<v8::FunctionTemplate>::New v8::Local<v8::FunctionTemplate>::New
(isolate, *reinterpret_cast<v8js_tmpl_t *>(self->GetAlignedPointerFromInternalField(0))); (isolate, *reinterpret_cast<v8js_tmpl_t *>(self->GetAlignedPointerFromInternalField(0)));
// use php_v8js_php_callback to actually execute the method // use v8js_php_callback to actually execute the method
v8::Local<v8::Function> cb = PHP_V8JS_CALLBACK(isolate, method_ptr, tmpl); v8::Local<v8::Function> cb = PHP_V8JS_CALLBACK(isolate, method_ptr, tmpl);
uint32_t i, argc = args->Length(); uint32_t i, argc = args->Length();
v8::Local<v8::Value> *argv = static_cast<v8::Local<v8::Value> *>(alloca(sizeof(v8::Local<v8::Value>) * argc)); v8::Local<v8::Value> *argv = static_cast<v8::Local<v8::Value> *>(alloca(sizeof(v8::Local<v8::Value>) * argc));
@ -515,7 +515,7 @@ static void php_v8js_fake_call_impl(const v8::FunctionCallbackInfo<v8::Value>& i
/* This method handles named property and method get/set/query/delete. */ /* This method handles named property and method get/set/query/delete. */
template<typename T> template<typename T>
inline v8::Local<v8::Value> php_v8js_named_property_callback(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<T> &info, property_op_t callback_type, v8::Local<v8::Value> set_value) /* {{{ */ inline v8::Local<v8::Value> v8js_named_property_callback(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<T> &info, property_op_t callback_type, v8::Local<v8::Value> set_value) /* {{{ */
{ {
v8::Isolate *isolate = info.GetIsolate(); v8::Isolate *isolate = info.GetIsolate();
v8::String::Utf8Value cstr(property); v8::String::Utf8Value cstr(property);
@ -570,7 +570,7 @@ inline v8::Local<v8::Value> php_v8js_named_property_callback(v8::Local<v8::Strin
// there is no actual PHP __call() implementation) // there is no actual PHP __call() implementation)
v8::Local<v8::Function> cb = v8::Local<v8::Function> cb =
v8::FunctionTemplate::New(isolate, v8::FunctionTemplate::New(isolate,
php_v8js_fake_call_impl, V8JS_NULL, v8js_fake_call_impl, V8JS_NULL,
v8::Signature::New(isolate, tmpl))->GetFunction(); v8::Signature::New(isolate, tmpl))->GetFunction();
cb->SetName(property); cb->SetName(property);
ret_value = cb; ret_value = cb;
@ -735,30 +735,30 @@ inline v8::Local<v8::Value> php_v8js_named_property_callback(v8::Local<v8::Strin
} }
/* }}} */ /* }}} */
static void php_v8js_named_property_getter(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value> &info) /* {{{ */ static void v8js_named_property_getter(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value> &info) /* {{{ */
{ {
info.GetReturnValue().Set(php_v8js_named_property_callback(property, info, V8JS_PROP_GETTER)); info.GetReturnValue().Set(v8js_named_property_callback(property, info, V8JS_PROP_GETTER));
} }
/* }}} */ /* }}} */
static void php_v8js_named_property_setter(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value> &info) /* {{{ */ static void v8js_named_property_setter(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value> &info) /* {{{ */
{ {
info.GetReturnValue().Set(php_v8js_named_property_callback(property, info, V8JS_PROP_SETTER, value)); info.GetReturnValue().Set(v8js_named_property_callback(property, info, V8JS_PROP_SETTER, value));
} }
/* }}} */ /* }}} */
static void php_v8js_named_property_query(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Integer> &info) /* {{{ */ static void v8js_named_property_query(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Integer> &info) /* {{{ */
{ {
v8::Local<v8::Value> r = php_v8js_named_property_callback(property, info, V8JS_PROP_QUERY); v8::Local<v8::Value> r = v8js_named_property_callback(property, info, V8JS_PROP_QUERY);
if (!r.IsEmpty()) { if (!r.IsEmpty()) {
info.GetReturnValue().Set(r->ToInteger()); info.GetReturnValue().Set(r->ToInteger());
} }
} }
/* }}} */ /* }}} */
static void php_v8js_named_property_deleter(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Boolean> &info) /* {{{ */ static void v8js_named_property_deleter(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Boolean> &info) /* {{{ */
{ {
v8::Local<v8::Value> r = php_v8js_named_property_callback(property, info, V8JS_PROP_DELETER); v8::Local<v8::Value> r = v8js_named_property_callback(property, info, V8JS_PROP_DELETER);
if (!r.IsEmpty()) { if (!r.IsEmpty()) {
info.GetReturnValue().Set(r->ToBoolean()); info.GetReturnValue().Set(r->ToBoolean());
} }
@ -767,7 +767,7 @@ static void php_v8js_named_property_deleter(v8::Local<v8::String> property, cons
static v8::Handle<v8::Object> php_v8js_wrap_object(v8::Isolate *isolate, zend_class_entry *ce, zval *value TSRMLS_DC) /* {{{ */ static v8::Handle<v8::Object> v8js_wrap_object(v8::Isolate *isolate, zend_class_entry *ce, zval *value TSRMLS_DC) /* {{{ */
{ {
v8js_ctx *ctx = (v8js_ctx *) isolate->GetData(0); v8js_ctx *ctx = (v8js_ctx *) isolate->GetData(0);
v8::Local<v8::FunctionTemplate> new_tpl; v8::Local<v8::FunctionTemplate> new_tpl;
@ -787,8 +787,8 @@ static v8::Handle<v8::Object> php_v8js_wrap_object(v8::Isolate *isolate, zend_cl
if (ce == zend_ce_closure) { if (ce == zend_ce_closure) {
/* Got a closure, mustn't cache ... */ /* Got a closure, mustn't cache ... */
persist_tpl_ = new v8js_tmpl_t(isolate, new_tpl); persist_tpl_ = new v8js_tmpl_t(isolate, new_tpl);
/* We'll free persist_tpl_ via php_v8js_weak_closure_callback, below */ /* We'll free persist_tpl_ via v8js_weak_closure_callback, below */
new_tpl->InstanceTemplate()->SetCallAsFunctionHandler(php_v8js_php_callback); new_tpl->InstanceTemplate()->SetCallAsFunctionHandler(v8js_php_callback);
} else { } else {
/* Add new v8::FunctionTemplate to tpl_map, as long as it is not a closure. */ /* Add new v8::FunctionTemplate to tpl_map, as long as it is not a closure. */
persist_tpl_ = &ctx->template_cache[ce->name]; persist_tpl_ = &ctx->template_cache[ce->name];
@ -796,8 +796,8 @@ static v8::Handle<v8::Object> php_v8js_wrap_object(v8::Isolate *isolate, zend_cl
/* We'll free persist_tpl_ when template_cache is destroyed */ /* We'll free persist_tpl_ when template_cache is destroyed */
v8::Local<v8::ObjectTemplate> inst_tpl = new_tpl->InstanceTemplate(); v8::Local<v8::ObjectTemplate> inst_tpl = new_tpl->InstanceTemplate();
v8::NamedPropertyGetterCallback getter = php_v8js_named_property_getter; v8::NamedPropertyGetterCallback getter = v8js_named_property_getter;
v8::NamedPropertyEnumeratorCallback enumerator = php_v8js_named_property_enumerator; v8::NamedPropertyEnumeratorCallback enumerator = v8js_named_property_enumerator;
/* Check for ArrayAccess object */ /* Check for ArrayAccess object */
if (V8JSG(use_array_access) && ce) { if (V8JSG(use_array_access) && ce) {
@ -814,16 +814,16 @@ static v8::Handle<v8::Object> php_v8js_wrap_object(v8::Isolate *isolate, zend_cl
} }
if(has_array_access && has_countable) { if(has_array_access && has_countable) {
inst_tpl->SetIndexedPropertyHandler(php_v8js_array_access_getter, inst_tpl->SetIndexedPropertyHandler(v8js_array_access_getter,
php_v8js_array_access_setter, v8js_array_access_setter,
php_v8js_array_access_query, v8js_array_access_query,
php_v8js_array_access_deleter, v8js_array_access_deleter,
php_v8js_array_access_enumerator); v8js_array_access_enumerator);
/* Switch to special ArrayAccess getter, which falls back to /* Switch to special ArrayAccess getter, which falls back to
* php_v8js_named_property_getter, but possibly bridges the * v8js_named_property_getter, but possibly bridges the
* call to Array.prototype functions. */ * call to Array.prototype functions. */
getter = php_v8js_array_access_named_getter; getter = v8js_array_access_named_getter;
/* Overwrite enumerator, since for(... in ...) loop should /* Overwrite enumerator, since for(... in ...) loop should
* not see the methods but iterate over the elements. */ * not see the methods but iterate over the elements. */
@ -835,9 +835,9 @@ static v8::Handle<v8::Object> php_v8js_wrap_object(v8::Isolate *isolate, zend_cl
// Finish setup of new_tpl // Finish setup of new_tpl
inst_tpl->SetNamedPropertyHandler inst_tpl->SetNamedPropertyHandler
(getter, /* getter */ (getter, /* getter */
php_v8js_named_property_setter, /* setter */ v8js_named_property_setter, /* setter */
php_v8js_named_property_query, /* query */ v8js_named_property_query, /* query */
php_v8js_named_property_deleter, /* deleter */ v8js_named_property_deleter, /* deleter */
enumerator, /* enumerator */ enumerator, /* enumerator */
V8JS_NULL /* data */ V8JS_NULL /* data */
); );
@ -847,13 +847,13 @@ static v8::Handle<v8::Object> php_v8js_wrap_object(v8::Isolate *isolate, zend_cl
sizeof(ZEND_INVOKE_FUNC_NAME), sizeof(ZEND_INVOKE_FUNC_NAME),
(void**)&invoke_method_ptr) == SUCCESS && (void**)&invoke_method_ptr) == SUCCESS &&
invoke_method_ptr->common.fn_flags & ZEND_ACC_PUBLIC) { invoke_method_ptr->common.fn_flags & ZEND_ACC_PUBLIC) {
new_tpl->InstanceTemplate()->SetCallAsFunctionHandler(php_v8js_invoke_callback, PHP_V8JS_CALLBACK(isolate, invoke_method_ptr, new_tpl)); new_tpl->InstanceTemplate()->SetCallAsFunctionHandler(v8js_invoke_callback, PHP_V8JS_CALLBACK(isolate, invoke_method_ptr, new_tpl));
} }
} }
v8::Local<v8::Array> call_handler_data = v8::Array::New(isolate, 2); v8::Local<v8::Array> call_handler_data = v8::Array::New(isolate, 2);
call_handler_data->Set(0, v8::External::New(isolate, persist_tpl_)); call_handler_data->Set(0, v8::External::New(isolate, persist_tpl_));
call_handler_data->Set(1, v8::External::New(isolate, ce)); call_handler_data->Set(1, v8::External::New(isolate, ce));
new_tpl->SetCallHandler(php_v8js_construct_callback, call_handler_data); new_tpl->SetCallHandler(v8js_construct_callback, call_handler_data);
} }
// Create v8 wrapper object // Create v8 wrapper object
@ -863,7 +863,7 @@ static v8::Handle<v8::Object> php_v8js_wrap_object(v8::Isolate *isolate, zend_cl
if (ce == zend_ce_closure) { if (ce == zend_ce_closure) {
// free uncached function template when object is freed // free uncached function template when object is freed
ctx->weak_closures[persist_tpl_].Reset(isolate, newobj); ctx->weak_closures[persist_tpl_].Reset(isolate, newobj);
ctx->weak_closures[persist_tpl_].SetWeak(persist_tpl_, php_v8js_weak_closure_callback); ctx->weak_closures[persist_tpl_].SetWeak(persist_tpl_, v8js_weak_closure_callback);
} }
return newobj; return newobj;
@ -871,7 +871,7 @@ static v8::Handle<v8::Object> php_v8js_wrap_object(v8::Isolate *isolate, zend_cl
/* }}} */ /* }}} */
static v8::Handle<v8::Object> php_v8js_wrap_array_to_object(v8::Isolate *isolate, zval *value TSRMLS_DC) /* {{{ */ static v8::Handle<v8::Object> v8js_wrap_array_to_object(v8::Isolate *isolate, zval *value TSRMLS_DC) /* {{{ */
{ {
int i; int i;
HashPosition pos; HashPosition pos;
@ -936,7 +936,7 @@ static v8::Handle<v8::Object> php_v8js_wrap_array_to_object(v8::Isolate *isolate
/* }}} */ /* }}} */
v8::Handle<v8::Value> php_v8js_hash_to_jsobj(zval *value, v8::Isolate *isolate TSRMLS_DC) /* {{{ */ v8::Handle<v8::Value> v8js_hash_to_jsobj(zval *value, v8::Isolate *isolate TSRMLS_DC) /* {{{ */
{ {
HashTable *myht; HashTable *myht;
zend_class_entry *ce = NULL; zend_class_entry *ce = NULL;
@ -967,12 +967,12 @@ v8::Handle<v8::Value> php_v8js_hash_to_jsobj(zval *value, v8::Isolate *isolate T
/* If it's a PHP object, wrap it */ /* If it's a PHP object, wrap it */
if (ce) { if (ce) {
return php_v8js_wrap_object(isolate, ce, value TSRMLS_CC); return v8js_wrap_object(isolate, ce, value TSRMLS_CC);
} }
/* Associative PHP arrays cannot be wrapped to JS arrays, convert them to /* Associative PHP arrays cannot be wrapped to JS arrays, convert them to
* JS objects and attach all their array keys as properties. */ * JS objects and attach all their array keys as properties. */
return php_v8js_wrap_array_to_object(isolate, value TSRMLS_CC); return v8js_wrap_array_to_object(isolate, value TSRMLS_CC);
} }
/* }}} */ /* }}} */

View File

@ -14,7 +14,7 @@
#ifndef V8JS_OBJECT_EXPORT_H #ifndef V8JS_OBJECT_EXPORT_H
#define V8JS_OBJECT_EXPORT_H #define V8JS_OBJECT_EXPORT_H
v8::Handle<v8::Value> php_v8js_hash_to_jsobj(zval *value, v8::Isolate *isolate TSRMLS_DC); v8::Handle<v8::Value> v8js_hash_to_jsobj(zval *value, v8::Isolate *isolate TSRMLS_DC);
typedef enum { typedef enum {
@ -25,7 +25,7 @@ typedef enum {
} property_op_t; } property_op_t;
template<typename T> template<typename T>
v8::Local<v8::Value> php_v8js_named_property_callback(v8::Local<v8::String> property, v8::Local<v8::Value> v8js_named_property_callback(v8::Local<v8::String> property,
const v8::PropertyCallbackInfo<T> &info, const v8::PropertyCallbackInfo<T> &info,
property_op_t callback_type, property_op_t callback_type,
v8::Local<v8::Value> set_value = v8::Local<v8::Value>()); v8::Local<v8::Value> set_value = v8::Local<v8::Value>());

View File

@ -133,7 +133,7 @@ void v8js_v8_call(v8js_ctx *c, zval **return_value,
efree(timer_ctx); efree(timer_ctx);
/* Check for fatal error marker possibly set by php_v8js_error_handler; just /* Check for fatal error marker possibly set by v8js_error_handler; just
* rethrow the error since we're now out of V8. */ * rethrow the error since we're now out of V8. */
if(V8JSG(fatal_error_abort)) { if(V8JSG(fatal_error_abort)) {
zend_bailout(); zend_bailout();
@ -174,14 +174,14 @@ void v8js_v8_call(v8js_ctx *c, zval **return_value,
/* Report immediately if report_uncaught is true */ /* Report immediately if report_uncaught is true */
if (c->report_uncaught) { if (c->report_uncaught) {
php_v8js_throw_script_exception(&try_catch TSRMLS_CC); v8js_throw_script_exception(&try_catch TSRMLS_CC);
return; return;
} }
/* Exception thrown from JS, preserve it for future execution */ /* Exception thrown from JS, preserve it for future execution */
if (result.IsEmpty()) { if (result.IsEmpty()) {
MAKE_STD_ZVAL(c->pending_exception); MAKE_STD_ZVAL(c->pending_exception);
php_v8js_create_script_exception(c->pending_exception, &try_catch TSRMLS_CC); v8js_create_script_exception(c->pending_exception, &try_catch TSRMLS_CC);
return; return;
} }
} }

View File

@ -25,7 +25,7 @@ extern "C" {
#include <v8.h> #include <v8.h>
#include <string> #include <string>
static void php_v8js_fetch_php_variable(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info) /* {{{ */ static void v8js_fetch_php_variable(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info) /* {{{ */
{ {
v8::Handle<v8::External> data = v8::Handle<v8::External>::Cast(info.Data()); v8::Handle<v8::External> data = v8::Handle<v8::External>::Cast(info.Data());
v8js_accessor_ctx *ctx = static_cast<v8js_accessor_ctx *>(data->Value()); v8js_accessor_ctx *ctx = static_cast<v8js_accessor_ctx *>(data->Value());
@ -50,7 +50,7 @@ void v8js_accessor_ctx_dtor(v8js_accessor_ctx *ctx TSRMLS_DC) /* {{{ */
} }
/* }}} */ /* }}} */
void php_v8js_register_accessors(std::vector<v8js_accessor_ctx*> *accessor_list, v8::Local<v8::FunctionTemplate> php_obj_t, zval *array, v8::Isolate *isolate TSRMLS_DC) /* {{{ */ void v8js_register_accessors(std::vector<v8js_accessor_ctx*> *accessor_list, v8::Local<v8::FunctionTemplate> php_obj_t, zval *array, v8::Isolate *isolate TSRMLS_DC) /* {{{ */
{ {
char *property_name; char *property_name;
uint property_name_len; uint property_name_len;
@ -86,7 +86,7 @@ void php_v8js_register_accessors(std::vector<v8js_accessor_ctx*> *accessor_list,
ctx->isolate = isolate; ctx->isolate = isolate;
/* Set the variable fetch callback for given symbol on named property */ /* Set the variable fetch callback for given symbol on named property */
php_obj->SetAccessor(V8JS_STRL(property_name, property_name_len - 1), php_v8js_fetch_php_variable, NULL, v8::External::New(isolate, ctx), v8::PROHIBITS_OVERWRITING, v8::ReadOnly, v8::AccessorSignature::New(isolate, php_obj_t)); php_obj->SetAccessor(V8JS_STRL(property_name, property_name_len - 1), v8js_fetch_php_variable, NULL, v8::External::New(isolate, ctx), v8::PROHIBITS_OVERWRITING, v8::ReadOnly, v8::AccessorSignature::New(isolate, php_obj_t));
/* record the context so we can free it later */ /* record the context so we can free it later */
accessor_list->push_back(ctx); accessor_list->push_back(ctx);