Class: Arachni::Browser::Javascript::Proxy
- Inherits:
 - BasicObject
 
- Defined in:
 - lib/arachni/browser/javascript/proxy.rb,
lib/arachni/browser/javascript/proxy/stub.rb 
Overview
Extends `BasicObject` because we don't want any baggage to avoid method-name clashes with the Javascript-side objects.
Provides a proxy to a Javascript object.
Direct Known Subclasses
Defined Under Namespace
Classes: Stub
Instance Attribute Summary collapse
- 
  
    
      #javascript  ⇒ Javascript 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Active Arachni::Browser::Javascript interface.
 - 
  
    
      #stub  ⇒ Stub 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Stub interface for JS code.
 
Class Method Summary collapse
Instance Method Summary collapse
- #call(function, *arguments) ⇒ Object (also: #method_missing)
 - #class ⇒ Object
 - 
  
    
      #function?(name)  ⇒ Bool 
    
    
  
  
  
  
  
  
  
  
  
    
`true` if the `name` property of the current object points to a function, `false` otherwise.
 - 
  
    
      #initialize(javascript, object)  ⇒ Proxy 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of Proxy.
 - 
  
    
      #js_object  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    
Active JS-side object name – prefixed with the relevant `_token`.
 - 
  
    
      #respond_to?(property)  ⇒ Bool 
    
    
  
  
  
  
  
  
  
  
  
    
`true` if `self` of the JS object responds to `property`, `false` otherwise.
 
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing ⇒ Object
      61 62 63  | 
    
      # File 'lib/arachni/browser/javascript/proxy.rb', line 61 def call( function, *arguments ) @javascript.run_without_elements "return #{stub.write( function, *arguments )}" end  | 
  
Instance Attribute Details
#javascript ⇒ Javascript (readonly)
Returns Active Arachni::Browser::Javascript interface.
      27 28 29  | 
    
      # File 'lib/arachni/browser/javascript/proxy.rb', line 27 def javascript @javascript end  | 
  
#stub ⇒ Stub (readonly)
Returns Stub interface for JS code.
      23 24 25  | 
    
      # File 'lib/arachni/browser/javascript/proxy.rb', line 23 def stub @stub end  | 
  
Class Method Details
.function?(env, object, name) ⇒ Boolean
      76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95  | 
    
      # File 'lib/arachni/browser/javascript/proxy.rb', line 76 def self.function?( env, object, name ) mutex.synchronize do @isFunction ||= {} key = "#{object}.#{name}".hash return @isFunction[key] if @isFunction.include?( key ) if name.to_s.end_with? '=' name = name.to_s return @isFunction[key] = env.run( "return ('#{name[0...-1]}' in #{object})" ) end @isFunction[key] = env.run( "return Object.prototype.toString.call( #{object}." << "#{name} ) == '[object Function]'" ) end end  | 
  
.mutex ⇒ Object
      96 97 98  | 
    
      # File 'lib/arachni/browser/javascript/proxy.rb', line 96 def self.mutex @mutex ||= ::Mutex.new end  | 
  
Instance Method Details
#call(function, *arguments) ⇒ Object Also known as: method_missing
      58 59 60  | 
    
      # File 'lib/arachni/browser/javascript/proxy.rb', line 58 def call( function, *arguments ) @javascript.run_without_elements "return #{stub.write( function, *arguments )}" end  | 
  
#class ⇒ Object
      72 73 74  | 
    
      # File 'lib/arachni/browser/javascript/proxy.rb', line 72 def class Proxy end  | 
  
#function?(name) ⇒ Bool
Returns `true` if the `name` property of the current object points to a function, `false` otherwise.
      45 46 47  | 
    
      # File 'lib/arachni/browser/javascript/proxy.rb', line 45 def function?( name ) self.class.function?( @javascript, js_object, name ) end  | 
  
#js_object ⇒ String
Returns Active JS-side object name – prefixed with the relevant `_token`.
      51 52 53  | 
    
      # File 'lib/arachni/browser/javascript/proxy.rb', line 51 def js_object "_#{@javascript.token}#{@object}" end  | 
  
#respond_to?(property) ⇒ Bool
Returns `true` if `self` of the JS object responds to `property`, `false` otherwise.
      68 69 70  | 
    
      # File 'lib/arachni/browser/javascript/proxy.rb', line 68 def respond_to?( property ) stub.respond_to?( property ) end  |