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

Method _setOwnIdx

array.go:214–257  ·  view source on GitHub ↗
(idx uint32, val Value, throw bool)

Source from the content-addressed store, hash-verified

212}
213
214func (a *arrayObject) _setOwnIdx(idx uint32, val Value, throw bool) bool {
215 var prop Value
216 if idx < uint32(len(a.values)) {
217 prop = a.values[idx]
218 }
219
220 if prop == nil {
221 if proto := a.prototype; proto != nil {
222 // we know it's foreign because prototype loops are not allowed
223 if res, ok := proto.self.setForeignIdx(valueInt(idx), val, a.val, throw); ok {
224 return res
225 }
226 }
227 // new property
228 if !a.extensible {
229 a.val.runtime.typeErrorResult(throw, "Cannot add property %d, object is not extensible", idx)
230 return false
231 } else {
232 if idx >= a.length {
233 if !a.setLengthInt(idx+1, throw) {
234 return false
235 }
236 }
237 if idx >= uint32(len(a.values)) {
238 if !a.expand(idx) {
239 a.val.self.(*sparseArrayObject).add(idx, val)
240 return true
241 }
242 }
243 a.objCount++
244 }
245 } else {
246 if prop, ok := prop.(*valueProperty); ok {
247 if !prop.isWritable() {
248 a.val.runtime.typeErrorResult(throw)
249 return false
250 }
251 prop.set(a.val, val)
252 return true
253 }
254 }
255 a.values[idx] = val
256 return true
257}
258
259func (a *arrayObject) setOwnStr(name unistring.String, val Value, throw bool) bool {
260 if idx := strToArrayIdx(name); idx != math.MaxUint32 {

Callers 2

setOwnIdxMethod · 0.95
setOwnStrMethod · 0.95

Calls 8

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

Tested by

no test coverage detected