2009-11-11 21:12:20 -05:00
|
|
|
|
|
|
|
module Rhino
|
2009-11-15 21:56:31 -05:00
|
|
|
|
|
|
|
# Wraps a function that has been defined in Javascript so that it can
|
|
|
|
# be referenced and called from javascript. e.g.
|
|
|
|
#
|
|
|
|
# plus = Rhino::Context.open do |cx|
|
|
|
|
# cx.eval('function(lhs, rhs) {return lhs + rhs}')
|
|
|
|
# end
|
|
|
|
# plus.call(5,4) # => 9
|
|
|
|
#
|
2009-11-11 21:12:20 -05:00
|
|
|
class NativeFunction < NativeObject
|
|
|
|
def call(*args)
|
|
|
|
begin
|
|
|
|
cxt = J::Context.enter()
|
|
|
|
scope = @j.getParentScope() || cxt.initStandardObjects()
|
|
|
|
@j.call(cxt, scope, scope, args.map {|o| To.javascript(o)})
|
|
|
|
ensure
|
|
|
|
J::Context.exit()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|