MCPcopy Create free account
hub / github.com/devld/go-drive / Array

Method Array

script/utils.go:137–164  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

135}
136
137func (v *Value) Array() []*Value {
138 obj := v.object()
139 if obj == nil {
140 return nil
141 }
142 // Read elements directly from the underlying otto object to avoid the
143 // per-index *Value allocation and object re-resolution that v.Get would
144 // incur. otto has no indexed accessor, so string keys are unavoidable, but
145 // this keeps the hot path (listing large directories) as lean as possible.
146 lengthVal, e := obj.Get("length")
147 if e != nil {
148 v.vm.ThrowTypeError("not a valid array")
149 }
150 length, e := lengthVal.ToInteger()
151 if e != nil || length < 0 {
152 v.vm.ThrowTypeError("not a valid array")
153 }
154 n := int(length)
155 r := make([]*Value, n)
156 for i := range n {
157 ev, e := obj.Get(strconv.Itoa(i))
158 if e != nil {
159 v.vm.ThrowTypeError(e.Error())
160 }
161 r[i] = newValue(v.vm, ev)
162 }
163 return r
164}
165
166func (v *Value) M() types.M {
167 if v.IsNil() {

Callers 2

parseValueFunction · 0.80
ListMethod · 0.80

Calls 5

objectMethod · 0.95
newValueFunction · 0.85
ThrowTypeErrorMethod · 0.80
GetMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected