From 25f1d91b3f98405c4d40fff7aaab82bc45a9bcb7 Mon Sep 17 00:00:00 2001 From: Charles Lowell Date: Tue, 29 Jun 2010 08:22:41 +0300 Subject: [PATCH] add dynamic property access via the [] and []= methods. --- lib/v8/access.rb | 9 ++++++++- spec/redjs | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/v8/access.rb b/lib/v8/access.rb index 0c38e18..0cc1da7 100644 --- a/lib/v8/access.rb +++ b/lib/v8/access.rb @@ -107,6 +107,8 @@ module V8 else To.v8(method) end + elsif obj.respond_to?(:[]) + To.v8(obj[name]) else C::Empty end @@ -116,11 +118,15 @@ module V8 class NamedPropertySetter def self.call(property, value, info) obj = To.rb(info.This()) - setter = To.rb(property) + "=" + name = To.rb(property) + setter = name + "=" methods = accessible_methods(obj) if methods.include?(setter) obj.send(setter, To.rb(value)) value + elsif obj.respond_to?(:[]=) + obj.send(:[]=, name, To.rb(value)) + value else C::Empty end @@ -187,6 +193,7 @@ module V8 break if ancestor == ::Object methods.merge(ancestor.public_instance_methods(false).map {|m| m.to_s}) end + methods.reject! {|m| m == "[]" || m == "[]="} end end diff --git a/spec/redjs b/spec/redjs index 7587bc3..9ff9293 160000 --- a/spec/redjs +++ b/spec/redjs @@ -1 +1 @@ -Subproject commit 7587bc34da1f2944393e312bf4f1911218375b4a +Subproject commit 9ff9293c6d55d9276c3512221c4fdb912808564a