Object
# File lib/origami/javascript.rb, line 546 def initialize(pdf) @options = { :viewerVersion => JavaScript::Platforms::WINDOWS, :viewerType => JavaScript::Viewers::ADOBE_READER, :viewerVariation => JavaScript::Viewers::ADOBE_READER, :platform => 9, :console => STDOUT, :log_method_calls => false } @global = JavaScript::Doc.new(self, pdf) app = JavaScript::App.new(self) acrohelp = JavaScript::Acrohelp.new(self) global = JavaScript::Global.new(self) console = JavaScript::Console.new(self) util = JavaScript::Util.new(self) @context = V8::Context.new(:with => @global) @context['app'] = app @context['acrohelp'] = acrohelp @context['console'] = console @context['global'] = global @context['util'] = util @parseInt = @context['parseInt'] @hooks = {} end
# File lib/origami/javascript.rb, line 649 def debugger_break exec 'debugger' end
Binds the V8 remote debugging agent on the specified TCP port.
# File lib/origami/javascript.rb, line 645 def enable_debugger(port = 5858) V8::C::Debug.EnableAgent("Origami", port) end
Evaluates a JavaScript code in the current context.
# File lib/origami/javascript.rb, line 578 def exec(script) @context.eval(script) end
Set a hook on a JavaScript method.
# File lib/origami/javascript.rb, line 585 def hook(name, &callback) ns = name.split('.') previous = @context ns.each do |n| raise JavaScript::EngineError, "#{name} does not exist" if previous.nil? previous = previous[n] end case previous when V8::Function, UnboundMethod, nil then @context[name] = lambda do |*args| callback[previous, *args] end @hooks[name] = [previous, callback] else raise JavaScript::EngineError, "#{name} is not a function" end end
Returns an Hash of all defined members in specified object name.
# File lib/origami/javascript.rb, line 618 def members(obj) members = {} list = @context.eval (function(base){ var members = []; for (var i in base) members.push([i, base[i]]); return members; })(#{obj}) list.each do |var| members[var[0]] = var[1] end members end
Returns all members in the global scope.
# File lib/origami/javascript.rb, line 638 def scope members('this') end
Removes an existing hook on a JavaScript method.
# File lib/origami/javascript.rb, line 609 def unhook(name) if @hooks.has_key?(name) @context[name] = @hooks[name][0] end end
Generated with the Darkfish Rdoc Generator 2.