Class: Sol::JSObject
- Inherits:
-
Object
show all
- Defined in:
- lib/jx/jsobject.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(jsvalue, scope = nil) ⇒ JSObject
70
71
72
73
74
75
|
# File 'lib/jx/jsobject.rb', line 70
def initialize(jsvalue, scope = nil)
@jsvalue = jsvalue
@scope = scope
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args, &blk) ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/jx/jsobject.rb', line 105
def method_missing(symbol, *args, &blk)
args.push(B.blk2func(blk)) if (blk)
name = symbol.id2name
if name == "[]="
assign(*(B.process_args(args)))
elsif name =~ /(.*)=$/
assign($1, B.process_args(args)[0])
elsif (@jsvalue.undefined?)
raise "Cannot extract property '#{name}' from undefined object"
elsif ((member = @jsvalue.getProperty(name)).function? && args.size > 0)
B.invoke(@jsvalue, member, *(B.process_args2(args)))
else
JSObject.build(member, @jsvalue)
end
end
|
Instance Attribute Details
#jsvalue ⇒ Object
Returns the value of attribute jsvalue.
28
29
30
|
# File 'lib/jx/jsobject.rb', line 28
def jsvalue
@jsvalue
end
|
Class Method Details
.build(jsvalue, scope = B.document) ⇒ Object
Builds a new Ruby JSObject or one of its more specific subclasses from the given java jsvalue
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/jx/jsobject.rb', line 36
def self.build(jsvalue, scope = B.document)
if (jsvalue.isBoolean())
jsvalue.getBooleanValue()
elsif (jsvalue.isBooleanObject())
jsvalue.getBooleanValue()
elsif (jsvalue.isNumber())
jsvalue.getNumberValue()
elsif (jsvalue.isNumberObject())
jsvalue.getNumberValue()
elsif (jsvalue.isString())
jsvalue.getStringValue()
elsif (jsvalue.isStringObject())
jsvalue.getStringValue()
elsif (jsvalue.isArray())
JSArray.new(jsvalue.asArray(), scope)
elsif (jsvalue.isFunction())
JSFunction.new(jsvalue.asFunction(), scope)
elsif (jsvalue.isObject())
JSObject.new(jsvalue, scope)
elsif (jsvalue.isUndefined())
JSUndefined.new(jsvalue, scope)
elsif (jsvalue.is_a? Java::ComTeamdevJxbrowserChromium::am)
raise "This is probably a Symbol"
else
raise "Unknown jsvalue type #{jsvalue}"
end
end
|
Instance Method Details
#array? ⇒ Boolean
132
133
134
|
# File 'lib/jx/jsobject.rb', line 132
def array?
false
end
|
#assign(property_name, data) ⇒ Object
97
98
99
|
# File 'lib/jx/jsobject.rb', line 97
def assign(property_name, data)
@jsvalue.setProperty(property_name, data)
end
|
#boolean? ⇒ Boolean
136
137
138
|
# File 'lib/jx/jsobject.rb', line 136
def boolean?
false
end
|
#boolean_object? ⇒ Boolean
140
141
142
|
# File 'lib/jx/jsobject.rb', line 140
def boolean_object?
false
end
|
#function? ⇒ Boolean
144
145
146
|
# File 'lib/jx/jsobject.rb', line 144
def function?
false
end
|
#instanceof(constructor) ⇒ Object
89
90
91
|
# File 'lib/jx/jsobject.rb', line 89
def instanceof(constructor)
B.rr.instanceOf(@jsvalue, constructor.jsvalue)
end
|
#nil? ⇒ Boolean
148
149
150
|
# File 'lib/jx/jsobject.rb', line 148
def nil?
false
end
|
#number? ⇒ Boolean
152
153
154
|
# File 'lib/jx/jsobject.rb', line 152
def number?
false
end
|
#number_object? ⇒ Boolean
156
157
158
|
# File 'lib/jx/jsobject.rb', line 156
def number_object?
false
end
|
#object? ⇒ Boolean
160
161
162
|
# File 'lib/jx/jsobject.rb', line 160
def object?
true
end
|
#string? ⇒ Boolean
164
165
166
|
# File 'lib/jx/jsobject.rb', line 164
def string?
false
end
|
#string_object? ⇒ Boolean
168
169
170
|
# File 'lib/jx/jsobject.rb', line 168
def string_object?
false
end
|
#typeof ⇒ Object
81
82
83
|
# File 'lib/jx/jsobject.rb', line 81
def typeof
B.push("object")
end
|
#undefined? ⇒ Boolean
172
173
174
|
# File 'lib/jx/jsobject.rb', line 172
def undefined?
false
end
|