| // WeakSet constructor with adder change. |
| function shouldThrow(func, errorMessage) { |
| if (String(error) !== errorMessage) |
| throw new Error(`Bad error: ${error}`); |
| throw new Error("Didn't throw!"); |
| var originalAdder = WeakSet.prototype.add; |
| WeakSet.prototype.add = function (key) { |
| return originalAdder.call(this, key); |
| var set = new WeakSet(values); |
| if (counter !== values.length) |
| throw new Error("bad counter " + counter); |
| WeakSet.prototype.add = function () { |
| throw new Error("adder called"); |
| var set = new WeakSet([]); |
| }, "Error: adder called"); |
| WeakSet.prototype.add = "foo"; |
| }, "TypeError: 'add' property of a WeakSet should be callable."); |