2012-01-06 12:29:22 -05:00
|
|
|
module Rhino
|
|
|
|
module Ruby
|
2012-04-20 14:24:43 -04:00
|
|
|
class DefaultAccess < AccessBase
|
2012-01-06 12:29:22 -05:00
|
|
|
|
2012-04-20 14:24:43 -04:00
|
|
|
def has(object, name, scope)
|
2012-01-06 12:29:22 -05:00
|
|
|
if object.respond_to?(name.to_s) ||
|
2012-04-21 13:51:47 -04:00
|
|
|
object.respond_to?(:"#{name}=")
|
2012-01-06 12:29:22 -05:00
|
|
|
return true
|
|
|
|
end
|
2012-04-20 14:24:43 -04:00
|
|
|
super
|
2012-01-06 12:29:22 -05:00
|
|
|
end
|
|
|
|
|
2012-04-20 14:24:43 -04:00
|
|
|
def get(object, name, scope)
|
2012-01-06 12:29:22 -05:00
|
|
|
if object.respond_to?(name_s = name.to_s)
|
|
|
|
method = object.method(name_s)
|
2012-01-07 11:01:38 -05:00
|
|
|
if method.arity == 0
|
2012-04-20 14:24:43 -04:00
|
|
|
return Rhino.to_javascript(method.call, scope)
|
2012-01-06 12:29:22 -05:00
|
|
|
else
|
2012-01-10 11:24:12 -05:00
|
|
|
return Function.wrap(method.unbind)
|
2012-01-06 12:29:22 -05:00
|
|
|
end
|
2012-04-21 13:51:47 -04:00
|
|
|
elsif object.respond_to?(:"#{name}=")
|
2012-01-07 11:01:38 -05:00
|
|
|
return nil
|
2012-01-06 12:29:22 -05:00
|
|
|
end
|
2012-04-20 14:24:43 -04:00
|
|
|
super
|
2012-01-06 12:29:22 -05:00
|
|
|
end
|
|
|
|
|
2012-04-20 14:24:43 -04:00
|
|
|
def put(object, name, value)
|
2012-04-21 13:51:47 -04:00
|
|
|
if object.respond_to?(set_name = :"#{name}=")
|
2012-01-06 12:29:22 -05:00
|
|
|
return object.send(set_name, Rhino.to_ruby(value))
|
|
|
|
end
|
2012-04-20 14:24:43 -04:00
|
|
|
super
|
2012-01-06 12:29:22 -05:00
|
|
|
end
|
|
|
|
|
2012-04-20 14:24:43 -04:00
|
|
|
extend DeprecatedAccess # backward compatibility for a while
|
|
|
|
|
2012-01-06 12:29:22 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|