diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2018-01-19 11:03:02 +0100 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-02-01 09:41:47 +0100 |
commit | 936eea5099bb5ab31b76ef22fcf15baed0cdf5ab (patch) | |
tree | da01943b8c9564ab72350876e2a1ea4ebe21bd75 /doc/api/assert.md | |
parent | edbcf7c8442d96aabeb564ba1121dad2ff4321a0 (diff) | |
download | android-node-v8-936eea5099bb5ab31b76ef22fcf15baed0cdf5ab.tar.gz android-node-v8-936eea5099bb5ab31b76ef22fcf15baed0cdf5ab.tar.bz2 android-node-v8-936eea5099bb5ab31b76ef22fcf15baed0cdf5ab.zip |
doc: document asserts Weak(Map|Set) behavior
Right now it is not documentated that WeakMap entries are not
compared. This might result in some confusion. This adds a note
about the behavior in `assert.deepStrictEqual`. This documentation
is also references in `util.isDeepStrictEqual`, so we do not have
to document it again for that function as the underlying algorithm
is the same.
PR-URL: https://github.com/nodejs/node/pull/18248
Fixes: https://github.com/nodejs/node/issues/18228
Refs: https://github.com/nodejs/node/pull/18228
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'doc/api/assert.md')
-rw-r--r-- | doc/api/assert.md | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/doc/api/assert.md b/doc/api/assert.md index 09ea4483d1..dc9a902695 100644 --- a/doc/api/assert.md +++ b/doc/api/assert.md @@ -249,6 +249,8 @@ are recursively evaluated also by the following rules. * Map keys and Set items are compared unordered. * Recursion stops when both sides differ or both sides encounter a circular reference. +* [`WeakMap`][] and [`WeakSet`][] comparison does not rely on their values. See + below for further details. ```js const assert = require('assert').strict; @@ -290,6 +292,16 @@ assert.deepStrictEqual({ [symbol1]: 1 }, { [symbol1]: 1 }); // OK, because it is the same symbol on both objects. assert.deepStrictEqual({ [symbol1]: 1 }, { [symbol2]: 1 }); // Fails because symbol1 !== symbol2! + +const weakMap1 = new WeakMap(); +const weakMap2 = new WeakMap([[{}, {}]]); +const weakMap3 = new WeakMap(); +weakMap3.unequal = true; + +assert.deepStrictEqual(weakMap1, weakMap2); +// OK, because it is impossible to compare the entries +assert.deepStrictEqual(weakMap1, weakMap3); +// Fails because weakMap3 has a property that weakMap1 does not contain! ``` If the values are not equal, an `AssertionError` is thrown with a `message` @@ -920,6 +932,8 @@ second argument. This might lead to difficult-to-spot errors. [`Set`]: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Set [`Symbol`]: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Symbol [`TypeError`]: errors.html#errors_class_typeerror +[`WeakMap`]: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/WeakMap +[`WeakSet`]: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/WeakSet [`assert.deepEqual()`]: #assert_assert_deepequal_actual_expected_message [`assert.deepStrictEqual()`]: #assert_assert_deepstrictequal_actual_expected_message [`assert.notDeepStrictEqual()`]: #assert_assert_notdeepstrictequal_actual_expected_message |