mirror of
https://github.com/rubyjs/therubyrhino
synced 2023-03-27 23:21:34 -04:00
function's return value should be converted to Ruby
(when invoked Ruby #call style)
This commit is contained in:
parent
fc7b183be6
commit
0a38ab3f0a
2 changed files with 15 additions and 2 deletions
|
@ -165,7 +165,8 @@ class Java::OrgMozillaJavascript::BaseFunction
|
|||
# calling as a (var) stored function - no this === undefined "use strict"
|
||||
# TODO can't pass Undefined.instance as this - it's not a Scriptable !?
|
||||
this = Rhino::JS::ScriptRuntime.getGlobal(context)
|
||||
__call__(context, scope, this, Rhino.args_to_javascript(args, scope))
|
||||
js_args = Rhino.args_to_javascript(args, scope)
|
||||
Rhino.to_ruby __call__(context, scope, this, js_args)
|
||||
rescue Rhino::JS::JavaScriptException => e
|
||||
raise Rhino::JSError.new(e)
|
||||
ensure
|
||||
|
|
|
@ -158,10 +158,22 @@ describe "NativeFunction" do
|
|||
|
||||
it_should_behave_like 'ScriptableObject'
|
||||
|
||||
it 'is callable' do
|
||||
it 'is (Ruby) callable' do
|
||||
# NOTE: no implicit or bound this thus this === global
|
||||
@object.call.should == '[object global]'
|
||||
end
|
||||
|
||||
it 'is (Ruby) callable passing arguments' do
|
||||
js = "( function foo(arg) { return 'foo' + arg; } )"
|
||||
foo = @context.evaluateString(@scope, js, '<eval>', 0, nil)
|
||||
foo.call(42).should == 'foo42'
|
||||
end
|
||||
|
||||
it 'is (Ruby) callable converting result' do
|
||||
js = "( function foo(arg) { return [ 1, 2, arg ]; } )"
|
||||
foo = @context.evaluateString(@scope, js, '<eval>', 0, nil)
|
||||
foo.call('x').should == [ 1, 2, 'x' ]
|
||||
end
|
||||
|
||||
it 'might be bind and called' do
|
||||
@object.bind(@object).should be_a(Rhino::JS::Function)
|
||||
|
|
Loading…
Reference in a new issue