1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00

Fix loading of V8::Conversion classes inside an eigenclass

This commit is contained in:
Rodrigo Kochenburger 2012-07-23 21:06:45 -03:00
parent 09e4d40251
commit 7f3a8cb91f
3 changed files with 28 additions and 5 deletions

View file

@ -20,9 +20,10 @@ end
for type in [Class, Object, Array, Hash, String, Symbol, Time, Proc, Method] do for type in [Class, Object, Array, Hash, String, Symbol, Time, Proc, Method] do
type.class_eval do type.class_eval do
include V8::Conversion.const_get(name) include V8::Conversion.const_get(type.name)
end end
end end
class UnboundMethod class UnboundMethod
include V8::Conversion::Method include V8::Conversion::Method
end end

View file

@ -4,17 +4,19 @@ class V8::Conversion
def to_template def to_template
weakcell(:constructor) do 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 = template.InstanceTemplate()
prototype.SetNamedPropertyHandler(Get, Set) prototype.SetNamedPropertyHandler(V8::Conversion::ClassActions::Get, V8::Conversion::ClassActions::Set)
prototype.SetIndexedPropertyHandler(IGet, ISet) prototype.SetIndexedPropertyHandler(V8::Conversion::ClassActions::IGet, V8::Conversion::ClassActions::ISet)
if self != ::Object && superclass != ::Object && superclass != ::Class if self != ::Object && superclass != ::Object && superclass != ::Class
template.Inherit(superclass.to_template) template.Inherit(superclass.to_template)
end end
template template
end end
end end
end
module ClassActions
class Constructor class Constructor
include V8::Error::Protect include V8::Error::Protect
@ -115,6 +117,5 @@ class V8::Conversion
end end
end end
end end
end end
end end

21
spec/class_scope_spec.rb Normal file
View file

@ -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