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

"int" property resolution for JS objects

This commit is contained in:
kares 2011-12-09 19:04:23 +01:00
parent d3d6928a46
commit 69b239cbf9

View file

@ -100,7 +100,16 @@ class Java::OrgMozillaJavascript::NativeObject
import "org.mozilla.javascript" import "org.mozilla.javascript"
# re-implement Map#put def [](name)
value = Rhino.to_ruby(ScriptableObject.getProperty(self, s_name = name.to_s))
# handle { '5': 5 }.keys() ... [ 5 ] not [ '5' ] !
if value.nil? && (i_name = s_name.to_i) != 0
value = Rhino.to_ruby(ScriptableObject.getProperty(self, i_name))
end
value
end
# re-implement unsupported Map#put
def []=(key, value) def []=(key, value)
scope = self scope = self
ScriptableObject.putProperty(self, key.to_s, Rhino.to_javascript(value, scope)) ScriptableObject.putProperty(self, key.to_s, Rhino.to_javascript(value, scope))