From 7f3a8cb91f261ed14c02e230b4f5e476a4891a91 Mon Sep 17 00:00:00 2001 From: Rodrigo Kochenburger Date: Mon, 23 Jul 2012 21:06:45 -0300 Subject: [PATCH] Fix loading of V8::Conversion classes inside an eigenclass --- lib/v8/conversion.rb | 3 ++- lib/v8/conversion/class.rb | 9 +++++---- spec/class_scope_spec.rb | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 spec/class_scope_spec.rb diff --git a/lib/v8/conversion.rb b/lib/v8/conversion.rb index fa47a34..76bc332 100644 --- a/lib/v8/conversion.rb +++ b/lib/v8/conversion.rb @@ -20,9 +20,10 @@ end for type in [Class, Object, Array, Hash, String, Symbol, Time, Proc, Method] do type.class_eval do - include V8::Conversion.const_get(name) + include V8::Conversion.const_get(type.name) end end + class UnboundMethod include V8::Conversion::Method end diff --git a/lib/v8/conversion/class.rb b/lib/v8/conversion/class.rb index 030e996..3e7a663 100644 --- a/lib/v8/conversion/class.rb +++ b/lib/v8/conversion/class.rb @@ -4,17 +4,19 @@ class V8::Conversion def to_template weakcell(:constructor) do - template = V8::C::FunctionTemplate::New(Constructor.new(self)) + template = V8::C::FunctionTemplate::New(V8::Conversion::ClassActions::Constructor.new(self)) prototype = template.InstanceTemplate() - prototype.SetNamedPropertyHandler(Get, Set) - prototype.SetIndexedPropertyHandler(IGet, ISet) + prototype.SetNamedPropertyHandler(V8::Conversion::ClassActions::Get, V8::Conversion::ClassActions::Set) + prototype.SetIndexedPropertyHandler(V8::Conversion::ClassActions::IGet, V8::Conversion::ClassActions::ISet) if self != ::Object && superclass != ::Object && superclass != ::Class template.Inherit(superclass.to_template) end template end end + end + module ClassActions class Constructor include V8::Error::Protect @@ -115,6 +117,5 @@ class V8::Conversion end end end - end end \ No newline at end of file diff --git a/spec/class_scope_spec.rb b/spec/class_scope_spec.rb new file mode 100644 index 0000000..bc9be01 --- /dev/null +++ b/spec/class_scope_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +# NOTE: This was written to reproduce a bug where V8::Conversion would load the wrong class +# when inside of an eigen class scope. + +# We use Set because ::Set is a existing class and V8::Conversion::Class::Set also exists +require "set" + +describe "Class scope" do + it "doesn't try to use V8::Conversion::Class::* as root objects" do + klass = Class.new do + class << self + def test + Set.new + end + end + end + + klass.test.should be_instance_of(::Set) + end +end \ No newline at end of file