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

Method _setOwnIdx

array_sparse.go:152–204  ·  view source on GitHub ↗
(idx uint32, val Value, throw bool)

Source from the content-addressed store, hash-verified

150}
151
152func (a *sparseArrayObject) _setOwnIdx(idx uint32, val Value, throw bool) bool {
153 var prop Value
154 i := a.findIdx(idx)
155 if i < len(a.items) && a.items[i].idx == idx {
156 prop = a.items[i].value
157 }
158
159 if prop == nil {
160 if proto := a.prototype; proto != nil {
161 // we know it's foreign because prototype loops are not allowed
162 if res, ok := proto.self.setForeignIdx(valueInt(idx), val, a.val, throw); ok {
163 return res
164 }
165 }
166
167 // new property
168 if !a.extensible {
169 a.val.runtime.typeErrorResult(throw, "Cannot add property %d, object is not extensible", idx)
170 return false
171 }
172
173 if idx >= a.length {
174 if !a.setLengthInt(idx+1, throw) {
175 return false
176 }
177 }
178
179 if a.expand(idx) {
180 a.items = append(a.items, sparseArrayItem{})
181 copy(a.items[i+1:], a.items[i:])
182 a.items[i] = sparseArrayItem{
183 idx: idx,
184 value: val,
185 }
186 } else {
187 ar := a.val.self.(*arrayObject)
188 ar.values[idx] = val
189 ar.objCount++
190 return true
191 }
192 } else {
193 if prop, ok := prop.(*valueProperty); ok {
194 if !prop.isWritable() {
195 a.val.runtime.typeErrorResult(throw)
196 return false
197 }
198 prop.set(a.val, val)
199 } else {
200 a.items[i].value = val
201 }
202 }
203 return true
204}
205
206func (a *sparseArrayObject) setOwnStr(name unistring.String, val Value, throw bool) bool {
207 if idx := strToArrayIdx(name); idx != math.MaxUint32 {

Callers 2

setOwnStrMethod · 0.95
setOwnIdxMethod · 0.95

Calls 8

findIdxMethod · 0.95
setLengthIntMethod · 0.95
expandMethod · 0.95
valueIntTypeAlias · 0.85
typeErrorResultMethod · 0.80
isWritableMethod · 0.80
setForeignIdxMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected