(idx uint32)
| 345 | } |
| 346 | |
| 347 | func (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 | |
| 381 | func (r *Runtime) defineArrayLength(prop *valueProperty, descr PropertyDescriptor, setter func(uint32, bool) bool, throw bool) bool { |
| 382 | var newLen uint32 |
no test coverage detected