(call FunctionCall)
| 375 | } |
| 376 | |
| 377 | func (r *Runtime) arrayproto_sort(call FunctionCall) Value { |
| 378 | o := call.This.ToObject(r) |
| 379 | |
| 380 | var compareFn func(FunctionCall) Value |
| 381 | arg := call.Argument(0) |
| 382 | if arg != _undefined { |
| 383 | if arg, ok := call.Argument(0).(*Object); ok { |
| 384 | compareFn, _ = arg.self.assertCallable() |
| 385 | } |
| 386 | if compareFn == nil { |
| 387 | panic(r.NewTypeError("The comparison function must be either a function or undefined")) |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | var s sortable |
| 392 | if r.checkStdArrayObj(o) != nil { |
| 393 | s = o.self |
| 394 | } else if _, ok := o.self.(reflectValueWrapper); ok { |
| 395 | s = o.self |
| 396 | } |
| 397 | |
| 398 | if s != nil { |
| 399 | ctx := arraySortCtx{ |
| 400 | obj: s, |
| 401 | compare: compareFn, |
| 402 | } |
| 403 | |
| 404 | sort.Stable(&ctx) |
| 405 | } else { |
| 406 | length := toLength(o.self.getStr("length", nil)) |
| 407 | a := make([]Value, 0, length) |
| 408 | for i := int64(0); i < length; i++ { |
| 409 | idx := valueInt(i) |
| 410 | if o.self.hasPropertyIdx(idx) { |
| 411 | a = append(a, nilSafe(o.self.getIdx(idx, nil))) |
| 412 | } |
| 413 | } |
| 414 | ar := r.newArrayValues(a) |
| 415 | ctx := arraySortCtx{ |
| 416 | obj: ar.self, |
| 417 | compare: compareFn, |
| 418 | } |
| 419 | |
| 420 | sort.Stable(&ctx) |
| 421 | for i := 0; i < len(a); i++ { |
| 422 | o.self.setOwnIdx(valueInt(i), a[i], true) |
| 423 | } |
| 424 | for i := int64(len(a)); i < length; i++ { |
| 425 | o.self.deleteIdx(valueInt(i), true) |
| 426 | } |
| 427 | } |
| 428 | return o |
| 429 | } |
| 430 | |
| 431 | func (r *Runtime) arrayproto_splice(call FunctionCall) Value { |
| 432 | o := call.This.ToObject(r) |
nothing calls this directly
no test coverage detected