Skip to content

Commit

Permalink
Test Array.prototype.sort called with a primitive
Browse files Browse the repository at this point in the history
  • Loading branch information
shvaikalesh authored and rwaldron committed Mar 2, 2021
1 parent c8daa32 commit c00087e
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/built-ins/Array/prototype/sort/call-with-primitive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (C) 2021 Alexey Shvayka. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-array.prototype.sort
description: >
This value is coerced to an object.
info: |
Array.prototype.sort ( comparefn )
[...]
2. Let obj be ? ToObject(this value).
[...]
12. Return obj.
features: [Symbol, BigInt]
---*/

assert.throws(TypeError, function() {
[].sort.call(undefined);
}, "undefined");

assert.throws(TypeError, function() {
[].sort.call(null);
}, "null");

assert([].sort.call(false) instanceof Boolean, "boolean");
assert([].sort.call(0) instanceof Number, "number");
assert([].sort.call("") instanceof String, "string");
assert([].sort.call(Symbol()) instanceof Symbol, "symbol");
assert([].sort.call(0n) instanceof BigInt, "bigint");

0 comments on commit c00087e

Please sign in to comment.