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

Method expand

array.go:347–379  ·  view source on GitHub ↗
(idx uint32)

Source from the content-addressed store, hash-verified

345}
346
347func (a *arrayObject) expand(idx uint32) bool {
348 targetLen := idx + 1
349 if targetLen > uint32(len(a.values)) {
350 if targetLen < uint32(cap(a.values)) {
351 a.values = a.values[:targetLen]
352 } else {
353 if idx > 4096 && (a.objCount == 0 || idx/uint32(a.objCount) > 10) {
354 //log.Println("Switching standard->sparse")
355 sa := &sparseArrayObject{
356 baseObject: a.baseObject,
357 length: a.length,
358 propValueCount: a.propValueCount,
359 }
360 sa.setValues(a.values, a.objCount+1)
361 sa.val.self = sa
362 sa.lengthProp.writable = a.lengthProp.writable
363 sa._put("length", &sa.lengthProp)
364 return false
365 } else {
366 if bits.UintSize == 32 {
367 if targetLen >= math.MaxInt32 {
368 panic(a.val.runtime.NewTypeError("Array index overflows int"))
369 }
370 }
371 tl := int(targetLen)
372 newValues := make([]Value, tl, growCap(tl, len(a.values), cap(a.values)))
373 copy(newValues, a.values)
374 a.values = newValues
375 }
376 }
377 }
378 return true
379}
380
381func (r *Runtime) defineArrayLength(prop *valueProperty, descr PropertyDescriptor, setter func(uint32, bool) bool, throw bool) bool {
382 var newLen uint32

Callers 2

_setOwnIdxMethod · 0.95
_defineIdxPropertyMethod · 0.95

Calls 4

setValuesMethod · 0.95
growCapFunction · 0.85
NewTypeErrorMethod · 0.80
_putMethod · 0.45

Tested by

no test coverage detected