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

Fix dynamic property lookup to hide special methods.

the methods '[]' and '[]=' were being returned as
valid property names.
This commit is contained in:
Charles Lowell 2012-04-20 10:48:36 -05:00
parent cd7d5e7b94
commit 490002aad7

View file

@ -6,7 +6,7 @@ module V8
if methods.include?(name)
method = obj.method(name)
method.arity == 0 ? method.call : method.unbind
elsif obj.respond_to?(:[])
elsif obj.respond_to?(:[]) && !special?(name)
obj.send(:[], name, &dontintercept)
else
yield
@ -26,7 +26,7 @@ module V8
methods = accessible_methods(obj, true)
if methods.include?(setter)
obj.send(setter, value)
elsif obj.respond_to?(:[]=)
elsif obj.respond_to?(:[]=) && !special?(name)
obj.send(:[]=, name, value, &dontintercept)
else
yield
@ -80,8 +80,13 @@ module V8
break if ancestor == ::Object
methods.merge(ancestor.public_instance_methods(false).map {|m| m.to_s})
end
methods.reject! {|m| m == "[]" || m == "[]=" || m =~ /=$/} unless special_methods
methods.reject!(&special?) unless special_methods
end
end
def special?(name = nil)
@special ||= lambda {|m| m == "[]" || m == "[]=" || m =~ /=$/}
name.nil? ? @special : @special[name]
end
end
end
end