Skip to content

Commit 55b7b12

Browse files
committed
wrap Symbol.for in Symbol.prototype.description polyfill for correct handling of empty string descriptions
1 parent 36f9309 commit 55b7b12

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Throw a `RangeError` on `NaN` `start` / `end` / `step`
66
- Allow `null` as `optionOrStep`
77
- `Math.atanh` has become slightly more correct with small values
8+
- Wrap `Symbol.for` in `Symbol.prototype.description` polyfill for correct handling of empty string descriptions
89
- Fixed one more case (`Iterator.prototype.take`) of a V8 ~ Chromium < 126 [bug](https://issues.chromium.org/issues/336839115)
910
- Forced replacement of `Iterator.{ concat, zip, zipKeyed }` in the pure version for ensuring proper wrapped `Iterator` instances as the result
1011
- Fixed double `.return` calling in case of throwing error in this method in the internal `iterate` helper that affected some polyfills

packages/core-js/modules/es.symbol.description.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
var $ = require('../internals/export');
55
var DESCRIPTORS = require('../internals/descriptors');
66
var globalThis = require('../internals/global-this');
7+
var call = require('../internals/function-call');
78
var uncurryThis = require('../internals/function-uncurry-this');
89
var hasOwn = require('../internals/has-own-property');
910
var isCallable = require('../internals/is-callable');
@@ -33,6 +34,14 @@ if (DESCRIPTORS && isCallable(NativeSymbol) && (!('description' in SymbolPrototy
3334
};
3435

3536
copyConstructorProperties(SymbolWrapper, NativeSymbol);
37+
// wrap Symbol.for for correct handling of empty string descriptions
38+
var nativeFor = SymbolWrapper['for'];
39+
SymbolWrapper['for'] = { 'for': function (key) {
40+
var stringKey = toString(key);
41+
var symbol = call(nativeFor, this, stringKey);
42+
if (stringKey === '') EmptyStringDescriptionStore[symbol] = true;
43+
return symbol;
44+
} }['for'];
3645
SymbolWrapper.prototype = SymbolPrototype;
3746
SymbolPrototype.constructor = SymbolWrapper;
3847

tests/unit-global/es.symbol.description.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,7 @@ QUnit.test('Symbol#description', assert => {
2626
assert.same(Symbol().toString(), 'Symbol()');
2727
assert.same(String(Symbol()), 'Symbol()');
2828
}
29+
// Symbol.for with empty string key should have '' description
30+
assert.same(Symbol.for('').description, '', 'Symbol.for("").description');
31+
assert.same(Symbol.for('foo').description, 'foo', 'Symbol.for("foo").description');
2932
});

0 commit comments

Comments
 (0)