Module: Johnson::TraceMonkey::JSLandProxy
- Defined in:
- lib/johnson/tracemonkey/js_land_proxy.rb
Overview
:nodoc:
Class Method Summary collapse
- .autovivified(target, attribute) ⇒ Object
- .autovivified?(target, attribute) ⇒ Boolean
- .autovivify(target, attribute, value) ⇒ Object
- .js_property?(target, name) ⇒ Boolean
- .send_with_possible_block(target, symbol, args) ⇒ Object
- .treat_all_properties_as_methods(target) ⇒ Object
Class Method Details
.autovivified(target, attribute) ⇒ Object
29 30 31 |
# File 'lib/johnson/tracemonkey/js_land_proxy.rb', line 29 def self.autovivified(target, attribute) target.send(:__johnson_js_properties)[attribute] end |
.autovivified?(target, attribute) ⇒ Boolean
33 34 35 36 |
# File 'lib/johnson/tracemonkey/js_land_proxy.rb', line 33 def self.autovivified?(target, attribute) target.respond_to?(:__johnson_js_properties) && target.send(:__johnson_js_properties).key?(attribute) end |
.autovivify(target, attribute, value) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/johnson/tracemonkey/js_land_proxy.rb', line 38 def self.autovivify(target, attribute, value) (class << target; self; end).instance_eval do unless target.respond_to?(:__johnson_js_properties) define_method(:__johnson_js_properties) do @__johnson_js_properties ||= {} end end define_method(:"#{attribute}=") do |arg| send(:__johnson_js_properties)[attribute] = arg end define_method(:"#{attribute}") do |*args| js_prop = send(:__johnson_js_properties)[attribute] if js_prop.is_a?(RubyLandProxy) && js_prop.function? js_prop.call_using(self, *args) else js_prop end end end target.send(:"#{attribute}=", value) end |
.js_property?(target, name) ⇒ Boolean
23 24 25 26 27 |
# File 'lib/johnson/tracemonkey/js_land_proxy.rb', line 23 def self.js_property?(target, name) # FIXME: that rescue is gross; handles, e.g., "name?" (target.send(:instance_variable_defined?, "@#{name}") rescue false) || (target.respond_to?(:js_property?) && target.__send__(:js_property?, name)) end |
.send_with_possible_block(target, symbol, args) ⇒ Object
14 15 16 17 |
# File 'lib/johnson/tracemonkey/js_land_proxy.rb', line 14 def self.send_with_possible_block(target, symbol, args) block = args.pop if args.last.is_a?(RubyLandProxy) && args.last.function? target.__send__(symbol, *args, &block) end |
.treat_all_properties_as_methods(target) ⇒ Object
19 20 21 |
# File 'lib/johnson/tracemonkey/js_land_proxy.rb', line 19 def self.treat_all_properties_as_methods(target) def target.js_property?(name); true; end end |