mirror of
https://github.com/tc39/test262.git
synced 2025-12-07 22:09:47 +01:00
Modifed the test to verify that callbackfn is not called if the key cannot be held weakly.
This commit is contained in:
parent
a5e69a1534
commit
557b748bff
@ -13,29 +13,22 @@ info: |
|
||||
...
|
||||
features: [Symbol, WeakMap, upsert]
|
||||
---*/
|
||||
|
||||
var log = [];
|
||||
var invalidKeys = [1, false, undefined, 'string', null];
|
||||
|
||||
var s = new WeakMap();
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
s.getOrInsertComputed(1, () => 1);
|
||||
});
|
||||
for (let invalidKey of invalidKeys) {
|
||||
assert.throws(TypeError, function () {
|
||||
s.getOrInsertComputed(invalidKey,
|
||||
() => log.push(`Unexpected evaluation of callback function, key: ${typeof invalidKey}`));
|
||||
}, `${typeof invalidKey} not allowed as WeakMap key`);
|
||||
}
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
s.getOrInsertComputed(false, () => 1);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
s.getOrInsertComputed(undefined, () => 1);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
s.getOrInsertComputed('string', () => 1);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
s.getOrInsertComputed(null, () => 1);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
s.getOrInsertComputed(Symbol.for('registered symbol'), () => 1);
|
||||
assert.throws(TypeError, function () {
|
||||
s.getOrInsertComputed(Symbol.for('registered symbol'),
|
||||
() => log.push("Unexpected callback evaluation"));
|
||||
}, 'Registered symbol not allowed as WeakMap key');
|
||||
|
||||
assert.compareArray(log, []);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user