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

Method setLength

object_template.go:396–423  ·  view source on GitHub ↗
(l uint32, throw bool)

Source from the content-addressed store, hash-verified

394}
395
396func (a *templatedArrayObject) setLength(l uint32, throw bool) bool {
397 lenProp := a.getLenProp()
398 oldLen := uint32(lenProp.value.ToInteger())
399 if l == oldLen {
400 return true
401 }
402 if !lenProp.writable {
403 a.val.runtime.typeErrorResult(throw, "length is not writable")
404 return false
405 }
406 ret := true
407 if l < oldLen {
408 a.materialisePropNames()
409 a.fixPropOrder()
410 i := sort.Search(a.idxPropCount, func(idx int) bool {
411 return strToArrayIdx(a.propNames[idx]) >= l
412 })
413 for j := a.idxPropCount - 1; j >= i; j-- {
414 if !a.deleteStr(a.propNames[j], false) {
415 l = strToArrayIdx(a.propNames[j]) + 1
416 ret = false
417 break
418 }
419 }
420 }
421 lenProp.value = intToValue(int64(l))
422 return ret
423}
424
425func (a *templatedArrayObject) setOwnStr(name unistring.String, value Value, throw bool) bool {
426 if name == "length" {

Callers 1

setOwnStrMethod · 0.95

Calls 8

getLenPropMethod · 0.95
strToArrayIdxFunction · 0.85
intToValueFunction · 0.85
typeErrorResultMethod · 0.80
materialisePropNamesMethod · 0.80
fixPropOrderMethod · 0.80
ToIntegerMethod · 0.65
deleteStrMethod · 0.65

Tested by

no test coverage detected