mirror of
https://github.com/tc39/test262.git
synced 2025-10-01 05:58:45 +02:00
This adds tests to WeakMap, WeakSet, WeakRef, and FinalizationRegistry for Symbols as weakly-held values. Regular symbols and well-known symbols are both tested. These tests correspond to existing tests for Objects as weakly-held values, but are put in separate files so that they can be filtered out with the "symbols-as-weakmap-keys" feature flag. Registered symbols are not allowed; this is already tested in the "cannot- be-held-weakly" tests. See: #2850
34 lines
1014 B
JavaScript
34 lines
1014 B
JavaScript
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
|
// This code is governed by the BSD license found in the LICENSE file.
|
|
/*---
|
|
esid: sec-weakset-iterable
|
|
description: >
|
|
Returns the new WeakSet adding Symbol values from the iterable parameter.
|
|
info: |
|
|
WeakSet ( [ _iterable_ ] )
|
|
8. Repeat,
|
|
d. Let _status_ be Completion(Call(_adder_, _set_, « _nextValue_ »)).
|
|
|
|
WeakSet.prototype.add ( _value_ ):
|
|
6. Append _value_ as the last element of _entries_.
|
|
features: [Symbol, WeakSet, symbols-as-weakmap-keys]
|
|
---*/
|
|
|
|
var first = Symbol('a description');
|
|
var second = Symbol('a description');
|
|
var added = [];
|
|
var realAdd = WeakSet.prototype.add;
|
|
WeakSet.prototype.add = function(value) {
|
|
added.push(value);
|
|
return realAdd.call(this, value);
|
|
};
|
|
var s = new WeakSet([first, second, Symbol.hasInstance]);
|
|
|
|
assert.compareArray(
|
|
added,
|
|
[first, second, Symbol.hasInstance],
|
|
"add() was called 3 times, on the two unregistered and one well-known symbols in order"
|
|
);
|
|
|
|
WeakSet.prototype.add = realAdd;
|