Skip to content

Commit

Permalink
add an extra workaround of errors with exotic environment objects in …
Browse files Browse the repository at this point in the history
…`Symbol` polyfill, close #1289
  • Loading branch information
zloirock committed Sep 17, 2023
1 parent 45292f8 commit 06b4703
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Changelog
##### Unreleased
- Fully forced polyfilling of [the TC39 `Observable` proposal](https://github.com/tc39/proposal-observable) because of incompatibility with [the new WHATWG `Observable` proposal](https://github.com/WICG/observable)
- Added an extra workaround of errors with exotic environment objects in `Symbol` polyfill, [#1289](https://github.com/zloirock/core-js/issues/1289)
- Compat data improvements:
- V8 unshipped [`Iterator` helpers](https://github.com/tc39/proposal-iterator-helpers) because of [some Web compatibility issues](https://github.com/tc39/proposal-iterator-helpers/issues/286)
- [`Array` grouping proposal](https://github.com/tc39/proposal-array-grouping) features marked as [supported from FF119](https://bugzilla.mozilla.org/show_bug.cgi?id=1792650#c9)
Expand Down
21 changes: 14 additions & 7 deletions packages/core-js/modules/es.symbol.constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,20 @@ var WellKnownSymbolsStore = shared('wks');
var USE_SETTER = !QObject || !QObject[PROTOTYPE] || !QObject[PROTOTYPE].findChild;

// fallback for old Android, https://code.google.com/p/v8/issues/detail?id=687
var setSymbolDescriptor = DESCRIPTORS && fails(function () {
return nativeObjectCreate(nativeDefineProperty({}, 'a', {
get: function () { return nativeDefineProperty(this, 'a', { value: 7 }).a; }
})).a !== 7;
}) ? function (O, P, Attributes) {
var fallbackDefineProperty = function (O, P, Attributes) {
var ObjectPrototypeDescriptor = nativeGetOwnPropertyDescriptor(ObjectPrototype, P);
if (ObjectPrototypeDescriptor) delete ObjectPrototype[P];
nativeDefineProperty(O, P, Attributes);
if (ObjectPrototypeDescriptor && O !== ObjectPrototype) {
nativeDefineProperty(ObjectPrototype, P, ObjectPrototypeDescriptor);
}
} : nativeDefineProperty;
};

var setSymbolDescriptor = DESCRIPTORS && fails(function () {
return nativeObjectCreate(nativeDefineProperty({}, 'a', {
get: function () { return nativeDefineProperty(this, 'a', { value: 7 }).a; }
})).a !== 7;
}) ? fallbackDefineProperty : nativeDefineProperty;

var wrap = function (tag, description) {
var symbol = AllSymbols[tag] = nativeObjectCreate(SymbolPrototype);
Expand Down Expand Up @@ -167,7 +169,12 @@ if (!NATIVE_SYMBOL) {
var setter = function (value) {
if (this === ObjectPrototype) call(setter, ObjectPrototypeSymbols, value);
if (hasOwn(this, HIDDEN) && hasOwn(this[HIDDEN], tag)) this[HIDDEN][tag] = false;
setSymbolDescriptor(this, tag, createPropertyDescriptor(1, value));
var descriptor = createPropertyDescriptor(1, value);
try {
setSymbolDescriptor(this, tag, descriptor);
} catch (error) {
fallbackDefineProperty(this, tag, descriptor);
}
};
if (DESCRIPTORS && USE_SETTER) setSymbolDescriptor(ObjectPrototype, tag, { configurable: true, set: setter });
return wrap(tag, description);
Expand Down

0 comments on commit 06b4703

Please sign in to comment.