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.
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
75 76 77 |
# File 'lib/arachni/browser/javascript/proxy.rb', line 75 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 |
Instance Method Details
#call(function, *arguments) ⇒ Object Also known as: method_missing
72 73 74 |
# File 'lib/arachni/browser/javascript/proxy.rb', line 72 def call( function, *arguments ) @javascript.run_without_elements "return #{stub.write( function, *arguments )}" end |
#class ⇒ Object
86 87 88 |
# File 'lib/arachni/browser/javascript/proxy.rb', line 86 def class Proxy end |
#function?(name) ⇒ Bool
Returns ‘true` if the `name` property of the current object points to a function, `false` otherwise.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/arachni/browser/javascript/proxy.rb', line 46 def function?( name ) return @isFunction[name.to_sym] if @isFunction.include?( name.to_sym ) if name.to_s.end_with? '=' name = name.to_s return @isFunction[name.to_sym] = @javascript.run( "return ('#{name[0...-1]}' in #{js_object})" ) end @isFunction[name.to_sym] = @javascript.run( "return Object.prototype.toString.call( #{js_object}." << "#{name} ) == '[object Function]'" ) end |
#js_object ⇒ String
Returns Active JS-side object name – prefixed with the relevant ‘_token`.
65 66 67 |
# File 'lib/arachni/browser/javascript/proxy.rb', line 65 def js_object "_#{@javascript.token}#{@object}" end |
#respond_to?(property) ⇒ Bool
Returns ‘true` if `self` of the JS object responds to `property`, `false` otherwise.
82 83 84 |
# File 'lib/arachni/browser/javascript/proxy.rb', line 82 def respond_to?( property ) stub.respond_to?( property ) end |