mirror of
https://github.com/tc39/test262.git
synced 2025-12-08 14:30:04 +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]
|
features: [Symbol, WeakMap, upsert]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
|
var log = [];
|
||||||
|
var invalidKeys = [1, false, undefined, 'string', null];
|
||||||
|
|
||||||
var s = new WeakMap();
|
var s = new WeakMap();
|
||||||
|
|
||||||
assert.throws(TypeError, function() {
|
for (let invalidKey of invalidKeys) {
|
||||||
s.getOrInsertComputed(1, () => 1);
|
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() {
|
assert.throws(TypeError, function () {
|
||||||
s.getOrInsertComputed(false, () => 1);
|
s.getOrInsertComputed(Symbol.for('registered symbol'),
|
||||||
});
|
() => log.push("Unexpected callback evaluation"));
|
||||||
|
|
||||||
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);
|
|
||||||
}, 'Registered symbol not allowed as WeakMap key');
|
}, 'Registered symbol not allowed as WeakMap key');
|
||||||
|
|
||||||
|
assert.compareArray(log, []);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user