From 77804fce1c91cad0a2458b27d07af934122e292a Mon Sep 17 00:00:00 2001 From: Charles Lowell Date: Wed, 20 Jun 2012 15:30:34 -0500 Subject: [PATCH] Don't check for strings and primitives in idmap. It appears that `Ref::WeakValueMap` is not 100% correct. There are cases where entries are temporarily corrupted; probably while attached finalizers run. This is a slight decrease in flexibility in that strings and primitives cannot maintain referential integrity when passed by reference to v8, but the default is to pass them by value anyway, and it greatly reduces the number of object_ids that the idmap sees and therefore reduces the chances of a recycled object id causing a bad lookup. While this is not a perfect fix, it does make a collision very unlikely, and it prevents the crashes being seen in #169 If this pops up again, we'll have to look at getting a perfectly reliable weakmap implementation. --- benchmarks.rb | 5 ----- lib/v8/conversion/indentity.rb | 1 + 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/benchmarks.rb b/benchmarks.rb index e389555..24de590 100644 --- a/benchmarks.rb +++ b/benchmarks.rb @@ -39,11 +39,6 @@ if MODE==:object end elsif MODE==:function def get(i) - test = @cxt['test'] - unless test - $stderr.puts "wtf? #{test.inspect} -> #{@cxt.eval('test')}" - $stderr.puts "wff2? #{test.inspect} -> #{@cxt['test']}" - end @cxt["test"].getObject(i) end elsif MODE==:eval diff --git a/lib/v8/conversion/indentity.rb b/lib/v8/conversion/indentity.rb index fa469ab..a11cabf 100644 --- a/lib/v8/conversion/indentity.rb +++ b/lib/v8/conversion/indentity.rb @@ -11,6 +11,7 @@ class V8::Conversion end def to_v8(ruby_object) + return super(ruby_object) if ruby_object.is_a?(String) || ruby_object.is_a?(Primitive) rb_idmap[ruby_object.object_id] || super(ruby_object) end