Permalink
Browse files

Fix dynamic property lookup to hide special methods.

the methods '[]' and '[]=' were being returned as
valid property names.
  • Loading branch information...
1 parent cd7d5e7 commit 490002aad7115e4f2a63293fac266dd236f0ac46 @cowboyd committed Apr 20, 2012
Showing with 9 additions and 4 deletions.
  1. +9 −4 lib/v8/access.rb
View
@@ -6,7 +6,7 @@ def get(obj, name, &dontintercept)
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 @@ def set(obj, name, value, &dontintercept)
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 @@ def accessible_methods(obj, special_methods = false)
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

0 comments on commit 490002a

Please sign in to comment.