(call FunctionCall)
| 1359 | } |
| 1360 | |
| 1361 | func (r *Runtime) arrayproto_toSpliced(call FunctionCall) Value { |
| 1362 | o := call.This.ToObject(r) |
| 1363 | length := toLength(o.self.getStr("length", nil)) |
| 1364 | actualStart := relToIdx(call.Argument(0).ToInteger(), length) |
| 1365 | var actualSkipCount int64 |
| 1366 | if len(call.Arguments) == 1 { |
| 1367 | actualSkipCount = length - actualStart |
| 1368 | } else if len(call.Arguments) > 1 { |
| 1369 | actualSkipCount = min(max(call.Argument(1).ToInteger(), 0), length-actualStart) |
| 1370 | } |
| 1371 | itemCount := max(int64(len(call.Arguments)-2), 0) |
| 1372 | newLength := length - actualSkipCount + itemCount |
| 1373 | if newLength >= maxInt { |
| 1374 | panic(r.NewTypeError("Invalid array length")) |
| 1375 | } |
| 1376 | |
| 1377 | if src := r.checkStdArrayObj(o); src != nil { |
| 1378 | var values []Value |
| 1379 | if itemCount == actualSkipCount { |
| 1380 | values = make([]Value, len(src.values)) |
| 1381 | copy(values, src.values) |
| 1382 | } else { |
| 1383 | values = make([]Value, newLength) |
| 1384 | copy(values, src.values[:actualStart]) |
| 1385 | copy(values[actualStart+itemCount:], src.values[actualStart+actualSkipCount:]) |
| 1386 | } |
| 1387 | if itemCount > 0 { |
| 1388 | copy(values[actualStart:], call.Arguments[2:]) |
| 1389 | } |
| 1390 | return r.newArrayValues(values) |
| 1391 | } else { |
| 1392 | a := r.newArrayLength(newLength) |
| 1393 | var i int64 |
| 1394 | rl := actualStart + actualSkipCount |
| 1395 | |
| 1396 | for i < actualStart { |
| 1397 | pi := valueInt(i) |
| 1398 | iValue := nilSafe(o.self.getIdx(pi, nil)) |
| 1399 | createDataPropertyOrThrow(a, pi, iValue) |
| 1400 | i++ |
| 1401 | } |
| 1402 | |
| 1403 | if itemCount > 0 { |
| 1404 | for _, item := range call.Arguments[2:] { |
| 1405 | createDataPropertyOrThrow(a, valueInt(i), nilSafe(item)) |
| 1406 | i++ |
| 1407 | } |
| 1408 | } |
| 1409 | |
| 1410 | for i < newLength { |
| 1411 | pi := valueInt(i) |
| 1412 | from := valueInt(rl) |
| 1413 | fromValue := nilSafe(o.self.getIdx(from, nil)) |
| 1414 | createDataPropertyOrThrow(a, pi, fromValue) |
| 1415 | i++ |
| 1416 | rl++ |
| 1417 | } |
| 1418 |
nothing calls this directly
no test coverage detected