Skip to content

Commit

Permalink
avoid sharing internal [[DedentMap]] from String.dedent proposa b…
Browse files Browse the repository at this point in the history
…etween `core-js` instances before stabilization of the proposal
  • Loading branch information
zloirock committed Nov 15, 2023
1 parent cc2f8c1 commit d35fcf8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 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
- Fixed an issue getting the global object on Duktape, [#1303](https://github.com/zloirock/core-js/issues/1303)
- Avoid sharing internal `[[DedentMap]]` from [`String.dedent` proposal](https://github.com/tc39/proposal-string-dedent) between `core-js` instances before stabilization of the proposal
- Some internal untangling
- Compat data improvements:
- Added [Deno 1.38](https://deno.com/blog/v1.38) compat data mapping
Expand Down
19 changes: 7 additions & 12 deletions packages/core-js/modules/esnext.string.dedent.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';
var FREEZING = require('../internals/freezing');
var $ = require('../internals/export');
var shared = require('../internals/shared');
var getBuiltIn = require('../internals/get-built-in');
var makeBuiltIn = require('../internals/make-built-in');
var uncurryThis = require('../internals/function-uncurry-this');
var apply = require('../internals/function-apply');
Expand All @@ -12,18 +10,15 @@ var isCallable = require('../internals/is-callable');
var lengthOfArrayLike = require('../internals/length-of-array-like');
var defineProperty = require('../internals/object-define-property').f;
var createArrayFromList = require('../internals/array-slice-simple');
var WeakMapHelpers = require('../internals/weak-map-helpers');
var cooked = require('../internals/string-cooked');
var parse = require('../internals/string-parse');
var whitespaces = require('../internals/whitespaces');

var WeakMap = getBuiltIn('WeakMap');
var globalDedentRegistry = shared('GlobalDedentRegistry', new WeakMap());

/* eslint-disable no-self-assign -- prototype methods protection */
globalDedentRegistry.has = globalDedentRegistry.has;
globalDedentRegistry.get = globalDedentRegistry.get;
globalDedentRegistry.set = globalDedentRegistry.set;
/* eslint-enable no-self-assign -- prototype methods protection */
var DedentMap = new WeakMapHelpers.WeakMap();
var weakMapGet = WeakMapHelpers.get;
var weakMapHas = WeakMapHelpers.has;
var weakMapSet = WeakMapHelpers.set;

var $Array = Array;
var $TypeError = TypeError;
Expand All @@ -48,14 +43,14 @@ var dedentTemplateStringsArray = function (template) {
var rawInput = template.raw;
// https://github.com/tc39/proposal-string-dedent/issues/75
if (FREEZING && !isFrozen(rawInput)) throw new $TypeError('Raw template should be frozen');
if (globalDedentRegistry.has(rawInput)) return globalDedentRegistry.get(rawInput);
if (weakMapHas(DedentMap, rawInput)) return weakMapGet(DedentMap, rawInput);
var raw = dedentStringsArray(rawInput);
var cookedArr = cookStrings(raw);
defineProperty(cookedArr, 'raw', {
value: freeze(raw)
});
freeze(cookedArr);
globalDedentRegistry.set(rawInput, cookedArr);
weakMapSet(DedentMap, rawInput, cookedArr);
return cookedArr;
};

Expand Down

0 comments on commit d35fcf8

Please sign in to comment.