class Arachni::Browser::Javascript::Proxy::Stub

@note Extends ‘BasicObject` because we don’t want any baggage to avoid

method clashes with the Javascript-side objects.

Prepares JS calls for the given object based on property type.

@author Tasos “Zapotek” Laskos <tasos.laskos@arachni-scanner.com>

Public Class Methods

new( proxy ) click to toggle source

@param [Proxy] proxy

Parent {Proxy}.
# File lib/arachni/browser/javascript/proxy/stub.rb, line 22
def initialize( proxy )
    @proxy = proxy
end

Public Instance Methods

class() click to toggle source
# File lib/arachni/browser/javascript/proxy/stub.rb, line 66
def class
    Stub
end
function( name, *arguments ) click to toggle source

@param [#to_sym] name

Function name.

@param [Array] arguments

Arguments to pass to the JS function.

@return [String]

JS code to call the given function.
# File lib/arachni/browser/javascript/proxy/stub.rb, line 33
def function( name, *arguments )
    arguments = arguments.map { |arg| arg.to_json }.join( ', ' )

    if name.to_s.end_with?( '=' )
        "#{property( name )}#{arguments if !arguments.empty?}"
    else
        "#{property( name )}(#{arguments if !arguments.empty?})"
    end
end
method_missing( name, *arguments )
Alias for: write
property( name ) click to toggle source

@param [#to_sym] name

Function name.

@return [String]

JS code to retrieve the given property.
# File lib/arachni/browser/javascript/proxy/stub.rb, line 48
def property( name )
    "#{@proxy.js_object}.#{name}"
end
respond_to?( property ) click to toggle source

@param [Symbol] property

@return [Bool]

`true` if `self` of the JS object responds to `property`,
`false` otherwise.
# File lib/arachni/browser/javascript/proxy/stub.rb, line 80
def respond_to?( property )
    property = property.to_s
    property = property[0...-1] if property.end_with? '='

    @proxy.javascript.run( "return ('#{property}' in #{@proxy.js_object})" )
end
to_s() click to toggle source

@return [String]

# File lib/arachni/browser/javascript/proxy/stub.rb, line 71
def to_s
    "<#{self.class}##{object_id} #{@proxy.js_object}>"
end
write( name, *arguments ) click to toggle source

@param [#to_sym] name

Function/property name.

@param [Array] arguments

Arguments to pass to the JS function.

@return [String]

JS code to call the given function or retrieve the given property.
(Type detection is performed by {Proxy#function?}.)
# File lib/arachni/browser/javascript/proxy/stub.rb, line 60
def write( name, *arguments )
    @proxy.function?( name ) ?
        function( name, *arguments ) : property( name )
end
Also aliased as: method_missing