forked from mongodb-forks/goja
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobject_lazy.go
332 lines (275 loc) · 7.62 KB
/
object_lazy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
package goja
import (
"reflect"
"github.com/dop251/goja/unistring"
)
type lazyObject struct {
val *Object
create func(*Object) objectImpl
}
func (o *lazyObject) className() string {
obj := o.create(o.val)
o.val.self = obj
return obj.className()
}
func (o *lazyObject) typeOf() valueString {
obj := o.create(o.val)
o.val.self = obj
return obj.typeOf()
}
func (o *lazyObject) getIdx(p valueInt, receiver Value) Value {
obj := o.create(o.val)
o.val.self = obj
return obj.getIdx(p, receiver)
}
func (o *lazyObject) getSym(p *Symbol, receiver Value) Value {
obj := o.create(o.val)
o.val.self = obj
return obj.getSym(p, receiver)
}
func (o *lazyObject) getOwnPropIdx(idx valueInt) Value {
obj := o.create(o.val)
o.val.self = obj
return obj.getOwnPropIdx(idx)
}
func (o *lazyObject) getOwnPropSym(s *Symbol) Value {
obj := o.create(o.val)
o.val.self = obj
return obj.getOwnPropSym(s)
}
func (o *lazyObject) hasPropertyIdx(idx valueInt) bool {
obj := o.create(o.val)
o.val.self = obj
return obj.hasPropertyIdx(idx)
}
func (o *lazyObject) hasPropertySym(s *Symbol) bool {
obj := o.create(o.val)
o.val.self = obj
return obj.hasPropertySym(s)
}
func (o *lazyObject) hasOwnPropertyIdx(idx valueInt) bool {
obj := o.create(o.val)
o.val.self = obj
return obj.hasOwnPropertyIdx(idx)
}
func (o *lazyObject) hasOwnPropertySym(s *Symbol) bool {
obj := o.create(o.val)
o.val.self = obj
return obj.hasOwnPropertySym(s)
}
func (o *lazyObject) defineOwnPropertyStr(name unistring.String, desc PropertyDescriptor, throw bool) bool {
obj := o.create(o.val)
o.val.self = obj
return obj.defineOwnPropertyStr(name, desc, throw)
}
func (o *lazyObject) defineOwnPropertyIdx(name valueInt, desc PropertyDescriptor, throw bool) bool {
obj := o.create(o.val)
o.val.self = obj
return obj.defineOwnPropertyIdx(name, desc, throw)
}
func (o *lazyObject) defineOwnPropertySym(name *Symbol, desc PropertyDescriptor, throw bool) bool {
obj := o.create(o.val)
o.val.self = obj
return obj.defineOwnPropertySym(name, desc, throw)
}
func (o *lazyObject) deleteIdx(idx valueInt, throw bool) bool {
obj := o.create(o.val)
o.val.self = obj
return obj.deleteIdx(idx, throw)
}
func (o *lazyObject) deleteSym(s *Symbol, throw bool) bool {
obj := o.create(o.val)
o.val.self = obj
return obj.deleteSym(s, throw)
}
func (o *lazyObject) getStr(name unistring.String, receiver Value) Value {
obj := o.create(o.val)
o.val.self = obj
return obj.getStr(name, receiver)
}
func (o *lazyObject) getOwnPropStr(name unistring.String) Value {
obj := o.create(o.val)
o.val.self = obj
return obj.getOwnPropStr(name)
}
func (o *lazyObject) setOwnStr(p unistring.String, v Value, throw bool) bool {
obj := o.create(o.val)
o.val.self = obj
return obj.setOwnStr(p, v, throw)
}
func (o *lazyObject) setOwnIdx(p valueInt, v Value, throw bool) bool {
obj := o.create(o.val)
o.val.self = obj
return obj.setOwnIdx(p, v, throw)
}
func (o *lazyObject) setOwnSym(p *Symbol, v Value, throw bool) bool {
obj := o.create(o.val)
o.val.self = obj
return obj.setOwnSym(p, v, throw)
}
func (o *lazyObject) setForeignStr(p unistring.String, v, receiver Value, throw bool) (bool, bool) {
obj := o.create(o.val)
o.val.self = obj
return obj.setForeignStr(p, v, receiver, throw)
}
func (o *lazyObject) setForeignIdx(p valueInt, v, receiver Value, throw bool) (bool, bool) {
obj := o.create(o.val)
o.val.self = obj
return obj.setForeignIdx(p, v, receiver, throw)
}
func (o *lazyObject) setForeignSym(p *Symbol, v, receiver Value, throw bool) (bool, bool) {
obj := o.create(o.val)
o.val.self = obj
return obj.setForeignSym(p, v, receiver, throw)
}
func (o *lazyObject) hasPropertyStr(name unistring.String) bool {
obj := o.create(o.val)
o.val.self = obj
return obj.hasPropertyStr(name)
}
func (o *lazyObject) hasOwnPropertyStr(name unistring.String) bool {
obj := o.create(o.val)
o.val.self = obj
return obj.hasOwnPropertyStr(name)
}
func (o *lazyObject) _putProp(unistring.String, Value, bool, bool, bool) Value {
panic("cannot use _putProp() in lazy object")
}
func (o *lazyObject) _putSym(*Symbol, Value) {
panic("cannot use _putSym() in lazy object")
}
func (o *lazyObject) toPrimitiveNumber() Value {
obj := o.create(o.val)
o.val.self = obj
return obj.toPrimitiveNumber()
}
func (o *lazyObject) toPrimitiveString() Value {
obj := o.create(o.val)
o.val.self = obj
return obj.toPrimitiveString()
}
func (o *lazyObject) toPrimitive() Value {
obj := o.create(o.val)
o.val.self = obj
return obj.toPrimitive()
}
func (o *lazyObject) assertCallable() (call func(FunctionCall) Value, ok bool) {
obj := o.create(o.val)
o.val.self = obj
return obj.assertCallable()
}
func (o *lazyObject) vmCall(vm *vm, n int) {
obj := o.create(o.val)
o.val.self = obj
obj.vmCall(vm, n)
}
func (o *lazyObject) assertConstructor() func(args []Value, newTarget *Object) *Object {
obj := o.create(o.val)
o.val.self = obj
return obj.assertConstructor()
}
func (o *lazyObject) deleteStr(name unistring.String, throw bool) bool {
obj := o.create(o.val)
o.val.self = obj
return obj.deleteStr(name, throw)
}
func (o *lazyObject) proto() *Object {
obj := o.create(o.val)
o.val.self = obj
return obj.proto()
}
func (o *lazyObject) hasInstance(v Value) bool {
obj := o.create(o.val)
o.val.self = obj
return obj.hasInstance(v)
}
func (o *lazyObject) isExtensible() bool {
obj := o.create(o.val)
o.val.self = obj
return obj.isExtensible()
}
func (o *lazyObject) preventExtensions(throw bool) bool {
obj := o.create(o.val)
o.val.self = obj
return obj.preventExtensions(throw)
}
func (o *lazyObject) iterateStringKeys() iterNextFunc {
obj := o.create(o.val)
o.val.self = obj
return obj.iterateStringKeys()
}
func (o *lazyObject) iterateSymbols() iterNextFunc {
obj := o.create(o.val)
o.val.self = obj
return obj.iterateSymbols()
}
func (o *lazyObject) iterateKeys() iterNextFunc {
obj := o.create(o.val)
o.val.self = obj
return obj.iterateKeys()
}
func (o *lazyObject) export(ctx *objectExportCtx) interface{} {
obj := o.create(o.val)
o.val.self = obj
return obj.export(ctx)
}
func (o *lazyObject) exportType() reflect.Type {
obj := o.create(o.val)
o.val.self = obj
return obj.exportType()
}
func (o *lazyObject) exportToMap(m reflect.Value, typ reflect.Type, ctx *objectExportCtx) error {
obj := o.create(o.val)
o.val.self = obj
return obj.exportToMap(m, typ, ctx)
}
func (o *lazyObject) exportToArrayOrSlice(s reflect.Value, typ reflect.Type, ctx *objectExportCtx) error {
obj := o.create(o.val)
o.val.self = obj
return obj.exportToArrayOrSlice(s, typ, ctx)
}
func (o *lazyObject) equal(other objectImpl) bool {
obj := o.create(o.val)
o.val.self = obj
return obj.equal(other)
}
func (o *lazyObject) stringKeys(all bool, accum []Value) []Value {
obj := o.create(o.val)
o.val.self = obj
return obj.stringKeys(all, accum)
}
func (o *lazyObject) symbols(all bool, accum []Value) []Value {
obj := o.create(o.val)
o.val.self = obj
return obj.symbols(all, accum)
}
func (o *lazyObject) keys(all bool, accum []Value) []Value {
obj := o.create(o.val)
o.val.self = obj
return obj.keys(all, accum)
}
func (o *lazyObject) setProto(proto *Object, throw bool) bool {
obj := o.create(o.val)
o.val.self = obj
return obj.setProto(proto, throw)
}
func (o *lazyObject) getPrivateEnv(typ *privateEnvType, create bool) *privateElements {
obj := o.create(o.val)
o.val.self = obj
return obj.getPrivateEnv(typ, create)
}
func (o *lazyObject) sortLen() int {
obj := o.create(o.val)
o.val.self = obj
return obj.sortLen()
}
func (o *lazyObject) sortGet(i int) Value {
obj := o.create(o.val)
o.val.self = obj
return obj.sortGet(i)
}
func (o *lazyObject) swap(i int, j int) {
obj := o.create(o.val)
o.val.self = obj
obj.swap(i, j)
}