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

Method arrayproto_with

builtin_array.go:1252–1295  ·  view source on GitHub ↗
(call FunctionCall)

Source from the content-addressed store, hash-verified

1250}
1251
1252func (r *Runtime) arrayproto_with(call FunctionCall) Value {
1253 o := call.This.ToObject(r)
1254 relativeIndex := call.Argument(0).ToInteger()
1255 value := call.Argument(1)
1256 length := toLength(o.self.getStr("length", nil))
1257
1258 actualIndex := int64(0)
1259 if relativeIndex >= 0 {
1260 actualIndex = relativeIndex
1261 } else {
1262 actualIndex = length + relativeIndex
1263 }
1264 if actualIndex >= length || actualIndex < 0 {
1265 panic(r.newErrorf(r.getRangeError(), "Invalid index %s", call.Argument(0).String()))
1266 }
1267
1268 if src := r.checkStdArrayObj(o); src != nil {
1269 a := make([]Value, 0, length)
1270 for k := int64(0); k < length; k++ {
1271 pk := valueInt(k)
1272 var fromValue Value
1273 if k == actualIndex {
1274 fromValue = value
1275 } else {
1276 fromValue = src.values[pk]
1277 }
1278 a = append(a, fromValue)
1279 }
1280 return r.newArrayValues(a)
1281 } else {
1282 a := r.newArrayLength(length)
1283 for k := int64(0); k < length; k++ {
1284 pk := valueInt(k)
1285 var fromValue Value
1286 if k == actualIndex {
1287 fromValue = value
1288 } else {
1289 fromValue = o.self.getIdx(pk, nil)
1290 }
1291 createDataPropertyOrThrow(a, pk, fromValue)
1292 }
1293 return a
1294 }
1295}
1296
1297func (r *Runtime) arrayproto_toReversed(call FunctionCall) Value {
1298 o := call.This.ToObject(r)

Callers

nothing calls this directly

Calls 14

newErrorfMethod · 0.95
getRangeErrorMethod · 0.95
checkStdArrayObjMethod · 0.95
newArrayValuesMethod · 0.95
newArrayLengthMethod · 0.95
toLengthFunction · 0.85
valueIntTypeAlias · 0.85
ToObjectMethod · 0.65
ToIntegerMethod · 0.65
getStrMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected