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

Method exportToArrayOrSlice

array.go:522–550  ·  view source on GitHub ↗
(dst reflect.Value, typ reflect.Type, ctx *objectExportCtx)

Source from the content-addressed store, hash-verified

520}
521
522func (a *arrayObject) exportToArrayOrSlice(dst reflect.Value, typ reflect.Type, ctx *objectExportCtx) error {
523 r := a.val.runtime
524 if iter := a.getSym(SymIterator, nil); iter == r.getArrayValues() || iter == nil {
525 l := toIntStrict(int64(a.length))
526 if typ.Kind() == reflect.Array {
527 if dst.Len() != l {
528 return fmt.Errorf("cannot convert an Array into an array, lengths mismatch (have %d, need %d)", l, dst.Len())
529 }
530 } else {
531 dst.Set(reflect.MakeSlice(typ, l, l))
532 }
533 ctx.putTyped(a.val, typ, dst.Interface())
534 for i := 0; i < l; i++ {
535 if i >= len(a.values) {
536 break
537 }
538 val := a.values[i]
539 if p, ok := val.(*valueProperty); ok {
540 val = p.get(a.val)
541 }
542 err := r.toReflectValue(val, dst.Index(i), ctx)
543 if err != nil {
544 return fmt.Errorf("could not convert array element %v to %v at %d: %w", val, typ, i, err)
545 }
546 }
547 return nil
548 }
549 return a.baseObject.exportToArrayOrSlice(dst, typ, ctx)
550}
551
552func (a *arrayObject) setValuesFromSparse(items []sparseArrayItem, newMaxIdx int) {
553 a.values = make([]Value, newMaxIdx+1)

Callers

nothing calls this directly

Calls 9

toIntStrictFunction · 0.85
getArrayValuesMethod · 0.80
putTypedMethod · 0.80
toReflectValueMethod · 0.80
getSymMethod · 0.65
LenMethod · 0.65
SetMethod · 0.65
getMethod · 0.65
exportToArrayOrSliceMethod · 0.65

Tested by

no test coverage detected