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

Method arrayproto_copyWithin

builtin_array.go:1045–1083  ·  view source on GitHub ↗
(call FunctionCall)

Source from the content-addressed store, hash-verified

1043}
1044
1045func (r *Runtime) arrayproto_copyWithin(call FunctionCall) Value {
1046 o := call.This.ToObject(r)
1047 l := toLength(o.self.getStr("length", nil))
1048 var relEnd, dir int64
1049 to := relToIdx(call.Argument(0).ToInteger(), l)
1050 from := relToIdx(call.Argument(1).ToInteger(), l)
1051 if end := call.Argument(2); end != _undefined {
1052 relEnd = end.ToInteger()
1053 } else {
1054 relEnd = l
1055 }
1056 final := relToIdx(relEnd, l)
1057 count := min(final-from, l-to)
1058 if arr := r.checkStdArrayObj(o); arr != nil {
1059 if count > 0 {
1060 copy(arr.values[to:to+count], arr.values[from:from+count])
1061 }
1062 return o
1063 }
1064 if from < to && to < from+count {
1065 dir = -1
1066 from = from + count - 1
1067 to = to + count - 1
1068 } else {
1069 dir = 1
1070 }
1071 for count > 0 {
1072 if o.self.hasPropertyIdx(valueInt(from)) {
1073 o.self.setOwnIdx(valueInt(to), nilSafe(o.self.getIdx(valueInt(from), nil)), true)
1074 } else {
1075 o.self.deleteIdx(valueInt(to), true)
1076 }
1077 from += dir
1078 to += dir
1079 count--
1080 }
1081
1082 return o
1083}
1084
1085func (r *Runtime) arrayproto_entries(call FunctionCall) Value {
1086 return r.createArrayIterator(call.This.ToObject(r), iterationKindKeyValue)

Callers

nothing calls this directly

Calls 13

checkStdArrayObjMethod · 0.95
toLengthFunction · 0.85
relToIdxFunction · 0.85
valueIntTypeAlias · 0.85
nilSafeFunction · 0.85
ToObjectMethod · 0.65
getStrMethod · 0.65
ToIntegerMethod · 0.65
hasPropertyIdxMethod · 0.65
setOwnIdxMethod · 0.65
getIdxMethod · 0.65
deleteIdxMethod · 0.65

Tested by

no test coverage detected