mirror of
https://github.com/rubyjs/therubyrhino
synced 2023-03-27 23:21:34 -04:00
avoid the dynamic interface proxy creation on factory.call(ContextAction) (fixes #30)
This commit is contained in:
parent
5b033dc5e5
commit
a2e907ae25
1 changed files with 66 additions and 59 deletions
|
@ -85,21 +85,8 @@ module Rhino
|
||||||
def initialize(options = {}) #:nodoc:
|
def initialize(options = {}) #:nodoc:
|
||||||
factory = options[:factory] ||
|
factory = options[:factory] ||
|
||||||
(options[:restrictable] ? RestrictableContextFactory.instance : self.class.default_factory)
|
(options[:restrictable] ? RestrictableContextFactory.instance : self.class.default_factory)
|
||||||
factory.call do |context|
|
@options = options
|
||||||
@native = context
|
factory.call(self) # org.mozilla.javascript.ContextAction (invokes #run)
|
||||||
@global = @native.initStandardObjects(nil, options[:sealed] == true)
|
|
||||||
if with = options[:with]
|
|
||||||
@scope = Rhino.to_javascript(with)
|
|
||||||
@scope.setParentScope(@global)
|
|
||||||
else
|
|
||||||
@scope = @global
|
|
||||||
end
|
|
||||||
unless options[:java]
|
|
||||||
for package in ["Packages", "java", "javax", "org", "com", "edu", "net"]
|
|
||||||
@global.delete(package)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if optimization_level = options[:optimization_level] || self.class.default_optimization_level
|
if optimization_level = options[:optimization_level] || self.class.default_optimization_level
|
||||||
self.optimization_level = optimization_level
|
self.optimization_level = optimization_level
|
||||||
end
|
end
|
||||||
|
@ -109,6 +96,26 @@ module Rhino
|
||||||
yield(self) if block_given?
|
yield(self) if block_given?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
include JS::ContextAction
|
||||||
|
|
||||||
|
# org.mozilla.javascript.ContextAction public Object run(Context context);
|
||||||
|
def run(context) # :nodoc:
|
||||||
|
@native = context
|
||||||
|
@global = @native.initStandardObjects(nil, @options[:sealed] == true)
|
||||||
|
if with = @options[:with]
|
||||||
|
@scope = Rhino.to_javascript(with)
|
||||||
|
@scope.setParentScope(@global)
|
||||||
|
else
|
||||||
|
@scope = @global
|
||||||
|
end
|
||||||
|
unless @options[:java]
|
||||||
|
@global.delete('Packages')
|
||||||
|
@global.delete('java'); @global.delete('javax')
|
||||||
|
@global.delete('org'); @global.delete('com')
|
||||||
|
@global.delete('edu'); @global.delete('net')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Returns the ContextFactory used while creating this context.
|
# Returns the ContextFactory used while creating this context.
|
||||||
def factory
|
def factory
|
||||||
@native.getFactory
|
@native.getFactory
|
||||||
|
@ -173,7 +180,7 @@ module Rhino
|
||||||
if restrictable?
|
if restrictable?
|
||||||
@native.instruction_limit = limit
|
@native.instruction_limit = limit
|
||||||
else
|
else
|
||||||
raise "setting an instruction_limit has no effect on this context, use " +
|
raise "setting an instruction_limit has no effect on this context, use " <<
|
||||||
"Context.open(:restrictable => true) to gain a restrictable instance"
|
"Context.open(:restrictable => true) to gain a restrictable instance"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -190,7 +197,7 @@ module Rhino
|
||||||
if restrictable?
|
if restrictable?
|
||||||
@native.timeout_limit = limit
|
@native.timeout_limit = limit
|
||||||
else
|
else
|
||||||
raise "setting an timeout_limit has no effect on this context, use " +
|
raise "setting an timeout_limit has no effect on this context, use " <<
|
||||||
"Context.open(:restrictable => true) to gain a restrictable instance"
|
"Context.open(:restrictable => true) to gain a restrictable instance"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue