object_lazy.go 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. package goja
  2. import (
  3. "reflect"
  4. "github.com/dop251/goja/unistring"
  5. )
  6. type lazyObject struct {
  7. val *Object
  8. create func(*Object) objectImpl
  9. }
  10. func (o *lazyObject) className() string {
  11. obj := o.create(o.val)
  12. o.val.self = obj
  13. return obj.className()
  14. }
  15. func (o *lazyObject) getIdx(p valueInt, receiver Value) Value {
  16. obj := o.create(o.val)
  17. o.val.self = obj
  18. return obj.getIdx(p, receiver)
  19. }
  20. func (o *lazyObject) getSym(p *Symbol, receiver Value) Value {
  21. obj := o.create(o.val)
  22. o.val.self = obj
  23. return obj.getSym(p, receiver)
  24. }
  25. func (o *lazyObject) getOwnPropIdx(idx valueInt) Value {
  26. obj := o.create(o.val)
  27. o.val.self = obj
  28. return obj.getOwnPropIdx(idx)
  29. }
  30. func (o *lazyObject) getOwnPropSym(s *Symbol) Value {
  31. obj := o.create(o.val)
  32. o.val.self = obj
  33. return obj.getOwnPropSym(s)
  34. }
  35. func (o *lazyObject) hasPropertyIdx(idx valueInt) bool {
  36. obj := o.create(o.val)
  37. o.val.self = obj
  38. return obj.hasPropertyIdx(idx)
  39. }
  40. func (o *lazyObject) hasPropertySym(s *Symbol) bool {
  41. obj := o.create(o.val)
  42. o.val.self = obj
  43. return obj.hasPropertySym(s)
  44. }
  45. func (o *lazyObject) hasOwnPropertyIdx(idx valueInt) bool {
  46. obj := o.create(o.val)
  47. o.val.self = obj
  48. return obj.hasOwnPropertyIdx(idx)
  49. }
  50. func (o *lazyObject) hasOwnPropertySym(s *Symbol) bool {
  51. obj := o.create(o.val)
  52. o.val.self = obj
  53. return obj.hasOwnPropertySym(s)
  54. }
  55. func (o *lazyObject) defineOwnPropertyStr(name unistring.String, desc PropertyDescriptor, throw bool) bool {
  56. obj := o.create(o.val)
  57. o.val.self = obj
  58. return obj.defineOwnPropertyStr(name, desc, throw)
  59. }
  60. func (o *lazyObject) defineOwnPropertyIdx(name valueInt, desc PropertyDescriptor, throw bool) bool {
  61. obj := o.create(o.val)
  62. o.val.self = obj
  63. return obj.defineOwnPropertyIdx(name, desc, throw)
  64. }
  65. func (o *lazyObject) defineOwnPropertySym(name *Symbol, desc PropertyDescriptor, throw bool) bool {
  66. obj := o.create(o.val)
  67. o.val.self = obj
  68. return obj.defineOwnPropertySym(name, desc, throw)
  69. }
  70. func (o *lazyObject) deleteIdx(idx valueInt, throw bool) bool {
  71. obj := o.create(o.val)
  72. o.val.self = obj
  73. return obj.deleteIdx(idx, throw)
  74. }
  75. func (o *lazyObject) deleteSym(s *Symbol, throw bool) bool {
  76. obj := o.create(o.val)
  77. o.val.self = obj
  78. return obj.deleteSym(s, throw)
  79. }
  80. func (o *lazyObject) getStr(name unistring.String, receiver Value) Value {
  81. obj := o.create(o.val)
  82. o.val.self = obj
  83. return obj.getStr(name, receiver)
  84. }
  85. func (o *lazyObject) getOwnPropStr(name unistring.String) Value {
  86. obj := o.create(o.val)
  87. o.val.self = obj
  88. return obj.getOwnPropStr(name)
  89. }
  90. func (o *lazyObject) setOwnStr(p unistring.String, v Value, throw bool) bool {
  91. obj := o.create(o.val)
  92. o.val.self = obj
  93. return obj.setOwnStr(p, v, throw)
  94. }
  95. func (o *lazyObject) setOwnIdx(p valueInt, v Value, throw bool) bool {
  96. obj := o.create(o.val)
  97. o.val.self = obj
  98. return obj.setOwnIdx(p, v, throw)
  99. }
  100. func (o *lazyObject) setOwnSym(p *Symbol, v Value, throw bool) bool {
  101. obj := o.create(o.val)
  102. o.val.self = obj
  103. return obj.setOwnSym(p, v, throw)
  104. }
  105. func (o *lazyObject) setForeignStr(p unistring.String, v, receiver Value, throw bool) (bool, bool) {
  106. obj := o.create(o.val)
  107. o.val.self = obj
  108. return obj.setForeignStr(p, v, receiver, throw)
  109. }
  110. func (o *lazyObject) setForeignIdx(p valueInt, v, receiver Value, throw bool) (bool, bool) {
  111. obj := o.create(o.val)
  112. o.val.self = obj
  113. return obj.setForeignIdx(p, v, receiver, throw)
  114. }
  115. func (o *lazyObject) setForeignSym(p *Symbol, v, receiver Value, throw bool) (bool, bool) {
  116. obj := o.create(o.val)
  117. o.val.self = obj
  118. return obj.setForeignSym(p, v, receiver, throw)
  119. }
  120. func (o *lazyObject) hasPropertyStr(name unistring.String) bool {
  121. obj := o.create(o.val)
  122. o.val.self = obj
  123. return obj.hasPropertyStr(name)
  124. }
  125. func (o *lazyObject) hasOwnPropertyStr(name unistring.String) bool {
  126. obj := o.create(o.val)
  127. o.val.self = obj
  128. return obj.hasOwnPropertyStr(name)
  129. }
  130. func (o *lazyObject) _putProp(unistring.String, Value, bool, bool, bool) Value {
  131. panic("cannot use _putProp() in lazy object")
  132. }
  133. func (o *lazyObject) _putSym(*Symbol, Value) {
  134. panic("cannot use _putSym() in lazy object")
  135. }
  136. func (o *lazyObject) toPrimitiveNumber() Value {
  137. obj := o.create(o.val)
  138. o.val.self = obj
  139. return obj.toPrimitiveNumber()
  140. }
  141. func (o *lazyObject) toPrimitiveString() Value {
  142. obj := o.create(o.val)
  143. o.val.self = obj
  144. return obj.toPrimitiveString()
  145. }
  146. func (o *lazyObject) toPrimitive() Value {
  147. obj := o.create(o.val)
  148. o.val.self = obj
  149. return obj.toPrimitive()
  150. }
  151. func (o *lazyObject) assertCallable() (call func(FunctionCall) Value, ok bool) {
  152. obj := o.create(o.val)
  153. o.val.self = obj
  154. return obj.assertCallable()
  155. }
  156. func (o *lazyObject) assertConstructor() func(args []Value, newTarget *Object) *Object {
  157. obj := o.create(o.val)
  158. o.val.self = obj
  159. return obj.assertConstructor()
  160. }
  161. func (o *lazyObject) deleteStr(name unistring.String, throw bool) bool {
  162. obj := o.create(o.val)
  163. o.val.self = obj
  164. return obj.deleteStr(name, throw)
  165. }
  166. func (o *lazyObject) proto() *Object {
  167. obj := o.create(o.val)
  168. o.val.self = obj
  169. return obj.proto()
  170. }
  171. func (o *lazyObject) hasInstance(v Value) bool {
  172. obj := o.create(o.val)
  173. o.val.self = obj
  174. return obj.hasInstance(v)
  175. }
  176. func (o *lazyObject) isExtensible() bool {
  177. obj := o.create(o.val)
  178. o.val.self = obj
  179. return obj.isExtensible()
  180. }
  181. func (o *lazyObject) preventExtensions(throw bool) bool {
  182. obj := o.create(o.val)
  183. o.val.self = obj
  184. return obj.preventExtensions(throw)
  185. }
  186. func (o *lazyObject) iterateStringKeys() iterNextFunc {
  187. obj := o.create(o.val)
  188. o.val.self = obj
  189. return obj.iterateStringKeys()
  190. }
  191. func (o *lazyObject) iterateSymbols() iterNextFunc {
  192. obj := o.create(o.val)
  193. o.val.self = obj
  194. return obj.iterateSymbols()
  195. }
  196. func (o *lazyObject) iterateKeys() iterNextFunc {
  197. obj := o.create(o.val)
  198. o.val.self = obj
  199. return obj.iterateKeys()
  200. }
  201. func (o *lazyObject) export(ctx *objectExportCtx) interface{} {
  202. obj := o.create(o.val)
  203. o.val.self = obj
  204. return obj.export(ctx)
  205. }
  206. func (o *lazyObject) exportType() reflect.Type {
  207. obj := o.create(o.val)
  208. o.val.self = obj
  209. return obj.exportType()
  210. }
  211. func (o *lazyObject) equal(other objectImpl) bool {
  212. obj := o.create(o.val)
  213. o.val.self = obj
  214. return obj.equal(other)
  215. }
  216. func (o *lazyObject) stringKeys(all bool, accum []Value) []Value {
  217. obj := o.create(o.val)
  218. o.val.self = obj
  219. return obj.stringKeys(all, accum)
  220. }
  221. func (o *lazyObject) symbols(all bool, accum []Value) []Value {
  222. obj := o.create(o.val)
  223. o.val.self = obj
  224. return obj.symbols(all, accum)
  225. }
  226. func (o *lazyObject) keys(all bool, accum []Value) []Value {
  227. obj := o.create(o.val)
  228. o.val.self = obj
  229. return obj.keys(all, accum)
  230. }
  231. func (o *lazyObject) setProto(proto *Object, throw bool) bool {
  232. obj := o.create(o.val)
  233. o.val.self = obj
  234. return obj.setProto(proto, throw)
  235. }
  236. func (o *lazyObject) sortLen() int64 {
  237. obj := o.create(o.val)
  238. o.val.self = obj
  239. return obj.sortLen()
  240. }
  241. func (o *lazyObject) sortGet(i int64) Value {
  242. obj := o.create(o.val)
  243. o.val.self = obj
  244. return obj.sortGet(i)
  245. }
  246. func (o *lazyObject) swap(i, j int64) {
  247. obj := o.create(o.val)
  248. o.val.self = obj
  249. obj.swap(i, j)
  250. }