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

Method exportToArrayOrSlice

builtin_set.go:66–89  ·  view source on GitHub ↗
(dst reflect.Value, typ reflect.Type, ctx *objectExportCtx)

Source from the content-addressed store, hash-verified

64}
65
66func (so *setObject) exportToArrayOrSlice(dst reflect.Value, typ reflect.Type, ctx *objectExportCtx) error {
67 l := so.m.size
68 if typ.Kind() == reflect.Array {
69 if dst.Len() != l {
70 return fmt.Errorf("cannot convert a Set into an array, lengths mismatch: have %d, need %d)", l, dst.Len())
71 }
72 } else {
73 dst.Set(reflect.MakeSlice(typ, l, l))
74 }
75 ctx.putTyped(so.val, typ, dst.Interface())
76 iter := so.m.newIter()
77 r := so.val.runtime
78 for i := 0; i < l; i++ {
79 entry := iter.next()
80 if entry == nil {
81 break
82 }
83 err := r.toReflectValue(entry.key, dst.Index(i), ctx)
84 if err != nil {
85 return err
86 }
87 }
88 return nil
89}
90
91func (so *setObject) exportToMap(dst reflect.Value, typ reflect.Type, ctx *objectExportCtx) error {
92 dst.Set(reflect.MakeMap(typ))

Callers

nothing calls this directly

Calls 6

putTypedMethod · 0.80
newIterMethod · 0.80
toReflectValueMethod · 0.80
LenMethod · 0.65
SetMethod · 0.65
nextMethod · 0.45

Tested by

no test coverage detected