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

Method _setLengthInt

array.go:81–116  ·  view source on GitHub ↗
(l uint32, throw bool)

Source from the content-addressed store, hash-verified

79}
80
81func (a *arrayObject) _setLengthInt(l uint32, throw bool) bool {
82 ret := true
83 if l <= a.length {
84 if a.propValueCount > 0 {
85 // Slow path
86 for i := len(a.values) - 1; i >= int(l); i-- {
87 if prop, ok := a.values[i].(*valueProperty); ok {
88 if !prop.configurable {
89 l = uint32(i) + 1
90 ret = false
91 break
92 }
93 a.propValueCount--
94 }
95 }
96 }
97 }
98 if l <= uint32(len(a.values)) {
99 if l >= 16 && l < uint32(cap(a.values))>>2 {
100 ar := make([]Value, l)
101 copy(ar, a.values)
102 a.values = ar
103 } else {
104 ar := a.values[l:len(a.values)]
105 for i := range ar {
106 ar[i] = nil
107 }
108 a.values = a.values[:l]
109 }
110 }
111 a.length = l
112 if !ret {
113 a.val.runtime.typeErrorResult(throw, "Cannot redefine property: length")
114 }
115 return ret
116}
117
118func (a *arrayObject) setLengthInt(l uint32, throw bool) bool {
119 if l == a.length {

Callers 2

setLengthIntMethod · 0.95
setLengthMethod · 0.95

Calls 1

typeErrorResultMethod · 0.80

Tested by

no test coverage detected