23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/hyperloop/console/object_space.rb', line 23
def self.objects(klass)
objs = []
matching_objs = []
%x{
var walk_the_object = function(js_obj) {
var keys = Object.keys(js_obj) //get all own property names of the object
keys.forEach( function ( key ) {
if ( key != '$$proto' ) {
var value = js_obj[ key ]; // get property value
// if the property value is an object...
if ( value && typeof value === 'object' ) {
// if we don't have this reference, and its an object of the class we want
if ( #{objs}.indexOf( value ) < 0 ) {
#{objs}.push( value ); // store the reference
if ( Object.keys(value).indexOf('$$id') >= 0 && value.$$class == #{klass} ) {
#{matching_objs}.push ( value )
}
walk_the_object(value) // traverse all its own properties
}
}
}
})
}
walk_the_object(window)
}
matching_objs
end
|