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

Method arrayproto_map

builtin_array.go:780–813  ·  view source on GitHub ↗
(call FunctionCall)

Source from the content-addressed store, hash-verified

778}
779
780func (r *Runtime) arrayproto_map(call FunctionCall) Value {
781 o := call.This.ToObject(r)
782 length := toLength(o.self.getStr("length", nil))
783 callbackFn := r.toCallable(call.Argument(0))
784 fc := FunctionCall{
785 This: call.Argument(1),
786 Arguments: []Value{nil, nil, o},
787 }
788 a := arraySpeciesCreate(o, length)
789 if _, stdSrc := o.self.(*arrayObject); stdSrc {
790 if arr, ok := a.self.(*arrayObject); ok {
791 values := make([]Value, length)
792 for k := int64(0); k < length; k++ {
793 idx := valueInt(k)
794 if val := o.self.getIdx(idx, nil); val != nil {
795 fc.Arguments[0] = val
796 fc.Arguments[1] = idx
797 values[k] = callbackFn(fc)
798 }
799 }
800 setArrayValues(arr, values)
801 return a
802 }
803 }
804 for k := int64(0); k < length; k++ {
805 idx := valueInt(k)
806 if val := o.self.getIdx(idx, nil); val != nil {
807 fc.Arguments[0] = val
808 fc.Arguments[1] = idx
809 createDataPropertyOrThrow(a, idx, callbackFn(fc))
810 }
811 }
812 return a
813}
814
815func (r *Runtime) arrayproto_filter(call FunctionCall) Value {
816 o := call.This.ToObject(r)

Callers

nothing calls this directly

Calls 10

toCallableMethod · 0.95
toLengthFunction · 0.85
arraySpeciesCreateFunction · 0.85
valueIntTypeAlias · 0.85
setArrayValuesFunction · 0.85
ToObjectMethod · 0.65
getStrMethod · 0.65
getIdxMethod · 0.65
ArgumentMethod · 0.45

Tested by

no test coverage detected