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