Browse Source

Add isolate to key of template cache.

Stefan Siegl 11 năm trước cách đây
mục cha
commit
bc82d13658
2 tập tin đã thay đổi với 8 bổ sung4 xóa
  1. 1 1
      tests/multi-object.phpt
  2. 7 3
      v8js_convert.cc

+ 1 - 1
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) {

+ 7 - 3
v8js_convert.cc

@@ -29,6 +29,9 @@ extern "C" {
 #include <map>
 #include <stdexcept>
 
+typedef std::pair<v8::Isolate *, const char *> TemplateCacheKey;
+typedef std::map<TemplateCacheKey, v8::Persistent<v8::FunctionTemplate> > 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<v8::Value>& info) /* {{{ */
 {
@@ -371,10 +374,10 @@ static v8::Handle<v8::Value> php_v8js_hash_to_jsobj(zval *value, v8::Isolate *is
 	if (ce) {
 		v8::Handle<v8::FunctionTemplate> new_tpl;
 		bool cached_tpl = true;
-		static std::map<const char *, v8::Persistent<v8::FunctionTemplate> > 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<v8::Value> 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<v8::FunctionTemplate>::New(isolate, new_tpl);
+				tpl_map[std::make_pair(isolate, ce->name)] =
+					v8::Persistent<v8::FunctionTemplate>::New(isolate, new_tpl);
 			}
 		}