Module: RubyRunJs::JsObjectMethods
- Extended by:
- Helper
- Defined in:
- lib/ruby_run_js/object_methods/js_object.rb
Class Method Summary
collapse
-
.constructor(builtin, this, value) ⇒ Object
-
.constructor_create(builtin, this, obj, properties) ⇒ Object
-
.constructor_defineProperties(builtin, this, obj, properties) ⇒ Object
-
.constructor_defineProperty(builtin, this, obj, prop_name, attributes) ⇒ Object
-
.constructor_freeze(builtin, this, obj) ⇒ Object
-
.constructor_getOwnPropertyDescriptor(builtin, this, obj, prop_name) ⇒ Object
-
.constructor_getOwnPropertyNames(builtin, this, obj) ⇒ JsArray
-
.constructor_getPrototypeOf(builtin, this, obj) ⇒ Object
-
.constructor_isExtensible(builtin, this, obj) ⇒ Object
-
.constructor_isFrozen(builtin, this, obj) ⇒ Object
-
.constructor_isSealed(builtin, this, obj) ⇒ Object
-
.constructor_keys(builtin, this, obj) ⇒ Object
-
.constructor_new(builtin, this, value) ⇒ Object
-
.constructor_preventExtensions(builtin, this, obj) ⇒ Object
-
.constructor_seal(builtin, this, obj) ⇒ Object
-
.prototype_hasOwnProperty(builtin, this, prop_name) ⇒ Object
-
.prototype_isPrototypeOf(builtin, this, obj) ⇒ Object
-
.prototype_propertyIsEnumerable(builtin, this, prop_name) ⇒ Object
-
.prototype_toLocaleString(builtin, this) ⇒ Object
-
.prototype_toString(builtin, this) ⇒ Object
-
.prototype_valueOf(builtin, this) ⇒ Object
Methods included from Helper
check_object, get_member, get_member_dot, is_accessor_descriptor, is_callable, is_data_descriptor, is_generic_descriptor, is_primitive, make_error, strict_equality
#convert_to_js_type, #to_boolean, #to_int32, #to_integer, #to_number, #to_object, #to_primitive, #to_string, #to_uint16, #to_uint32
Class Method Details
.constructor(builtin, this, value) ⇒ Object
11
12
13
14
15
16
|
# File 'lib/ruby_run_js/object_methods/js_object.rb', line 11
def constructor(builtin, this, value)
if value == null || value == undefined
return constructor_new(builtin, this, value)
end
to_object(value, builtin)
end
|
.constructor_create(builtin, this, obj, properties) ⇒ Object
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/ruby_run_js/object_methods/js_object.rb', line 58
def constructor_create(builtin, this, obj, properties)
if obj.js_type != :Object && obj.js_type != :Null
raise make_error('TypeError', 'Object.create called on non-object prototype')
end
result = JsObject.new(obj == null ? nil : obj)
unless properties == undefined
constructor_defineProperties(builtin, this, result, properties)
end
result
end
|
.constructor_defineProperties(builtin, this, obj, properties) ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/ruby_run_js/object_methods/js_object.rb', line 77
def constructor_defineProperties(builtin, this, obj, properties)
if obj.js_type != :Object
raise make_error('TypeError', 'Object.defineProperties called on non-object')
end
props = to_object(properties, builtin)
props.own.each do |k, v|
unless v['enumerable']
next
end
desc = toPropertyDescriptor(v)
obj.define_own_property(k, desc, true)
end
obj
end
|
.constructor_defineProperty(builtin, this, obj, prop_name, attributes) ⇒ Object
69
70
71
72
73
74
75
|
# File 'lib/ruby_run_js/object_methods/js_object.rb', line 69
def constructor_defineProperty(builtin, this, obj, prop_name, attributes)
if obj.js_type != :Object
raise make_error('TypeError', 'Object.defineProperty called on non-object')
end
obj.define_own_property(to_string(prop_name), toPropertyDescriptor(attributes), true)
obj
end
|
.constructor_freeze(builtin, this, obj) ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/ruby_run_js/object_methods/js_object.rb', line 106
def constructor_freeze(builtin, this, obj)
if obj.js_type != :Object
raise make_error('TypeError', 'Object.freeze called on non-object')
end
obj.own.each_value do |v|
v['configurable'] = false
if is_data_descriptor(v)
v['writable'] = false
end
end
obj.extensible = false
obj
end
|
.constructor_getOwnPropertyDescriptor(builtin, this, obj, prop_name) ⇒ Object
38
39
40
41
42
43
44
45
|
# File 'lib/ruby_run_js/object_methods/js_object.rb', line 38
def constructor_getOwnPropertyDescriptor(builtin, this, obj, prop_name)
if obj.js_type != :Object
raise make_error('TypeError', 'Object.getOwnPropertyDescriptor called on non-object')
end
prop_name = to_string(prop_name)
desc = obj.get_own_property(prop_name)
fromPropertyDescriptor(builtin, desc)
end
|
.constructor_getOwnPropertyNames(builtin, this, obj) ⇒ JsArray
49
50
51
52
53
54
55
56
|
# File 'lib/ruby_run_js/object_methods/js_object.rb', line 49
def constructor_getOwnPropertyNames(builtin, this, obj)
if obj.js_type != :Object
raise make_error('TypeError', 'Object.getOwnPropertyNames called on non-object')
end
array = builtin.new_array()
array.set_items(obj.own.keys)
array
end
|
.constructor_getPrototypeOf(builtin, this, obj) ⇒ Object
30
31
32
33
34
35
|
# File 'lib/ruby_run_js/object_methods/js_object.rb', line 30
def constructor_getPrototypeOf(builtin, this, obj)
if obj.js_type != :Object
raise make_error('TypeError', 'Object.getPrototypeOf called on non-object')
end
obj.prototype
end
|
.constructor_isExtensible(builtin, this, obj) ⇒ Object
151
152
153
154
155
156
|
# File 'lib/ruby_run_js/object_methods/js_object.rb', line 151
def constructor_isExtensible(builtin, this, obj)
if obj.js_type != :Object
raise make_error('TypeError', 'Object.isExtensible called on non-object')
end
obj.extensible
end
|
.constructor_isFrozen(builtin, this, obj) ⇒ Object
139
140
141
142
143
144
145
146
147
148
149
|
# File 'lib/ruby_run_js/object_methods/js_object.rb', line 139
def constructor_isFrozen(builtin, this, obj)
if obj.js_type != :Object
raise make_error('TypeError', 'Object.isFrozen called on non-object')
end
return false if obj.extensible
obj.own.each_value do |v|
return false if v['configurable']
return false if is_data_descriptor(v) && v['writable']
end
true
end
|
.constructor_isSealed(builtin, this, obj) ⇒ Object
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/ruby_run_js/object_methods/js_object.rb', line 128
def constructor_isSealed(builtin, this, obj)
if obj.js_type != :Object
raise make_error('TypeError', 'Object.isSealed called on non-object')
end
return false if obj.extensible
obj.own.each_value do |v|
return false if v['configurable']
end
true
end
|
.constructor_keys(builtin, this, obj) ⇒ Object
158
159
160
161
162
163
164
165
|
# File 'lib/ruby_run_js/object_methods/js_object.rb', line 158
def constructor_keys(builtin, this, obj)
if obj.js_type != :Object
raise make_error('TypeError', 'Object.keys called on non-object')
end
array = builtin.new_array()
array.set_items(obj.own.keys.filter { |k| obj.own[k]['enumerable'] })
array
end
|
.constructor_new(builtin, this, value) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/ruby_run_js/object_methods/js_object.rb', line 18
def constructor_new(builtin, this, value)
if value != undefined
case value.js_type
when :Object
return value
when :String, :Boolean, :Number
return to_object(value, builtin)
end
end
builtin.new_object
end
|
.constructor_preventExtensions(builtin, this, obj) ⇒ Object
120
121
122
123
124
125
126
|
# File 'lib/ruby_run_js/object_methods/js_object.rb', line 120
def constructor_preventExtensions(builtin, this, obj)
if obj.js_type != :Object
raise make_error('TypeError', 'Object.preventExtensions called on non-object')
end
obj.extensible = false
obj
end
|
.constructor_seal(builtin, this, obj) ⇒ Object
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/ruby_run_js/object_methods/js_object.rb', line 94
def constructor_seal(builtin, this, obj)
if obj.js_type != :Object
raise make_error('TypeError', 'Object.seal called on non-object')
end
obj.own.each_value do |v|
v['configurable'] = false
end
obj.extensible = false
obj
end
|
.prototype_hasOwnProperty(builtin, this, prop_name) ⇒ Object
184
185
186
187
|
# File 'lib/ruby_run_js/object_methods/js_object.rb', line 184
def prototype_hasOwnProperty(builtin, this, prop_name)
o = to_object(this, builtin)
o.get_own_property(to_string(prop_name)) != undefined
end
|
.prototype_isPrototypeOf(builtin, this, obj) ⇒ Object
191
192
193
194
195
196
197
198
199
|
# File 'lib/ruby_run_js/object_methods/js_object.rb', line 191
def prototype_isPrototypeOf(builtin, this, obj)
return false if obj.js_type != :Object
o = to_object(this, builtin)
loop do
obj = obj.prototype
return false if obj.nil? || obj == null
return true if obj == o
end
end
|
.prototype_propertyIsEnumerable(builtin, this, prop_name) ⇒ Object
201
202
203
204
205
206
|
# File 'lib/ruby_run_js/object_methods/js_object.rb', line 201
def prototype_propertyIsEnumerable(builtin, this, prop_name)
o = to_object(this, builtin)
desc = o.get_own_property(to_string(prop_name))
return false if desc == undefined
desc['enumerable']
end
|
.prototype_toLocaleString(builtin, this) ⇒ Object
175
176
177
178
179
180
181
182
|
# File 'lib/ruby_run_js/object_methods/js_object.rb', line 175
def prototype_toLocaleString(builtin, this)
o = to_object(this, builtin)
toString = o.get('toString')
unless is_callable(toString)
raise make_error('TypeError', 'toString of this is not callcable')
end
toString.call(this)
end
|
.prototype_toString(builtin, this) ⇒ Object
167
168
169
|
# File 'lib/ruby_run_js/object_methods/js_object.rb', line 167
def prototype_toString(builtin, this)
"[object #{this.js_class}]"
end
|
.prototype_valueOf(builtin, this) ⇒ Object
171
172
173
|
# File 'lib/ruby_run_js/object_methods/js_object.rb', line 171
def prototype_valueOf(builtin, this)
to_object(this, builtin)
end
|