wrap Symbol.for in Symbol.prototype.description polyfill for correct handling of empty string descriptions

This commit is contained in:
Denis Pushkarev
2026-02-16 11:02:55 +02:00
parent b7f391e67c
commit 9cf1ec2c27
3 changed files with 13 additions and 0 deletions
+1
View File
@@ -5,6 +5,7 @@
- Throw a `RangeError` on `NaN` `start` / `end` / `step`
- Allow `null` as `optionOrStep`
- `Math.atanh` has become slightly more correct with small values
- Wrap `Symbol.for` in `Symbol.prototype.description` polyfill for correct handling of empty string descriptions
- Fixed one more case (`Iterator.prototype.take`) of a V8 ~ Chromium < 126 [bug](https://issues.chromium.org/issues/336839115)
- Forced replacement of `Iterator.{ concat, zip, zipKeyed }` in the pure version for ensuring proper wrapped `Iterator` instances as the result
- Fixed double `.return` calling in case of throwing error in this method in the internal `iterate` helper that affected some polyfills
@@ -4,6 +4,7 @@
var $ = require('../internals/export');
var DESCRIPTORS = require('../internals/descriptors');
var globalThis = require('../internals/global-this');
var call = require('../internals/function-call');
var uncurryThis = require('../internals/function-uncurry-this');
var hasOwn = require('../internals/has-own-property');
var isCallable = require('../internals/is-callable');
@@ -33,6 +34,14 @@ if (DESCRIPTORS && isCallable(NativeSymbol) && (!('description' in SymbolPrototy
};
copyConstructorProperties(SymbolWrapper, NativeSymbol);
// wrap Symbol.for for correct handling of empty string descriptions
var nativeFor = SymbolWrapper['for'];
SymbolWrapper['for'] = { 'for': function (key) {
var stringKey = toString(key);
var symbol = call(nativeFor, this, stringKey);
if (stringKey === '') EmptyStringDescriptionStore[symbol] = true;
return symbol;
} }['for'];
SymbolWrapper.prototype = SymbolPrototype;
SymbolPrototype.constructor = SymbolWrapper;
@@ -26,4 +26,7 @@ QUnit.test('Symbol#description', assert => {
assert.same(Symbol().toString(), 'Symbol()');
assert.same(String(Symbol()), 'Symbol()');
}
// Symbol.for with empty string key should have '' description
assert.same(Symbol.for('').description, '', 'Symbol.for("").description');
assert.same(Symbol.for('foo').description, 'foo', 'Symbol.for("foo").description');
});