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

Method exportToArrayOrSlice

array_sparse.go:471–500  ·  view source on GitHub ↗
(dst reflect.Value, typ reflect.Type, ctx *objectExportCtx)

Source from the content-addressed store, hash-verified

469}
470
471func (a *sparseArrayObject) exportToArrayOrSlice(dst reflect.Value, typ reflect.Type, ctx *objectExportCtx) error {
472 r := a.val.runtime
473 if iter := a.getSym(SymIterator, nil); iter == r.getArrayValues() || iter == nil {
474 l := toIntStrict(int64(a.length))
475 if typ.Kind() == reflect.Array {
476 if dst.Len() != l {
477 return fmt.Errorf("cannot convert an Array into an array, lengths mismatch (have %d, need %d)", l, dst.Len())
478 }
479 } else {
480 dst.Set(reflect.MakeSlice(typ, l, l))
481 }
482 ctx.putTyped(a.val, typ, dst.Interface())
483 for _, item := range a.items {
484 val := item.value
485 if p, ok := val.(*valueProperty); ok {
486 val = p.get(a.val)
487 }
488 idx := toIntStrict(int64(item.idx))
489 if idx >= l {
490 break
491 }
492 err := r.toReflectValue(val, dst.Index(idx), ctx)
493 if err != nil {
494 return fmt.Errorf("could not convert array element %v to %v at %d: %w", item.value, typ, idx, err)
495 }
496 }
497 return nil
498 }
499 return a.baseObject.exportToArrayOrSlice(dst, typ, ctx)
500}

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