Improve Array#sort tests for verifying non callable comparefn (#1352)

Fix #1345
This commit is contained in:
Leo Balter 2017-11-21 11:41:18 -05:00 committed by GitHub
parent 3981242226
commit 168cc4c638
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 51 additions and 10 deletions

View File

@ -15,40 +15,81 @@ info: >
features: [Symbol]
---*/
var sample = [1, 2, 3];
var sample = [1];
var poisoned = {
get length() {
throw new Test262Error("IsCallable(comparefn) should be observed before this.length");
}
};
assert.throws(TypeError, function() {
sample.sort(null);
});
}, "sample.sort(null);");
assert.throws(TypeError, function() {
[].sort.call(poisoned, null);
}, "[].sort.call(poisoned, null);");
assert.throws(TypeError, function() {
sample.sort(true);
});
}, "sample.sort(true);");
assert.throws(TypeError, function() {
[].sort.call(poisoned, true);
}, "[].sort.call(poisoned, true);");
assert.throws(TypeError, function() {
sample.sort(false);
});
}, "sample.sort(false);");
assert.throws(TypeError, function() {
[].sort.call(poisoned, false);
}, "[].sort.call(poisoned, false);");
assert.throws(TypeError, function() {
sample.sort('');
});
}, "sample.sort('');");
assert.throws(TypeError, function() {
[].sort.call(poisoned, '');
}, "[].sort.call(poisoned, '');");
assert.throws(TypeError, function() {
sample.sort(/a/g);
});
}, "sample.sort(/a/g);");
assert.throws(TypeError, function() {
[].sort.call(poisoned, /a/g);
}, "[].sort.call(poisoned, /a/g);");
assert.throws(TypeError, function() {
sample.sort(42);
});
}, "sample.sort(42);");
assert.throws(TypeError, function() {
[].sort.call(poisoned, 42);
}, "[].sort.call(poisoned, 42);");
assert.throws(TypeError, function() {
sample.sort([]);
});
}, "sample.sort([]);");
assert.throws(TypeError, function() {
[].sort.call(poisoned, []);
}, "[].sort.call(poisoned, []);");
assert.throws(TypeError, function() {
sample.sort({});
});
}, "sample.sort({});");
assert.throws(TypeError, function() {
[].sort.call(poisoned, {});
}, "[].sort.call(poisoned, {});");
assert.throws(TypeError, function() {
sample.sort(Symbol());
});
}, "sample.sort(Symbol());");
assert.throws(TypeError, function() {
[].sort.call(poisoned, Symbol());
}, "[].sort.call(poisoned, Symbol());");