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:
|
||||
factory = options[:factory] ||
|
||||
(options[:restrictable] ? RestrictableContextFactory.instance : self.class.default_factory)
|
||||
factory.call do |context|
|
||||
@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]
|
||||
for package in ["Packages", "java", "javax", "org", "com", "edu", "net"]
|
||||
@global.delete(package)
|
||||
end
|
||||
end
|
||||
end
|
||||
@options = options
|
||||
factory.call(self) # org.mozilla.javascript.ContextAction (invokes #run)
|
||||
if optimization_level = options[:optimization_level] || self.class.default_optimization_level
|
||||
self.optimization_level = optimization_level
|
||||
end
|
||||
|
@ -109,6 +96,26 @@ module Rhino
|
|||
yield(self) if block_given?
|
||||
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.
|
||||
def factory
|
||||
@native.getFactory
|
||||
|
@ -173,7 +180,7 @@ module Rhino
|
|||
if restrictable?
|
||||
@native.instruction_limit = limit
|
||||
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"
|
||||
end
|
||||
end
|
||||
|
@ -190,7 +197,7 @@ module Rhino
|
|||
if restrictable?
|
||||
@native.timeout_limit = limit
|
||||
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"
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue