0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-11-09 23:08:41 +00:00

Merge pull request #65 from cscott/zts-fix

ZTS fixes
This commit is contained in:
Patrick Reilly 2013-10-26 14:25:30 -07:00
commit b2a92e5be1
5 changed files with 28 additions and 12 deletions

View File

@ -161,9 +161,18 @@ struct php_v8js_ctx {
std::vector<char *> modules_stack;
std::vector<char *> modules_base;
std::map<const char *,v8js_tmpl_t> template_cache;
#ifdef ZTS
void ***zts_ctx;
#endif
};
/* }}} */
#ifdef ZTS
# define V8JS_TSRMLS_FETCH() TSRMLS_FETCH_FROM_CTX(((php_v8js_ctx *) isolate->GetData())->zts_ctx);
#else
# define V8JS_TSRMLS_FETCH()
#endif
// Timer context
struct php_v8js_timer_ctx
{

View File

@ -563,6 +563,7 @@ static zend_object_value php_v8js_new(zend_class_entry *ce TSRMLS_DC) /* {{{ */
c = (php_v8js_ctx *) ecalloc(1, sizeof(*c));
zend_object_std_init(&c->std, ce TSRMLS_CC);
TSRMLS_SET_CTX(c->zts_ctx);
#if PHP_VERSION_ID >= 50400
object_properties_init(&c->std, ce);

View File

@ -153,9 +153,10 @@ static void php_v8js_php_callback(const v8::FunctionCallbackInfo<v8::Value>& inf
{
v8::Isolate *isolate = info.GetIsolate();
v8::Local<v8::Object> self = info.Holder();
V8JS_TSRMLS_FETCH();
zval *value = reinterpret_cast<zval *>(v8::External::Cast(*self->GetHiddenValue(V8JS_SYM(PHPJS_OBJECT_KEY)))->Value());
zend_function *method_ptr;
TSRMLS_FETCH();
zend_class_entry *ce = Z_OBJCE_P(value);
/* Set method_ptr from v8::External or fetch the closure invoker */
@ -177,7 +178,6 @@ static void php_v8js_construct_callback(const v8::FunctionCallbackInfo<v8::Value
// @todo assert constructor call
v8::Handle<v8::Object> newobj = info.This();
v8::Local<v8::External> php_object;
TSRMLS_FETCH();
if (!info.IsConstructCall()) {
return;
@ -192,6 +192,7 @@ static void php_v8js_construct_callback(const v8::FunctionCallbackInfo<v8::Value
php_object = v8::Local<v8::External>::Cast(info[0]);
} else {
// Object created from JavaScript context. Need to create PHP object first.
V8JS_TSRMLS_FETCH();
zend_class_entry *ce = static_cast<zend_class_entry *>(ext_ce->Value());
zend_function *ctor_ptr = ce->constructor;
@ -240,8 +241,9 @@ static int _php_v8js_is_assoc_array(HashTable *myht TSRMLS_DC) /* {{{ */
/* }}} */
static void php_v8js_weak_object_callback(const v8::WeakCallbackData<v8::Object, zval> &data) {
TSRMLS_FETCH();
v8::Isolate *isolate = data.GetIsolate();
zval *value = data.GetParameter();
V8JS_TSRMLS_FETCH();
if (READY_TO_DESTROY(value)) {
zval_dtor(value);
FREE_ZVAL(value);
@ -279,6 +281,7 @@ static void php_v8js_named_property_enumerator(const v8::PropertyCallbackInfo<v8
v8::Local<v8::Array> result = v8::Array::New(0);
uint32_t result_len = 0;
V8JS_TSRMLS_FETCH();
zend_class_entry *ce;
zend_function *method_ptr;
HashTable *proptable;
@ -401,6 +404,7 @@ static void php_v8js_fake_call_impl(const v8::FunctionCallbackInfo<v8::Value>& i
char *error;
int error_len;
V8JS_TSRMLS_FETCH();
zend_class_entry *ce;
zval *object = reinterpret_cast<zval *>(v8::External::Cast(*self->GetHiddenValue(V8JS_SYM(PHPJS_OBJECT_KEY)))->Value());
ce = Z_OBJCE_P(object);
@ -443,7 +447,7 @@ static void php_v8js_fake_call_impl(const v8::FunctionCallbackInfo<v8::Value>& i
const zend_object_handlers *h = Z_OBJ_HT_P(object);
zend_function *method_ptr =
h->get_method(&object, (char*)method_name, method_name_len
ZEND_HASH_KEY_NULL TSRMLS_DC);
ZEND_HASH_KEY_NULL TSRMLS_CC);
if (method_ptr == NULL ||
(method_ptr->common.fn_flags & ZEND_ACC_PUBLIC) == 0 ||
(method_ptr->common.fn_flags & (ZEND_ACC_CTOR|ZEND_ACC_DTOR|ZEND_ACC_CLONE)) != 0) {
@ -494,6 +498,7 @@ static inline v8::Local<v8::Value> php_v8js_named_property_callback(v8::Local<v8
v8::Local<v8::Value> ret_value;
v8::Local<v8::Function> cb;
V8JS_TSRMLS_FETCH();
zend_class_entry *scope = NULL; /* XXX? */
zend_class_entry *ce;
zend_function *method_ptr = NULL;
@ -559,7 +564,7 @@ static inline v8::Local<v8::Value> php_v8js_named_property_callback(v8::Local<v8
}
if (callback_type == V8JS_PROP_GETTER) {
/* Nope, not a method -- must be a (case-sensitive) property */
php_value = zend_read_property(scope, object, V8JS_CONST name, name_len, true);
php_value = zend_read_property(scope, object, V8JS_CONST name, name_len, true TSRMLS_CC);
// special case 'NULL' and return an empty value (indicating that
// we don't intercept this property) if the property doesn't
// exist.
@ -582,8 +587,8 @@ static inline v8::Local<v8::Value> php_v8js_named_property_callback(v8::Local<v8
* reference to it (and so don't have to deref) */
} else if (callback_type == V8JS_PROP_SETTER) {
MAKE_STD_ZVAL(php_value);
if (v8js_to_zval(set_value, php_value, 0, isolate) == SUCCESS) {
zend_update_property(scope, object, V8JS_CONST name, name_len, php_value);
if (v8js_to_zval(set_value, php_value, 0, isolate TSRMLS_CC) == SUCCESS) {
zend_update_property(scope, object, V8JS_CONST name, name_len, php_value TSRMLS_CC);
ret_value = set_value;
} else {
ret_value = v8::Handle<v8::Value>();

View File

@ -45,7 +45,7 @@ V8JS_METHOD(print) /* {{{ */
{
v8::Isolate *isolate = info.GetIsolate();
int ret = 0;
TSRMLS_FETCH();
V8JS_TSRMLS_FETCH();
for (int i = 0; i < info.Length(); i++) {
v8::String::Utf8Value str(info[i]);
@ -184,7 +184,7 @@ static void _php_v8js_dumper(v8::Isolate *isolate, v8::Local<v8::Value> var, int
V8JS_METHOD(var_dump) /* {{{ */
{
v8::Isolate *isolate = info.GetIsolate();
TSRMLS_FETCH();
V8JS_TSRMLS_FETCH();
for (int i = 0; i < info.Length(); i++) {
_php_v8js_dumper(isolate, info[i], 1 TSRMLS_CC);
@ -197,7 +197,7 @@ V8JS_METHOD(var_dump) /* {{{ */
V8JS_METHOD(require)
{
v8::Isolate *isolate = info.GetIsolate();
TSRMLS_FETCH();
V8JS_TSRMLS_FETCH();
// Get the extension context
v8::Handle<v8::External> data = v8::Handle<v8::External>::Cast(info.Data());

View File

@ -36,14 +36,15 @@ static void php_v8js_fetch_php_variable(v8::Local<v8::String> name, const v8::Pr
{
v8::Handle<v8::External> data = v8::Handle<v8::External>::Cast(info.Data());
php_v8js_accessor_ctx *ctx = static_cast<php_v8js_accessor_ctx *>(data->Value());
v8::Isolate *isolate = ctx->isolate;
zval **variable;
TSRMLS_FETCH();
V8JS_TSRMLS_FETCH();
zend_is_auto_global(ctx->variable_name_string, ctx->variable_name_string_len TSRMLS_CC);
if (zend_hash_find(&EG(symbol_table), ctx->variable_name_string, ctx->variable_name_string_len + 1, (void **) &variable) == SUCCESS) {
info.GetReturnValue().Set(zval_to_v8js(*variable, ctx->isolate TSRMLS_CC));
info.GetReturnValue().Set(zval_to_v8js(*variable, isolate TSRMLS_CC));
return;
}
}