(call FunctionCall)
| 1319 | } |
| 1320 | |
| 1321 | func (r *Runtime) arrayproto_toSorted(call FunctionCall) Value { |
| 1322 | var compareFn func(FunctionCall) Value |
| 1323 | arg := call.Argument(0) |
| 1324 | if arg != _undefined { |
| 1325 | if arg, ok := arg.(*Object); ok { |
| 1326 | compareFn, _ = arg.self.assertCallable() |
| 1327 | } |
| 1328 | if compareFn == nil { |
| 1329 | panic(r.NewTypeError("The comparison function must be either a function or undefined")) |
| 1330 | } |
| 1331 | } |
| 1332 | |
| 1333 | o := call.This.ToObject(r) |
| 1334 | length := toLength(o.self.getStr("length", nil)) |
| 1335 | if length >= math.MaxUint32 { |
| 1336 | panic(r.newError(r.getRangeError(), "Invalid array length")) |
| 1337 | } |
| 1338 | var a []Value |
| 1339 | |
| 1340 | if src := r.checkStdArrayObj(o); src != nil { |
| 1341 | a = make([]Value, length) |
| 1342 | copy(a, src.values) |
| 1343 | } else { |
| 1344 | a = make([]Value, 0, length) |
| 1345 | for i := int64(0); i < length; i++ { |
| 1346 | idx := valueInt(i) |
| 1347 | a = append(a, nilSafe(o.self.getIdx(idx, nil))) |
| 1348 | } |
| 1349 | } |
| 1350 | |
| 1351 | ar := r.newArrayValues(a) |
| 1352 | ctx := arraySortCtx{ |
| 1353 | obj: ar.self, |
| 1354 | compare: compareFn, |
| 1355 | } |
| 1356 | |
| 1357 | sort.Stable(&ctx) |
| 1358 | return ar |
| 1359 | } |
| 1360 | |
| 1361 | func (r *Runtime) arrayproto_toSpliced(call FunctionCall) Value { |
| 1362 | o := call.This.ToObject(r) |
nothing calls this directly
no test coverage detected