MCPcopy Create free account
hub / github.com/dop251/goja / _defineIdxProperty

Method _defineIdxProperty

array_sparse.go:339–374  ·  view source on GitHub ↗
(idx uint32, desc PropertyDescriptor, throw bool)

Source from the content-addressed store, hash-verified

337}
338
339func (a *sparseArrayObject) _defineIdxProperty(idx uint32, desc PropertyDescriptor, throw bool) bool {
340 var existing Value
341 i := a.findIdx(idx)
342 if i < len(a.items) && a.items[i].idx == idx {
343 existing = a.items[i].value
344 }
345 prop, ok := a.baseObject._defineOwnProperty(unistring.String(strconv.FormatUint(uint64(idx), 10)), existing, desc, throw)
346 if ok {
347 if idx >= a.length {
348 if !a.setLengthInt(idx+1, throw) {
349 return false
350 }
351 }
352 if i >= len(a.items) || a.items[i].idx != idx {
353 if a.expand(idx) {
354 a.items = append(a.items, sparseArrayItem{})
355 copy(a.items[i+1:], a.items[i:])
356 a.items[i] = sparseArrayItem{
357 idx: idx,
358 value: prop,
359 }
360 if idx >= a.length {
361 a.length = idx + 1
362 }
363 } else {
364 a.val.self.(*arrayObject).values[idx] = prop
365 }
366 } else {
367 a.items[i].value = prop
368 }
369 if _, ok := prop.(*valueProperty); ok {
370 a.propValueCount++
371 }
372 }
373 return ok
374}
375
376func (a *sparseArrayObject) defineOwnPropertyStr(name unistring.String, descr PropertyDescriptor, throw bool) bool {
377 if idx := strToArrayIdx(name); idx != math.MaxUint32 {

Callers 2

defineOwnPropertyStrMethod · 0.95
defineOwnPropertyIdxMethod · 0.95

Calls 5

findIdxMethod · 0.95
setLengthIntMethod · 0.95
expandMethod · 0.95
StringTypeAlias · 0.92
_defineOwnPropertyMethod · 0.80

Tested by

no test coverage detected