mirror of
https://github.com/rubyjs/therubyrhino
synced 2023-03-27 23:21:34 -04:00
confusing Context resolution during jsapi specs - thus be explicit about JS::Context
This commit is contained in:
parent
ae19ed1a0f
commit
98178598b0
1 changed files with 6 additions and 8 deletions
|
@ -83,11 +83,11 @@ class Java::OrgMozillaJavascript::ScriptableObject
|
||||||
def method_missing(name, *args)
|
def method_missing(name, *args)
|
||||||
if ScriptableObject.hasProperty(self, name.to_s)
|
if ScriptableObject.hasProperty(self, name.to_s)
|
||||||
begin
|
begin
|
||||||
context = Context.enter
|
context = Rhino::JS::Context.enter
|
||||||
js_args = Rhino.args_to_javascript(args, self) # scope == self
|
js_args = Rhino.args_to_javascript(args, self) # scope == self
|
||||||
ScriptableObject.callMethod(context, self, name.to_s, js_args)
|
ScriptableObject.callMethod(context, self, name.to_s, js_args)
|
||||||
ensure
|
ensure
|
||||||
Context.exit
|
Rhino::JS::Context.exit
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
super
|
super
|
||||||
|
@ -119,27 +119,25 @@ end
|
||||||
|
|
||||||
# The base class for all JavaScript function objects.
|
# The base class for all JavaScript function objects.
|
||||||
class Java::OrgMozillaJavascript::BaseFunction
|
class Java::OrgMozillaJavascript::BaseFunction
|
||||||
|
|
||||||
import "org.mozilla.javascript"
|
|
||||||
|
|
||||||
alias_method :__call__, :call # Rhino's Function#call(a1, a2, a3, a4)
|
alias_method :__call__, :call # Rhino's Function#call(a1, a2, a3, a4)
|
||||||
|
|
||||||
# make JavaScript functions callable Ruby style e.g. `fn.call('42')`
|
# make JavaScript functions callable Ruby style e.g. `fn.call('42')`
|
||||||
def call(*args)
|
def call(*args)
|
||||||
context = Context.enter
|
context = Rhino::JS::Context.enter
|
||||||
scope = getParentScope || context.initStandardObjects
|
scope = getParentScope || context.initStandardObjects
|
||||||
__call__(context, scope, scope, Rhino.args_to_javascript(args, scope))
|
__call__(context, scope, scope, Rhino.args_to_javascript(args, scope))
|
||||||
ensure
|
ensure
|
||||||
Context.exit
|
Rhino::JS::Context.exit
|
||||||
end
|
end
|
||||||
|
|
||||||
# use JavaScript functions constructors from Ruby as `fn.new`
|
# use JavaScript functions constructors from Ruby as `fn.new`
|
||||||
def new(*args)
|
def new(*args)
|
||||||
context = Context.enter
|
context = Rhino::JS::Context.enter
|
||||||
scope = getParentScope || context.initStandardObjects
|
scope = getParentScope || context.initStandardObjects
|
||||||
construct(context, scope, Rhino.args_to_javascript(args, scope))
|
construct(context, scope, Rhino.args_to_javascript(args, scope))
|
||||||
ensure
|
ensure
|
||||||
Context.exit
|
Rhino::JS::Context.exit
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue