Skip to content

Commit

Permalink
added a workaround for Chrome 38-40 bug which does not allow to inher…
Browse files Browse the repository at this point in the history
…it symbols (incl. well-known) from DOM collections prototypes to instances

#37
#406
  • Loading branch information
zloirock committed Feb 28, 2021
1 parent a136e4d commit 2394dac
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Changelog
##### Unreleased
- Added a workaround for Chrome 38-40 bug which does not allow to inherit symbols (incl. well-known) from DOM collections prototypes to instances, [#37](https://github.com/zloirock/core-js/issues/37)
- Used `NumericRangeIterator` as toStringTag instead of `RangeIterator` in `{ Number, BigInt }.range` iterator, per [this PR](https://github.com/tc39/proposal-Number.range/pull/46)
- TypedArray constructors marked as supported from Safari 14.0
- Updated compat data mapping for iOS Safari and Opera for Android
Expand Down
6 changes: 3 additions & 3 deletions packages/core-js-compat/src/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const data = {
safari: '10.0',
},
'es.symbol.iterator': {
chrome: '39',
chrome: '41',
edge: '13',
firefox: '36',
safari: '9.0',
Expand Down Expand Up @@ -78,7 +78,7 @@ const data = {
safari: '10.0',
},
'es.symbol.unscopables': {
chrome: '39',
chrome: '41',
edge: '13',
firefox: '48',
safari: '9.0',
Expand Down Expand Up @@ -880,7 +880,7 @@ const data = {
safari: '10.0',
},
'es.string.iterator': {
chrome: '39',
chrome: '41',
edge: '13',
firefox: '36',
safari: '9.0',
Expand Down
8 changes: 6 additions & 2 deletions packages/core-js/internals/native-symbol.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
var IS_NODE = require('../internals/engine-is-node');
var V8_VERSION = require('../internals/engine-v8-version');
var fails = require('../internals/fails');

module.exports = !!Object.getOwnPropertySymbols && !fails(function () {
// Chrome 38 Symbol has incorrect toString conversion
/* global Symbol -- required for testing */
return !String(Symbol());
return !Symbol.sham &&
// Chrome 38 Symbol has incorrect toString conversion
// Chrome 38-40 symbols are not inherited from DOM collections prototypes to instances
(IS_NODE ? V8_VERSION === 38 : V8_VERSION > 37 && V8_VERSION < 41);
});
9 changes: 6 additions & 3 deletions packages/core-js/internals/well-known-symbol.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ var Symbol = global.Symbol;
var createWellKnownSymbol = USE_SYMBOL_AS_UID ? Symbol : Symbol && Symbol.withoutSetter || uid;

module.exports = function (name) {
if (!has(WellKnownSymbolsStore, name)) {
if (NATIVE_SYMBOL && has(Symbol, name)) WellKnownSymbolsStore[name] = Symbol[name];
else WellKnownSymbolsStore[name] = createWellKnownSymbol('Symbol.' + name);
if (!has(WellKnownSymbolsStore, name) || !(NATIVE_SYMBOL || typeof WellKnownSymbolsStore[name] == 'string')) {
if (NATIVE_SYMBOL && has(Symbol, name)) {
WellKnownSymbolsStore[name] = Symbol[name];
} else {
WellKnownSymbolsStore[name] = createWellKnownSymbol('Symbol.' + name);
}
} return WellKnownSymbolsStore[name];
};
27 changes: 20 additions & 7 deletions tests/compat/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@ var NOT_WHITESPACES = '\u200B\u0085\u180E';

var USERAGENT = GLOBAL.navigator && GLOBAL.navigator.userAgent || '';

var process = GLOBAL.process;
var v8 = process && process.versions && process.versions.v8 || '';

var match, V8_VERSION;

if (v8) {
match = v8.split('.');
V8_VERSION = +(match[0] + match[1]);
} else if (USERAGENT) {
match = USERAGENT.match(/Edge\/(\d+)/);
if (!match || match[1] >= 74) {
match = USERAGENT.match(/Chrome\/(\d+)/);
if (match) V8_VERSION = +match[1];
}
}

var IS_NODE = Object.prototype.toString.call(process) == '[object process]';

// eslint-disable-next-line unicorn/no-unsafe-regex -- safe
var WEBKIT_STRING_PAD_BUG = /Version\/10\.\d+(\.\d+)?( Mobile\/\w+)? Safari\//.test(USERAGENT);

Expand All @@ -16,10 +34,6 @@ var DESCRIPTORS_SUPPORT = function () {
};

var PROMISES_SUPPORT = function () {
var process = GLOBAL.process;
var IS_NODE = Object.prototype.toString.call(process) == '[object process]';
var v8 = process && process.versions && process.versions.v8 || '';

var promise = Promise.resolve(1);
var empty = function () { /* empty */ };
var FakePromise = (promise.constructor = {})[Symbol.species] = function (exec) {
Expand All @@ -28,12 +42,11 @@ var PROMISES_SUPPORT = function () {

return (IS_NODE || typeof PromiseRejectionEvent == 'function')
&& promise.then(empty) instanceof FakePromise
&& v8.indexOf('6.6') !== 0
&& USERAGENT.indexOf('Chrome/66') === -1;
&& V8_VERSION !== 66;
};

var SYMBOLS_SUPPORT = function () {
return String(Symbol());
return Symbol && (IS_NODE ? V8_VERSION !== 38 : V8_VERSION < 38 || V8_VERSION > 40);
};

var URL_AND_URL_SEARCH_PARAMS_SUPPORT = function () {
Expand Down

0 comments on commit 2394dac

Please sign in to comment.