0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-12-22 14:01:53 +00:00

Store tsrm_ls in php_v8js_ctx.

This avoids the need to ever do a (slow) TSRMLS_FETCH().
This commit is contained in:
C. Scott Ananian 2013-10-25 23:46:03 -04:00
parent 011e517cfe
commit 39cc821f91
5 changed files with 23 additions and 11 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

@ -154,7 +154,7 @@ static void php_v8js_php_callback(const v8::FunctionCallbackInfo<v8::Value>& inf
v8::Isolate *isolate = info.GetIsolate();
v8::Local<v8::Object> self = info.Holder();
TSRMLS_FETCH();
V8JS_TSRMLS_FETCH();
zval *value = reinterpret_cast<zval *>(v8::External::Cast(*self->GetHiddenValue(V8JS_SYM(PHPJS_OBJECT_KEY)))->Value());
zend_function *method_ptr;
zend_class_entry *ce = Z_OBJCE_P(value);
@ -192,7 +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.
TSRMLS_FETCH();
V8JS_TSRMLS_FETCH();
zend_class_entry *ce = static_cast<zend_class_entry *>(ext_ce->Value());
zend_function *ctor_ptr = ce->constructor;
@ -241,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);
@ -280,7 +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;
TSRMLS_FETCH();
V8JS_TSRMLS_FETCH();
zend_class_entry *ce;
zend_function *method_ptr;
HashTable *proptable;
@ -403,7 +404,7 @@ static void php_v8js_fake_call_impl(const v8::FunctionCallbackInfo<v8::Value>& i
char *error;
int error_len;
TSRMLS_FETCH();
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);
@ -497,7 +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;
TSRMLS_FETCH();
V8JS_TSRMLS_FETCH();
zend_class_entry *scope = NULL; /* XXX? */
zend_class_entry *ce;
zend_function *method_ptr = NULL;

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