builtin_array.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. package otto
  2. import (
  3. "strconv"
  4. "strings"
  5. )
  6. // Array
  7. func builtinArray(call FunctionCall) Value {
  8. return toValue_object(builtinNewArrayNative(call.runtime, call.ArgumentList))
  9. }
  10. func builtinNewArray(self *_object, argumentList []Value) Value {
  11. return toValue_object(builtinNewArrayNative(self.runtime, argumentList))
  12. }
  13. func builtinNewArrayNative(runtime *_runtime, argumentList []Value) *_object {
  14. if len(argumentList) == 1 {
  15. firstArgument := argumentList[0]
  16. if firstArgument.IsNumber() {
  17. return runtime.newArray(arrayUint32(runtime, firstArgument))
  18. }
  19. }
  20. return runtime.newArrayOf(argumentList)
  21. }
  22. func builtinArray_toString(call FunctionCall) Value {
  23. thisObject := call.thisObject()
  24. join := thisObject.get("join")
  25. if join.isCallable() {
  26. join := join._object()
  27. return join.call(call.This, call.ArgumentList, false, nativeFrame)
  28. }
  29. return builtinObject_toString(call)
  30. }
  31. func builtinArray_toLocaleString(call FunctionCall) Value {
  32. separator := ","
  33. thisObject := call.thisObject()
  34. length := int64(toUint32(thisObject.get("length")))
  35. if length == 0 {
  36. return toValue_string("")
  37. }
  38. stringList := make([]string, 0, length)
  39. for index := int64(0); index < length; index += 1 {
  40. value := thisObject.get(arrayIndexToString(index))
  41. stringValue := ""
  42. switch value.kind {
  43. case valueEmpty, valueUndefined, valueNull:
  44. default:
  45. object := call.runtime.toObject(value)
  46. toLocaleString := object.get("toLocaleString")
  47. if !toLocaleString.isCallable() {
  48. panic(call.runtime.panicTypeError())
  49. }
  50. stringValue = toLocaleString.call(call.runtime, toValue_object(object)).string()
  51. }
  52. stringList = append(stringList, stringValue)
  53. }
  54. return toValue_string(strings.Join(stringList, separator))
  55. }
  56. func builtinArray_concat(call FunctionCall) Value {
  57. thisObject := call.thisObject()
  58. valueArray := []Value{}
  59. source := append([]Value{toValue_object(thisObject)}, call.ArgumentList...)
  60. for _, item := range source {
  61. switch item.kind {
  62. case valueObject:
  63. object := item._object()
  64. if isArray(object) {
  65. length := object.get("length").number().int64
  66. for index := int64(0); index < length; index += 1 {
  67. name := strconv.FormatInt(index, 10)
  68. if object.hasProperty(name) {
  69. valueArray = append(valueArray, object.get(name))
  70. } else {
  71. valueArray = append(valueArray, Value{})
  72. }
  73. }
  74. continue
  75. }
  76. fallthrough
  77. default:
  78. valueArray = append(valueArray, item)
  79. }
  80. }
  81. return toValue_object(call.runtime.newArrayOf(valueArray))
  82. }
  83. func builtinArray_shift(call FunctionCall) Value {
  84. thisObject := call.thisObject()
  85. length := int64(toUint32(thisObject.get("length")))
  86. if 0 == length {
  87. thisObject.put("length", toValue_int64(0), true)
  88. return Value{}
  89. }
  90. first := thisObject.get("0")
  91. for index := int64(1); index < length; index++ {
  92. from := arrayIndexToString(index)
  93. to := arrayIndexToString(index - 1)
  94. if thisObject.hasProperty(from) {
  95. thisObject.put(to, thisObject.get(from), true)
  96. } else {
  97. thisObject.delete(to, true)
  98. }
  99. }
  100. thisObject.delete(arrayIndexToString(length-1), true)
  101. thisObject.put("length", toValue_int64(length-1), true)
  102. return first
  103. }
  104. func builtinArray_push(call FunctionCall) Value {
  105. thisObject := call.thisObject()
  106. itemList := call.ArgumentList
  107. index := int64(toUint32(thisObject.get("length")))
  108. for len(itemList) > 0 {
  109. thisObject.put(arrayIndexToString(index), itemList[0], true)
  110. itemList = itemList[1:]
  111. index += 1
  112. }
  113. length := toValue_int64(index)
  114. thisObject.put("length", length, true)
  115. return length
  116. }
  117. func builtinArray_pop(call FunctionCall) Value {
  118. thisObject := call.thisObject()
  119. length := int64(toUint32(thisObject.get("length")))
  120. if 0 == length {
  121. thisObject.put("length", toValue_uint32(0), true)
  122. return Value{}
  123. }
  124. last := thisObject.get(arrayIndexToString(length - 1))
  125. thisObject.delete(arrayIndexToString(length-1), true)
  126. thisObject.put("length", toValue_int64(length-1), true)
  127. return last
  128. }
  129. func builtinArray_join(call FunctionCall) Value {
  130. separator := ","
  131. {
  132. argument := call.Argument(0)
  133. if argument.IsDefined() {
  134. separator = argument.string()
  135. }
  136. }
  137. thisObject := call.thisObject()
  138. length := int64(toUint32(thisObject.get("length")))
  139. if length == 0 {
  140. return toValue_string("")
  141. }
  142. stringList := make([]string, 0, length)
  143. for index := int64(0); index < length; index += 1 {
  144. value := thisObject.get(arrayIndexToString(index))
  145. stringValue := ""
  146. switch value.kind {
  147. case valueEmpty, valueUndefined, valueNull:
  148. default:
  149. stringValue = value.string()
  150. }
  151. stringList = append(stringList, stringValue)
  152. }
  153. return toValue_string(strings.Join(stringList, separator))
  154. }
  155. func builtinArray_splice(call FunctionCall) Value {
  156. thisObject := call.thisObject()
  157. length := int64(toUint32(thisObject.get("length")))
  158. start := valueToRangeIndex(call.Argument(0), length, false)
  159. deleteCount := valueToRangeIndex(call.Argument(1), int64(length)-start, true)
  160. valueArray := make([]Value, deleteCount)
  161. for index := int64(0); index < deleteCount; index++ {
  162. indexString := arrayIndexToString(int64(start + index))
  163. if thisObject.hasProperty(indexString) {
  164. valueArray[index] = thisObject.get(indexString)
  165. }
  166. }
  167. // 0, <1, 2, 3, 4>, 5, 6, 7
  168. // a, b
  169. // length 8 - delete 4 @ start 1
  170. itemList := []Value{}
  171. itemCount := int64(len(call.ArgumentList))
  172. if itemCount > 2 {
  173. itemCount -= 2 // Less the first two arguments
  174. itemList = call.ArgumentList[2:]
  175. } else {
  176. itemCount = 0
  177. }
  178. if itemCount < deleteCount {
  179. // The Object/Array is shrinking
  180. stop := int64(length) - deleteCount
  181. // The new length of the Object/Array before
  182. // appending the itemList remainder
  183. // Stopping at the lower bound of the insertion:
  184. // Move an item from the after the deleted portion
  185. // to a position after the inserted portion
  186. for index := start; index < stop; index++ {
  187. from := arrayIndexToString(index + deleteCount) // Position just after deletion
  188. to := arrayIndexToString(index + itemCount) // Position just after splice (insertion)
  189. if thisObject.hasProperty(from) {
  190. thisObject.put(to, thisObject.get(from), true)
  191. } else {
  192. thisObject.delete(to, true)
  193. }
  194. }
  195. // Delete off the end
  196. // We don't bother to delete below <stop + itemCount> (if any) since those
  197. // will be overwritten anyway
  198. for index := int64(length); index > (stop + itemCount); index-- {
  199. thisObject.delete(arrayIndexToString(index-1), true)
  200. }
  201. } else if itemCount > deleteCount {
  202. // The Object/Array is growing
  203. // The itemCount is greater than the deleteCount, so we do
  204. // not have to worry about overwriting what we should be moving
  205. // ---
  206. // Starting from the upper bound of the deletion:
  207. // Move an item from the after the deleted portion
  208. // to a position after the inserted portion
  209. for index := int64(length) - deleteCount; index > start; index-- {
  210. from := arrayIndexToString(index + deleteCount - 1)
  211. to := arrayIndexToString(index + itemCount - 1)
  212. if thisObject.hasProperty(from) {
  213. thisObject.put(to, thisObject.get(from), true)
  214. } else {
  215. thisObject.delete(to, true)
  216. }
  217. }
  218. }
  219. for index := int64(0); index < itemCount; index++ {
  220. thisObject.put(arrayIndexToString(index+start), itemList[index], true)
  221. }
  222. thisObject.put("length", toValue_int64(int64(length)+itemCount-deleteCount), true)
  223. return toValue_object(call.runtime.newArrayOf(valueArray))
  224. }
  225. func builtinArray_slice(call FunctionCall) Value {
  226. thisObject := call.thisObject()
  227. length := int64(toUint32(thisObject.get("length")))
  228. start, end := rangeStartEnd(call.ArgumentList, length, false)
  229. if start >= end {
  230. // Always an empty array
  231. return toValue_object(call.runtime.newArray(0))
  232. }
  233. sliceLength := end - start
  234. sliceValueArray := make([]Value, sliceLength)
  235. for index := int64(0); index < sliceLength; index++ {
  236. from := arrayIndexToString(index + start)
  237. if thisObject.hasProperty(from) {
  238. sliceValueArray[index] = thisObject.get(from)
  239. }
  240. }
  241. return toValue_object(call.runtime.newArrayOf(sliceValueArray))
  242. }
  243. func builtinArray_unshift(call FunctionCall) Value {
  244. thisObject := call.thisObject()
  245. length := int64(toUint32(thisObject.get("length")))
  246. itemList := call.ArgumentList
  247. itemCount := int64(len(itemList))
  248. for index := length; index > 0; index-- {
  249. from := arrayIndexToString(index - 1)
  250. to := arrayIndexToString(index + itemCount - 1)
  251. if thisObject.hasProperty(from) {
  252. thisObject.put(to, thisObject.get(from), true)
  253. } else {
  254. thisObject.delete(to, true)
  255. }
  256. }
  257. for index := int64(0); index < itemCount; index++ {
  258. thisObject.put(arrayIndexToString(index), itemList[index], true)
  259. }
  260. newLength := toValue_int64(length + itemCount)
  261. thisObject.put("length", newLength, true)
  262. return newLength
  263. }
  264. func builtinArray_reverse(call FunctionCall) Value {
  265. thisObject := call.thisObject()
  266. length := int64(toUint32(thisObject.get("length")))
  267. lower := struct {
  268. name string
  269. index int64
  270. exists bool
  271. }{}
  272. upper := lower
  273. lower.index = 0
  274. middle := length / 2 // Division will floor
  275. for lower.index != middle {
  276. lower.name = arrayIndexToString(lower.index)
  277. upper.index = length - lower.index - 1
  278. upper.name = arrayIndexToString(upper.index)
  279. lower.exists = thisObject.hasProperty(lower.name)
  280. upper.exists = thisObject.hasProperty(upper.name)
  281. if lower.exists && upper.exists {
  282. lowerValue := thisObject.get(lower.name)
  283. upperValue := thisObject.get(upper.name)
  284. thisObject.put(lower.name, upperValue, true)
  285. thisObject.put(upper.name, lowerValue, true)
  286. } else if !lower.exists && upper.exists {
  287. value := thisObject.get(upper.name)
  288. thisObject.delete(upper.name, true)
  289. thisObject.put(lower.name, value, true)
  290. } else if lower.exists && !upper.exists {
  291. value := thisObject.get(lower.name)
  292. thisObject.delete(lower.name, true)
  293. thisObject.put(upper.name, value, true)
  294. } else {
  295. // Nothing happens.
  296. }
  297. lower.index += 1
  298. }
  299. return call.This
  300. }
  301. func sortCompare(thisObject *_object, index0, index1 uint, compare *_object) int {
  302. j := struct {
  303. name string
  304. exists bool
  305. defined bool
  306. value string
  307. }{}
  308. k := j
  309. j.name = arrayIndexToString(int64(index0))
  310. j.exists = thisObject.hasProperty(j.name)
  311. k.name = arrayIndexToString(int64(index1))
  312. k.exists = thisObject.hasProperty(k.name)
  313. if !j.exists && !k.exists {
  314. return 0
  315. } else if !j.exists {
  316. return 1
  317. } else if !k.exists {
  318. return -1
  319. }
  320. x := thisObject.get(j.name)
  321. y := thisObject.get(k.name)
  322. j.defined = x.IsDefined()
  323. k.defined = y.IsDefined()
  324. if !j.defined && !k.defined {
  325. return 0
  326. } else if !j.defined {
  327. return 1
  328. } else if !k.defined {
  329. return -1
  330. }
  331. if compare == nil {
  332. j.value = x.string()
  333. k.value = y.string()
  334. if j.value == k.value {
  335. return 0
  336. } else if j.value < k.value {
  337. return -1
  338. }
  339. return 1
  340. }
  341. return int(toInt32(compare.call(Value{}, []Value{x, y}, false, nativeFrame)))
  342. }
  343. func arraySortSwap(thisObject *_object, index0, index1 uint) {
  344. j := struct {
  345. name string
  346. exists bool
  347. }{}
  348. k := j
  349. j.name = arrayIndexToString(int64(index0))
  350. j.exists = thisObject.hasProperty(j.name)
  351. k.name = arrayIndexToString(int64(index1))
  352. k.exists = thisObject.hasProperty(k.name)
  353. if j.exists && k.exists {
  354. jValue := thisObject.get(j.name)
  355. kValue := thisObject.get(k.name)
  356. thisObject.put(j.name, kValue, true)
  357. thisObject.put(k.name, jValue, true)
  358. } else if !j.exists && k.exists {
  359. value := thisObject.get(k.name)
  360. thisObject.delete(k.name, true)
  361. thisObject.put(j.name, value, true)
  362. } else if j.exists && !k.exists {
  363. value := thisObject.get(j.name)
  364. thisObject.delete(j.name, true)
  365. thisObject.put(k.name, value, true)
  366. } else {
  367. // Nothing happens.
  368. }
  369. }
  370. func arraySortQuickPartition(thisObject *_object, left, right, pivot uint, compare *_object) (uint, uint) {
  371. arraySortSwap(thisObject, pivot, right) // Right is now the pivot value
  372. cursor := left
  373. cursor2 := left
  374. for index := left; index < right; index++ {
  375. comparison := sortCompare(thisObject, index, right, compare) // Compare to the pivot value
  376. if comparison < 0 {
  377. arraySortSwap(thisObject, index, cursor)
  378. if cursor < cursor2 {
  379. arraySortSwap(thisObject, index, cursor2)
  380. }
  381. cursor += 1
  382. cursor2 += 1
  383. } else if comparison == 0 {
  384. arraySortSwap(thisObject, index, cursor2)
  385. cursor2 += 1
  386. }
  387. }
  388. arraySortSwap(thisObject, cursor2, right)
  389. return cursor, cursor2
  390. }
  391. func arraySortQuickSort(thisObject *_object, left, right uint, compare *_object) {
  392. if left < right {
  393. middle := left + (right-left)/2
  394. pivot, pivot2 := arraySortQuickPartition(thisObject, left, right, middle, compare)
  395. if pivot > 0 {
  396. arraySortQuickSort(thisObject, left, pivot-1, compare)
  397. }
  398. arraySortQuickSort(thisObject, pivot2+1, right, compare)
  399. }
  400. }
  401. func builtinArray_sort(call FunctionCall) Value {
  402. thisObject := call.thisObject()
  403. length := uint(toUint32(thisObject.get("length")))
  404. compareValue := call.Argument(0)
  405. compare := compareValue._object()
  406. if compareValue.IsUndefined() {
  407. } else if !compareValue.isCallable() {
  408. panic(call.runtime.panicTypeError())
  409. }
  410. if length > 1 {
  411. arraySortQuickSort(thisObject, 0, length-1, compare)
  412. }
  413. return call.This
  414. }
  415. func builtinArray_isArray(call FunctionCall) Value {
  416. return toValue_bool(isArray(call.Argument(0)._object()))
  417. }
  418. func builtinArray_indexOf(call FunctionCall) Value {
  419. thisObject, matchValue := call.thisObject(), call.Argument(0)
  420. if length := int64(toUint32(thisObject.get("length"))); length > 0 {
  421. index := int64(0)
  422. if len(call.ArgumentList) > 1 {
  423. index = call.Argument(1).number().int64
  424. }
  425. if index < 0 {
  426. if index += length; index < 0 {
  427. index = 0
  428. }
  429. } else if index >= length {
  430. index = -1
  431. }
  432. for ; index >= 0 && index < length; index++ {
  433. name := arrayIndexToString(int64(index))
  434. if !thisObject.hasProperty(name) {
  435. continue
  436. }
  437. value := thisObject.get(name)
  438. if strictEqualityComparison(matchValue, value) {
  439. return toValue_uint32(uint32(index))
  440. }
  441. }
  442. }
  443. return toValue_int(-1)
  444. }
  445. func builtinArray_lastIndexOf(call FunctionCall) Value {
  446. thisObject, matchValue := call.thisObject(), call.Argument(0)
  447. length := int64(toUint32(thisObject.get("length")))
  448. index := length - 1
  449. if len(call.ArgumentList) > 1 {
  450. index = call.Argument(1).number().int64
  451. }
  452. if 0 > index {
  453. index += length
  454. }
  455. if index > length {
  456. index = length - 1
  457. } else if 0 > index {
  458. return toValue_int(-1)
  459. }
  460. for ; index >= 0; index-- {
  461. name := arrayIndexToString(int64(index))
  462. if !thisObject.hasProperty(name) {
  463. continue
  464. }
  465. value := thisObject.get(name)
  466. if strictEqualityComparison(matchValue, value) {
  467. return toValue_uint32(uint32(index))
  468. }
  469. }
  470. return toValue_int(-1)
  471. }
  472. func builtinArray_every(call FunctionCall) Value {
  473. thisObject := call.thisObject()
  474. this := toValue_object(thisObject)
  475. if iterator := call.Argument(0); iterator.isCallable() {
  476. length := int64(toUint32(thisObject.get("length")))
  477. callThis := call.Argument(1)
  478. for index := int64(0); index < length; index++ {
  479. if key := arrayIndexToString(index); thisObject.hasProperty(key) {
  480. if value := thisObject.get(key); iterator.call(call.runtime, callThis, value, toValue_int64(index), this).bool() {
  481. continue
  482. }
  483. return falseValue
  484. }
  485. }
  486. return trueValue
  487. }
  488. panic(call.runtime.panicTypeError())
  489. }
  490. func builtinArray_some(call FunctionCall) Value {
  491. thisObject := call.thisObject()
  492. this := toValue_object(thisObject)
  493. if iterator := call.Argument(0); iterator.isCallable() {
  494. length := int64(toUint32(thisObject.get("length")))
  495. callThis := call.Argument(1)
  496. for index := int64(0); index < length; index++ {
  497. if key := arrayIndexToString(index); thisObject.hasProperty(key) {
  498. if value := thisObject.get(key); iterator.call(call.runtime, callThis, value, toValue_int64(index), this).bool() {
  499. return trueValue
  500. }
  501. }
  502. }
  503. return falseValue
  504. }
  505. panic(call.runtime.panicTypeError())
  506. }
  507. func builtinArray_forEach(call FunctionCall) Value {
  508. thisObject := call.thisObject()
  509. this := toValue_object(thisObject)
  510. if iterator := call.Argument(0); iterator.isCallable() {
  511. length := int64(toUint32(thisObject.get("length")))
  512. callThis := call.Argument(1)
  513. for index := int64(0); index < length; index++ {
  514. if key := arrayIndexToString(index); thisObject.hasProperty(key) {
  515. iterator.call(call.runtime, callThis, thisObject.get(key), toValue_int64(index), this)
  516. }
  517. }
  518. return Value{}
  519. }
  520. panic(call.runtime.panicTypeError())
  521. }
  522. func builtinArray_map(call FunctionCall) Value {
  523. thisObject := call.thisObject()
  524. this := toValue_object(thisObject)
  525. if iterator := call.Argument(0); iterator.isCallable() {
  526. length := int64(toUint32(thisObject.get("length")))
  527. callThis := call.Argument(1)
  528. values := make([]Value, length)
  529. for index := int64(0); index < length; index++ {
  530. if key := arrayIndexToString(index); thisObject.hasProperty(key) {
  531. values[index] = iterator.call(call.runtime, callThis, thisObject.get(key), index, this)
  532. } else {
  533. values[index] = Value{}
  534. }
  535. }
  536. return toValue_object(call.runtime.newArrayOf(values))
  537. }
  538. panic(call.runtime.panicTypeError())
  539. }
  540. func builtinArray_filter(call FunctionCall) Value {
  541. thisObject := call.thisObject()
  542. this := toValue_object(thisObject)
  543. if iterator := call.Argument(0); iterator.isCallable() {
  544. length := int64(toUint32(thisObject.get("length")))
  545. callThis := call.Argument(1)
  546. values := make([]Value, 0)
  547. for index := int64(0); index < length; index++ {
  548. if key := arrayIndexToString(index); thisObject.hasProperty(key) {
  549. value := thisObject.get(key)
  550. if iterator.call(call.runtime, callThis, value, index, this).bool() {
  551. values = append(values, value)
  552. }
  553. }
  554. }
  555. return toValue_object(call.runtime.newArrayOf(values))
  556. }
  557. panic(call.runtime.panicTypeError())
  558. }
  559. func builtinArray_reduce(call FunctionCall) Value {
  560. thisObject := call.thisObject()
  561. this := toValue_object(thisObject)
  562. if iterator := call.Argument(0); iterator.isCallable() {
  563. initial := len(call.ArgumentList) > 1
  564. start := call.Argument(1)
  565. length := int64(toUint32(thisObject.get("length")))
  566. index := int64(0)
  567. if length > 0 || initial {
  568. var accumulator Value
  569. if !initial {
  570. for ; index < length; index++ {
  571. if key := arrayIndexToString(index); thisObject.hasProperty(key) {
  572. accumulator = thisObject.get(key)
  573. index++
  574. break
  575. }
  576. }
  577. } else {
  578. accumulator = start
  579. }
  580. for ; index < length; index++ {
  581. if key := arrayIndexToString(index); thisObject.hasProperty(key) {
  582. accumulator = iterator.call(call.runtime, Value{}, accumulator, thisObject.get(key), key, this)
  583. }
  584. }
  585. return accumulator
  586. }
  587. }
  588. panic(call.runtime.panicTypeError())
  589. }
  590. func builtinArray_reduceRight(call FunctionCall) Value {
  591. thisObject := call.thisObject()
  592. this := toValue_object(thisObject)
  593. if iterator := call.Argument(0); iterator.isCallable() {
  594. initial := len(call.ArgumentList) > 1
  595. start := call.Argument(1)
  596. length := int64(toUint32(thisObject.get("length")))
  597. if length > 0 || initial {
  598. index := length - 1
  599. var accumulator Value
  600. if !initial {
  601. for ; index >= 0; index-- {
  602. if key := arrayIndexToString(index); thisObject.hasProperty(key) {
  603. accumulator = thisObject.get(key)
  604. index--
  605. break
  606. }
  607. }
  608. } else {
  609. accumulator = start
  610. }
  611. for ; index >= 0; index-- {
  612. if key := arrayIndexToString(index); thisObject.hasProperty(key) {
  613. accumulator = iterator.call(call.runtime, Value{}, accumulator, thisObject.get(key), key, this)
  614. }
  615. }
  616. return accumulator
  617. }
  618. }
  619. panic(call.runtime.panicTypeError())
  620. }