Class: JavascriptArray

Inherits:
JavascriptObject show all
Includes:
Enumerable
Defined in:
lib/vapir-firefox/javascript_object.rb

Overview

this class represents a javascript array - that is, a javascript object that has a ‘length’ attribute which is a non-negative integer, and returns elements at each subscript from 0 to less than than that length.

Instance Attribute Summary

Attributes inherited from JavascriptObject

#debug_name, #firefox_socket, #function_result, #ref

Instance Method Summary collapse

Methods inherited from JavascriptObject

#%, #*, #+, #-, #/, #<, #<=, #==, #>, #>=, #[], #[]=, always_define_methods, always_define_methods=, #assign, #assign_expr, #assign_or_call_or_val_or_object_by_suffix, #attr, #binary_operator, #call, #define_methods!, #implemented_interfaces, #initialize, #inspect, #instanceof, #invoke, #invoke?, #method_missing, #new, #object_respond_to?, #object_type, #pass, #pretty_print, #respond_to?, #store, #store_rand_object_key, #store_rand_temp, #sub, #to_array, #to_dom, #to_function, #to_hash, #to_js_array, #to_js_hash, #to_js_hash_safe, #to_ruby_array, #to_ruby_hash, #to_simple_enumerator, #triple_equals, #type, #val, #val_or_object, #val_str

Constructor Details

This class inherits a constructor from JavascriptObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class JavascriptObject

Instance Method Details

#eachObject

yields the element at each subscript of this javascript array, from 0 to self.length.



683
684
685
686
687
688
689
690
691
692
693
694
# File 'lib/vapir-firefox/javascript_object.rb', line 683

def each
  length=self.length
  raise FirefoxSocketJavascriptError, "length #{length.inspect} is not a non-negative integer on #{self.ref}" unless length.is_a?(Integer) && length >= 0
  for i in 0...length
    element=self[i]
    if element.is_a?(JavascriptObject)
      # yield a more permanent reference than the array subscript 
      element=element.store_rand_temp
    end
    yield element
  end
end