Skip to content

Commit

Permalink
protect polyfilled built-in constructors from calling on instances
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Apr 16, 2021
1 parent 25d67d1 commit 8355c43
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Changelog
##### Unreleased
- Nothing
- Polyfilled built-in constructors protected from calling on instances

##### 3.10.1 - 2021.04.08
- Prevented possible `RegExp#split` problems in old engines, [#751](https://github.com/zloirock/core-js/issues/751), [#919](https://github.com/zloirock/core-js/issues/919)
Expand Down
3 changes: 3 additions & 0 deletions packages/core-js/internals/internal-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var shared = require('../internals/shared-store');
var sharedKey = require('../internals/shared-key');
var hiddenKeys = require('../internals/hidden-keys');

var OBJECT_ALREADY_INITIALIZED = 'Object already initialized';
var WeakMap = global.WeakMap;
var set, get, has;

Expand All @@ -29,6 +30,7 @@ if (NATIVE_WEAK_MAP) {
var wmhas = store.has;
var wmset = store.set;
set = function (it, metadata) {
if (wmhas.call(store, it)) throw new TypeError(OBJECT_ALREADY_INITIALIZED);
metadata.facade = it;
wmset.call(store, it, metadata);
return metadata;
Expand All @@ -43,6 +45,7 @@ if (NATIVE_WEAK_MAP) {
var STATE = sharedKey('state');
hiddenKeys[STATE] = true;
set = function (it, metadata) {
if (objectHas(it, STATE)) throw new TypeError(OBJECT_ALREADY_INITIALIZED);
metadata.facade = it;
createNonEnumerableProperty(it, STATE, metadata);
return metadata;
Expand Down

0 comments on commit 8355c43

Please sign in to comment.