From bc82d13658d1073e6ac7c19d232f2a271c07ba7f Mon Sep 17 00:00:00 2001 From: Stefan Siegl Date: Wed, 2 Oct 2013 23:38:26 +0200 Subject: [PATCH] Add isolate to key of template cache. --- tests/multi-object.phpt | 2 +- v8js_convert.cc | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/multi-object.phpt b/tests/multi-object.phpt index e4995d7..ac788c7 100644 --- a/tests/multi-object.phpt +++ b/tests/multi-object.phpt @@ -25,7 +25,7 @@ for($i = 0; $i < 5; $i ++) { } $JS = <<< EOT -php.test.sayHello(); +PHP.test.sayHello(); EOT; foreach($instances as $v8) { diff --git a/v8js_convert.cc b/v8js_convert.cc index 6be3d24..76a7830 100644 --- a/v8js_convert.cc +++ b/v8js_convert.cc @@ -29,6 +29,9 @@ extern "C" { #include #include +typedef std::pair TemplateCacheKey; +typedef std::map > TemplateCache; + /* 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& info) /* {{{ */ { @@ -371,10 +374,10 @@ static v8::Handle php_v8js_hash_to_jsobj(zval *value, v8::Isolate *is if (ce) { v8::Handle new_tpl; bool cached_tpl = true; - static std::map > tpl_map; + static TemplateCache tpl_map; try { - new_tpl = tpl_map.at(ce->name); + new_tpl = tpl_map.at(std::make_pair(isolate, ce->name)); } catch (const std::out_of_range &) { cached_tpl = false; @@ -393,7 +396,8 @@ static v8::Handle php_v8js_hash_to_jsobj(zval *value, v8::Isolate *is new_tpl->InstanceTemplate()->SetCallAsFunctionHandler(php_v8js_php_callback); } else { /* Add new v8::FunctionTemplate to tpl_map, as long as it is not a closure. */ - tpl_map[ce->name] = v8::Persistent::New(isolate, new_tpl); + tpl_map[std::make_pair(isolate, ce->name)] = + v8::Persistent::New(isolate, new_tpl); } }