Class: Arachni::Browser::Javascript::Proxy::Stub
- Inherits:
- BasicObject
- Defined in:
- lib/arachni/browser/javascript/proxy/stub.rb
Overview
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.
Instance Method Summary collapse
- #class ⇒ Object
-
#function(name, *arguments) ⇒ String
JS code to call the given function.
-
#initialize(proxy) ⇒ Stub
constructor
A new instance of Stub.
-
#property(name) ⇒ String
JS code to retrieve the given property.
-
#respond_to?(property) ⇒ Bool
‘true` if `self` of the JS object responds to `property`, `false` otherwise.
- #to_s ⇒ String
-
#write(name, *arguments) ⇒ String
(also: #method_missing)
JS code to call the given function or retrieve the given property.
Constructor Details
#initialize(proxy) ⇒ Stub
Returns a new instance of Stub.
22 23 24 |
# File 'lib/arachni/browser/javascript/proxy/stub.rb', line 22 def initialize( proxy ) @proxy = proxy end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing ⇒ String
Returns JS code to call the given function or retrieve the given property. (Type detection is performed by Arachni::Browser::Javascript::Proxy#function?.).
64 65 66 67 |
# File 'lib/arachni/browser/javascript/proxy/stub.rb', line 64 def write( name, *arguments ) @proxy.function?( name ) ? function( name, *arguments ) : property( name ) end |
Instance Method Details
#class ⇒ Object
66 67 68 |
# File 'lib/arachni/browser/javascript/proxy/stub.rb', line 66 def class Stub end |
#function(name, *arguments) ⇒ String
Returns JS code to call the given function.
33 34 35 36 37 38 39 40 41 |
# 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 |
#property(name) ⇒ String
Returns JS code to retrieve the given property.
48 49 50 |
# File 'lib/arachni/browser/javascript/proxy/stub.rb', line 48 def property( name ) "#{@proxy.js_object}.#{name}" end |
#respond_to?(property) ⇒ Bool
Returns ‘true` if `self` of the JS object responds to `property`, `false` otherwise.
80 81 82 83 84 85 |
# 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 ⇒ String
71 72 73 |
# File 'lib/arachni/browser/javascript/proxy/stub.rb', line 71 def to_s "<#{self.class}##{object_id} #{@proxy.js_object}>" end |
#write(name, *arguments) ⇒ String Also known as: method_missing
Returns JS code to call the given function or retrieve the given property. (Type detection is performed by Arachni::Browser::Javascript::Proxy#function?.).
60 61 62 63 |
# File 'lib/arachni/browser/javascript/proxy/stub.rb', line 60 def write( name, *arguments ) @proxy.function?( name ) ? function( name, *arguments ) : property( name ) end |