core-js 3.31.0 → 3.31.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/full/index.js CHANGED
@@ -394,8 +394,10 @@ require('../modules/esnext.string.at');
394
394
  require('../modules/esnext.string.cooked');
395
395
  require('../modules/esnext.string.code-points');
396
396
  require('../modules/esnext.string.dedent');
397
+ require('../modules/esnext.string.is-well-formed');
397
398
  require('../modules/esnext.string.match-all');
398
399
  require('../modules/esnext.string.replace-all');
400
+ require('../modules/esnext.string.to-well-formed');
399
401
  require('../modules/esnext.symbol.async-dispose');
400
402
  require('../modules/esnext.symbol.dispose');
401
403
  require('../modules/esnext.symbol.is-registered-symbol');
@@ -448,7 +450,5 @@ require('../modules/web.url-search-params');
448
450
  require('../modules/web.url-search-params.delete');
449
451
  require('../modules/web.url-search-params.has');
450
452
  require('../modules/web.url-search-params.size');
451
- require('../modules/esnext.string.is-well-formed');
452
- require('../modules/esnext.string.to-well-formed');
453
453
 
454
454
  module.exports = require('../internals/path');
@@ -79,23 +79,25 @@ var addGetter = function (Constructor, key, getInternalState) {
79
79
  };
80
80
 
81
81
  var get = function (view, count, index, isLittleEndian) {
82
- var intIndex = toIndex(index);
83
82
  var store = getInternalDataViewState(view);
83
+ var intIndex = toIndex(index);
84
+ var boolIsLittleEndian = !!isLittleEndian;
84
85
  if (intIndex + count > store.byteLength) throw RangeError(WRONG_INDEX);
85
86
  var bytes = store.bytes;
86
87
  var start = intIndex + store.byteOffset;
87
88
  var pack = arraySlice(bytes, start, start + count);
88
- return isLittleEndian ? pack : reverse(pack);
89
+ return boolIsLittleEndian ? pack : reverse(pack);
89
90
  };
90
91
 
91
92
  var set = function (view, count, index, conversion, value, isLittleEndian) {
92
- var intIndex = toIndex(index);
93
93
  var store = getInternalDataViewState(view);
94
+ var intIndex = toIndex(index);
95
+ var pack = conversion(+value);
96
+ var boolIsLittleEndian = !!isLittleEndian;
94
97
  if (intIndex + count > store.byteLength) throw RangeError(WRONG_INDEX);
95
98
  var bytes = store.bytes;
96
99
  var start = intIndex + store.byteOffset;
97
- var pack = conversion(+value);
98
- for (var i = 0; i < count; i++) bytes[start + i] = pack[isLittleEndian ? i : count - i - 1];
100
+ for (var i = 0; i < count; i++) bytes[start + i] = pack[boolIsLittleEndian ? i : count - i - 1];
99
101
  };
100
102
 
101
103
  if (!NATIVE_ARRAY_BUFFER) {
@@ -155,24 +157,24 @@ if (!NATIVE_ARRAY_BUFFER) {
155
157
  return get(this, 1, byteOffset)[0];
156
158
  },
157
159
  getInt16: function getInt16(byteOffset /* , littleEndian */) {
158
- var bytes = get(this, 2, byteOffset, arguments.length > 1 ? arguments[1] : undefined);
160
+ var bytes = get(this, 2, byteOffset, arguments.length > 1 ? arguments[1] : false);
159
161
  return (bytes[1] << 8 | bytes[0]) << 16 >> 16;
160
162
  },
161
163
  getUint16: function getUint16(byteOffset /* , littleEndian */) {
162
- var bytes = get(this, 2, byteOffset, arguments.length > 1 ? arguments[1] : undefined);
164
+ var bytes = get(this, 2, byteOffset, arguments.length > 1 ? arguments[1] : false);
163
165
  return bytes[1] << 8 | bytes[0];
164
166
  },
165
167
  getInt32: function getInt32(byteOffset /* , littleEndian */) {
166
- return unpackInt32(get(this, 4, byteOffset, arguments.length > 1 ? arguments[1] : undefined));
168
+ return unpackInt32(get(this, 4, byteOffset, arguments.length > 1 ? arguments[1] : false));
167
169
  },
168
170
  getUint32: function getUint32(byteOffset /* , littleEndian */) {
169
- return unpackInt32(get(this, 4, byteOffset, arguments.length > 1 ? arguments[1] : undefined)) >>> 0;
171
+ return unpackInt32(get(this, 4, byteOffset, arguments.length > 1 ? arguments[1] : false)) >>> 0;
170
172
  },
171
173
  getFloat32: function getFloat32(byteOffset /* , littleEndian */) {
172
- return unpackIEEE754(get(this, 4, byteOffset, arguments.length > 1 ? arguments[1] : undefined), 23);
174
+ return unpackIEEE754(get(this, 4, byteOffset, arguments.length > 1 ? arguments[1] : false), 23);
173
175
  },
174
176
  getFloat64: function getFloat64(byteOffset /* , littleEndian */) {
175
- return unpackIEEE754(get(this, 8, byteOffset, arguments.length > 1 ? arguments[1] : undefined), 52);
177
+ return unpackIEEE754(get(this, 8, byteOffset, arguments.length > 1 ? arguments[1] : false), 52);
176
178
  },
177
179
  setInt8: function setInt8(byteOffset, value) {
178
180
  set(this, 1, byteOffset, packInt8, value);
@@ -181,22 +183,22 @@ if (!NATIVE_ARRAY_BUFFER) {
181
183
  set(this, 1, byteOffset, packInt8, value);
182
184
  },
183
185
  setInt16: function setInt16(byteOffset, value /* , littleEndian */) {
184
- set(this, 2, byteOffset, packInt16, value, arguments.length > 2 ? arguments[2] : undefined);
186
+ set(this, 2, byteOffset, packInt16, value, arguments.length > 2 ? arguments[2] : false);
185
187
  },
186
188
  setUint16: function setUint16(byteOffset, value /* , littleEndian */) {
187
- set(this, 2, byteOffset, packInt16, value, arguments.length > 2 ? arguments[2] : undefined);
189
+ set(this, 2, byteOffset, packInt16, value, arguments.length > 2 ? arguments[2] : false);
188
190
  },
189
191
  setInt32: function setInt32(byteOffset, value /* , littleEndian */) {
190
- set(this, 4, byteOffset, packInt32, value, arguments.length > 2 ? arguments[2] : undefined);
192
+ set(this, 4, byteOffset, packInt32, value, arguments.length > 2 ? arguments[2] : false);
191
193
  },
192
194
  setUint32: function setUint32(byteOffset, value /* , littleEndian */) {
193
- set(this, 4, byteOffset, packInt32, value, arguments.length > 2 ? arguments[2] : undefined);
195
+ set(this, 4, byteOffset, packInt32, value, arguments.length > 2 ? arguments[2] : false);
194
196
  },
195
197
  setFloat32: function setFloat32(byteOffset, value /* , littleEndian */) {
196
- set(this, 4, byteOffset, packFloat32, value, arguments.length > 2 ? arguments[2] : undefined);
198
+ set(this, 4, byteOffset, packFloat32, value, arguments.length > 2 ? arguments[2] : false);
197
199
  },
198
200
  setFloat64: function setFloat64(byteOffset, value /* , littleEndian */) {
199
- set(this, 8, byteOffset, packFloat64, value, arguments.length > 2 ? arguments[2] : undefined);
201
+ set(this, 8, byteOffset, packFloat64, value, arguments.length > 2 ? arguments[2] : false);
200
202
  }
201
203
  });
202
204
  } else {
@@ -4,9 +4,9 @@ var store = require('../internals/shared-store');
4
4
  (module.exports = function (key, value) {
5
5
  return store[key] || (store[key] = value !== undefined ? value : {});
6
6
  })('versions', []).push({
7
- version: '3.31.0',
7
+ version: '3.31.1',
8
8
  mode: IS_PURE ? 'pure' : 'global',
9
9
  copyright: '© 2014-2023 Denis Pushkarev (zloirock.ru)',
10
- license: 'https://github.com/zloirock/core-js/blob/v3.31.0/LICENSE',
10
+ license: 'https://github.com/zloirock/core-js/blob/v3.31.1/LICENSE',
11
11
  source: 'https://github.com/zloirock/core-js'
12
12
  });
@@ -13,7 +13,7 @@ var FORCED = !fails(function () {
13
13
  return $AggregateError([1], AGGREGATE_ERROR, { cause: 7 }).cause !== 7;
14
14
  });
15
15
 
16
- // https://github.com/tc39/proposal-error-cause
16
+ // https://tc39.es/ecma262/#sec-aggregate-error
17
17
  $({ global: true, constructor: true, arity: 2, forced: FORCED }, {
18
18
  AggregateError: wrapErrorConstructorWithCause(AGGREGATE_ERROR, function (init) {
19
19
  // eslint-disable-next-line no-unused-vars -- required for functions `.length`
@@ -6,7 +6,7 @@ var toIntegerOrInfinity = require('../internals/to-integer-or-infinity');
6
6
  var addToUnscopables = require('../internals/add-to-unscopables');
7
7
 
8
8
  // `Array.prototype.at` method
9
- // https://github.com/tc39/proposal-relative-indexing-method
9
+ // https://tc39.es/ecma262/#sec-array.prototype.at
10
10
  $({ target: 'Array', proto: true }, {
11
11
  at: function at(index) {
12
12
  var O = toObject(this);
@@ -4,7 +4,7 @@ var $findLastIndex = require('../internals/array-iteration-from-last').findLastI
4
4
  var addToUnscopables = require('../internals/add-to-unscopables');
5
5
 
6
6
  // `Array.prototype.findLastIndex` method
7
- // https://github.com/tc39/proposal-array-find-from-last
7
+ // https://tc39.es/ecma262/#sec-array.prototype.findlastindex
8
8
  $({ target: 'Array', proto: true }, {
9
9
  findLastIndex: function findLastIndex(callbackfn /* , that = undefined */) {
10
10
  return $findLastIndex(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
@@ -4,7 +4,7 @@ var $findLast = require('../internals/array-iteration-from-last').findLast;
4
4
  var addToUnscopables = require('../internals/add-to-unscopables');
5
5
 
6
6
  // `Array.prototype.findLast` method
7
- // https://github.com/tc39/proposal-array-find-from-last
7
+ // https://tc39.es/ecma262/#sec-array.prototype.findlast
8
8
  $({ target: 'Array', proto: true }, {
9
9
  findLast: function findLast(callbackfn /* , that = undefined */) {
10
10
  return $findLast(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
@@ -7,7 +7,7 @@ var addToUnscopables = require('../internals/add-to-unscopables');
7
7
  var $Array = Array;
8
8
 
9
9
  // `Array.prototype.toReversed` method
10
- // https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.toReversed
10
+ // https://tc39.es/ecma262/#sec-array.prototype.toreversed
11
11
  $({ target: 'Array', proto: true }, {
12
12
  toReversed: function toReversed() {
13
13
  return arrayToReversed(toIndexedObject(this), $Array);
@@ -11,7 +11,7 @@ var $Array = Array;
11
11
  var sort = uncurryThis(getVirtual('Array').sort);
12
12
 
13
13
  // `Array.prototype.toSorted` method
14
- // https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.toSorted
14
+ // https://tc39.es/ecma262/#sec-array.prototype.tosorted
15
15
  $({ target: 'Array', proto: true }, {
16
16
  toSorted: function toSorted(compareFn) {
17
17
  if (compareFn !== undefined) aCallable(compareFn);
@@ -12,7 +12,7 @@ var max = Math.max;
12
12
  var min = Math.min;
13
13
 
14
14
  // `Array.prototype.toSpliced` method
15
- // https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.toSpliced
15
+ // https://tc39.es/ecma262/#sec-array.prototype.tospliced
16
16
  $({ target: 'Array', proto: true }, {
17
17
  toSpliced: function toSpliced(start, deleteCount /* , ...items */) {
18
18
  var O = toIndexedObject(this);
@@ -6,7 +6,7 @@ var toIndexedObject = require('../internals/to-indexed-object');
6
6
  var $Array = Array;
7
7
 
8
8
  // `Array.prototype.with` method
9
- // https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.with
9
+ // https://tc39.es/ecma262/#sec-array.prototype.with
10
10
  $({ target: 'Array', proto: true }, {
11
11
  'with': function (index, value) {
12
12
  return arrayWith(toIndexedObject(this), $Array, index, value);
@@ -24,7 +24,6 @@ var exportWebAssemblyErrorCauseWrapper = function (ERROR_NAME, wrapper) {
24
24
  };
25
25
 
26
26
  // https://tc39.es/ecma262/#sec-nativeerror
27
- // https://github.com/tc39/proposal-error-cause
28
27
  exportGlobalErrorCauseWrapper('Error', function (init) {
29
28
  return function Error(message) { return apply(init, this, arguments); };
30
29
  });
@@ -2,7 +2,7 @@ var $ = require('../internals/export');
2
2
  var hasOwn = require('../internals/has-own-property');
3
3
 
4
4
  // `Object.hasOwn` method
5
- // https://github.com/tc39/proposal-accessible-object-hasownproperty
5
+ // https://tc39.es/ecma262/#sec-object.hasown
6
6
  $({ target: 'Object', stat: true }, {
7
7
  hasOwn: hasOwn
8
8
  });
@@ -14,7 +14,7 @@ var FORCED = fails(function () {
14
14
  });
15
15
 
16
16
  // `String.prototype.at` method
17
- // https://github.com/tc39/proposal-relative-indexing-method
17
+ // https://tc39.es/ecma262/#sec-string.prototype.at
18
18
  $({ target: 'String', proto: true, forced: FORCED }, {
19
19
  at: function at(index) {
20
20
  var S = toString(requireObjectCoercible(this));
@@ -7,7 +7,7 @@ var aTypedArray = ArrayBufferViewCore.aTypedArray;
7
7
  var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
8
8
 
9
9
  // `%TypedArray%.prototype.at` method
10
- // https://github.com/tc39/proposal-relative-indexing-method
10
+ // https://tc39.es/ecma262/#sec-%typedarray%.prototype.at
11
11
  exportTypedArrayMethod('at', function at(index) {
12
12
  var O = aTypedArray(this);
13
13
  var len = lengthOfArrayLike(O);
@@ -6,7 +6,7 @@ var aTypedArray = ArrayBufferViewCore.aTypedArray;
6
6
  var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
7
7
 
8
8
  // `%TypedArray%.prototype.findLastIndex` method
9
- // https://github.com/tc39/proposal-array-find-from-last
9
+ // https://tc39.es/ecma262/#sec-%typedarray%.prototype.findlastindex
10
10
  exportTypedArrayMethod('findLastIndex', function findLastIndex(predicate /* , thisArg */) {
11
11
  return $findLastIndex(aTypedArray(this), predicate, arguments.length > 1 ? arguments[1] : undefined);
12
12
  });
@@ -6,7 +6,7 @@ var aTypedArray = ArrayBufferViewCore.aTypedArray;
6
6
  var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
7
7
 
8
8
  // `%TypedArray%.prototype.findLast` method
9
- // https://github.com/tc39/proposal-array-find-from-last
9
+ // https://tc39.es/ecma262/#sec-%typedarray%.prototype.findlast
10
10
  exportTypedArrayMethod('findLast', function findLast(predicate /* , thisArg */) {
11
11
  return $findLast(aTypedArray(this), predicate, arguments.length > 1 ? arguments[1] : undefined);
12
12
  });
@@ -7,7 +7,7 @@ var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
7
7
  var getTypedArrayConstructor = ArrayBufferViewCore.getTypedArrayConstructor;
8
8
 
9
9
  // `%TypedArray%.prototype.toReversed` method
10
- // https://tc39.es/proposal-change-array-by-copy/#sec-%typedarray%.prototype.toReversed
10
+ // https://tc39.es/ecma262/#sec-%typedarray%.prototype.toreversed
11
11
  exportTypedArrayMethod('toReversed', function toReversed() {
12
12
  return arrayToReversed(aTypedArray(this), getTypedArrayConstructor(this));
13
13
  });
@@ -10,7 +10,7 @@ var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
10
10
  var sort = uncurryThis(ArrayBufferViewCore.TypedArrayPrototype.sort);
11
11
 
12
12
  // `%TypedArray%.prototype.toSorted` method
13
- // https://tc39.es/proposal-change-array-by-copy/#sec-%typedarray%.prototype.toSorted
13
+ // https://tc39.es/ecma262/#sec-%typedarray%.prototype.tosorted
14
14
  exportTypedArrayMethod('toSorted', function toSorted(compareFn) {
15
15
  if (compareFn !== undefined) aCallable(compareFn);
16
16
  var O = aTypedArray(this);
@@ -21,7 +21,7 @@ var PROPER_ORDER = !!function () {
21
21
  }();
22
22
 
23
23
  // `%TypedArray%.prototype.with` method
24
- // https://tc39.es/proposal-change-array-by-copy/#sec-%typedarray%.prototype.with
24
+ // https://tc39.es/ecma262/#sec-%typedarray%.prototype.with
25
25
  exportTypedArrayMethod('with', { 'with': function (index, value) {
26
26
  var O = aTypedArray(this);
27
27
  var relativeIndex = toIntegerOrInfinity(index);
@@ -142,7 +142,61 @@ var createDataTransfer = function () {
142
142
  return dataTransfer && dataTransfer.items && dataTransfer.files ? dataTransfer : null;
143
143
  };
144
144
 
145
- var structuredCloneInternal = function (value, map) {
145
+ var cloneBuffer = function (value, map, $type) {
146
+ if (mapHas(map, value)) return mapGet(map, value);
147
+
148
+ var type = $type || classof(value);
149
+ var clone, length, options, source, target, i;
150
+
151
+ if (type === 'SharedArrayBuffer') {
152
+ if (nativeRestrictedStructuredClone) clone = nativeRestrictedStructuredClone(value);
153
+ // SharedArrayBuffer should use shared memory, we can't polyfill it, so return the original
154
+ else clone = value;
155
+ } else {
156
+ var DataView = global.DataView;
157
+
158
+ // `ArrayBuffer#slice` is not available in IE10
159
+ // `ArrayBuffer#slice` and `DataView` are not available in old FF
160
+ if (!DataView && typeof value.slice != 'function') throwUnpolyfillable('ArrayBuffer');
161
+ // detached buffers throws in `DataView` and `.slice`
162
+ try {
163
+ if (typeof value.slice == 'function' && !value.resizable) {
164
+ clone = value.slice(0);
165
+ } else {
166
+ length = value.byteLength;
167
+ options = 'maxByteLength' in value ? { maxByteLength: value.maxByteLength } : undefined;
168
+ clone = new ArrayBuffer(length, options);
169
+ source = new DataView(value);
170
+ target = new DataView(clone);
171
+ for (i = 0; i < length; i++) {
172
+ target.setUint8(i, source.getUint8(i));
173
+ }
174
+ }
175
+ } catch (error) {
176
+ throw new DOMException('ArrayBuffer is detached', DATA_CLONE_ERROR);
177
+ }
178
+ }
179
+
180
+ mapSet(map, value, clone);
181
+
182
+ return clone;
183
+ };
184
+
185
+ var cloneView = function (value, type, offset, length, map) {
186
+ var C = global[type];
187
+ // in some old engines like Safari 9, typeof C is 'object'
188
+ // on Uint8ClampedArray or some other constructors
189
+ if (!isObject(C)) throwUnpolyfillable(type);
190
+ return new C(cloneBuffer(value.buffer, map), offset, length);
191
+ };
192
+
193
+ var Placeholder = function (object, type, metadata) {
194
+ this.object = object;
195
+ this.type = type;
196
+ this.metadata = metadata;
197
+ };
198
+
199
+ var structuredCloneInternal = function (value, map, transferredBuffers) {
146
200
  if (isSymbol(value)) throwUncloneable('Symbol');
147
201
  if (!isObject(value)) return value;
148
202
  // effectively preserves circular references
@@ -151,25 +205,20 @@ var structuredCloneInternal = function (value, map) {
151
205
  } else map = new Map();
152
206
 
153
207
  var type = classof(value);
154
- var deep = false;
155
- var C, name, cloned, dataTransfer, i, length, keys, key, source, target, options;
208
+ var C, name, cloned, dataTransfer, i, length, keys, key;
156
209
 
157
210
  switch (type) {
158
211
  case 'Array':
159
212
  cloned = Array(lengthOfArrayLike(value));
160
- deep = true;
161
213
  break;
162
214
  case 'Object':
163
215
  cloned = {};
164
- deep = true;
165
216
  break;
166
217
  case 'Map':
167
218
  cloned = new Map();
168
- deep = true;
169
219
  break;
170
220
  case 'Set':
171
221
  cloned = new Set();
172
- deep = true;
173
222
  break;
174
223
  case 'RegExp':
175
224
  // in this block because of a Safari 14.1 bug
@@ -212,11 +261,15 @@ var structuredCloneInternal = function (value, map) {
212
261
  default:
213
262
  cloned = Error();
214
263
  }
215
- deep = true;
216
264
  break;
217
265
  case 'DOMException':
218
266
  cloned = new DOMException(value.message, value.name);
219
- deep = true;
267
+ break;
268
+ case 'ArrayBuffer':
269
+ case 'SharedArrayBuffer':
270
+ cloned = transferredBuffers
271
+ ? new Placeholder(value, type)
272
+ : cloneBuffer(value, map, type);
220
273
  break;
221
274
  case 'DataView':
222
275
  case 'Int8Array':
@@ -226,28 +279,23 @@ var structuredCloneInternal = function (value, map) {
226
279
  case 'Uint16Array':
227
280
  case 'Int32Array':
228
281
  case 'Uint32Array':
282
+ case 'Float16Array':
229
283
  case 'Float32Array':
230
284
  case 'Float64Array':
231
285
  case 'BigInt64Array':
232
286
  case 'BigUint64Array':
233
- C = global[type];
234
- // in some old engines like Safari 9, typeof C is 'object'
235
- // on Uint8ClampedArray or some other constructors
236
- if (!isObject(C)) throwUnpolyfillable(type);
237
- cloned = new C(
238
- // this is safe, since arraybuffer cannot have circular references
239
- structuredCloneInternal(value.buffer, map),
240
- value.byteOffset,
241
- type === 'DataView' ? value.byteLength : value.length
242
- );
287
+ length = type === 'DataView' ? value.byteLength : value.length;
288
+ cloned = transferredBuffers
289
+ ? new Placeholder(value, type, { offset: value.byteOffset, length: length })
290
+ : cloneView(value, type, value.byteOffset, length, map);
243
291
  break;
244
292
  case 'DOMQuad':
245
293
  try {
246
294
  cloned = new DOMQuad(
247
- structuredCloneInternal(value.p1, map),
248
- structuredCloneInternal(value.p2, map),
249
- structuredCloneInternal(value.p3, map),
250
- structuredCloneInternal(value.p4, map)
295
+ structuredCloneInternal(value.p1, map, transferredBuffers),
296
+ structuredCloneInternal(value.p2, map, transferredBuffers),
297
+ structuredCloneInternal(value.p3, map, transferredBuffers),
298
+ structuredCloneInternal(value.p4, map, transferredBuffers)
251
299
  );
252
300
  } catch (error) {
253
301
  cloned = tryNativeRestrictedStructuredClone(value, type);
@@ -268,7 +316,7 @@ var structuredCloneInternal = function (value, map) {
268
316
  dataTransfer = createDataTransfer();
269
317
  if (dataTransfer) {
270
318
  for (i = 0, length = lengthOfArrayLike(value); i < length; i++) {
271
- dataTransfer.items.add(structuredCloneInternal(value[i], map));
319
+ dataTransfer.items.add(structuredCloneInternal(value[i], map, transferredBuffers));
272
320
  }
273
321
  cloned = dataTransfer.files;
274
322
  } else cloned = tryNativeRestrictedStructuredClone(value, type);
@@ -277,7 +325,7 @@ var structuredCloneInternal = function (value, map) {
277
325
  // Safari 9 ImageData is a constructor, but typeof ImageData is 'object'
278
326
  try {
279
327
  cloned = new ImageData(
280
- structuredCloneInternal(value.data, map),
328
+ structuredCloneInternal(value.data, map, transferredBuffers),
281
329
  value.width,
282
330
  value.height,
283
331
  { colorSpace: value.colorSpace }
@@ -305,32 +353,6 @@ var structuredCloneInternal = function (value, map) {
305
353
  case 'Date':
306
354
  cloned = new Date(thisTimeValue(value));
307
355
  break;
308
- case 'ArrayBuffer':
309
- C = global.DataView;
310
- // `ArrayBuffer#slice` is not available in IE10
311
- // `ArrayBuffer#slice` and `DataView` are not available in old FF
312
- if (!C && typeof value.slice != 'function') throwUnpolyfillable(type);
313
- // detached buffers throws in `DataView` and `.slice`
314
- try {
315
- if (typeof value.slice == 'function' && !value.resizable) {
316
- cloned = value.slice(0);
317
- } else {
318
- length = value.byteLength;
319
- options = 'maxByteLength' in value ? { maxByteLength: value.maxByteLength } : undefined;
320
- cloned = new ArrayBuffer(length, options);
321
- source = new C(value);
322
- target = new C(cloned);
323
- for (i = 0; i < length; i++) {
324
- target.setUint8(i, source.getUint8(i));
325
- }
326
- }
327
- } catch (error) {
328
- throw new DOMException('ArrayBuffer is detached', DATA_CLONE_ERROR);
329
- } break;
330
- case 'SharedArrayBuffer':
331
- // SharedArrayBuffer should use shared memory, we can't polyfill it, so return the original
332
- cloned = value;
333
- break;
334
356
  case 'Blob':
335
357
  try {
336
358
  cloned = value.slice(0, value.size, value.type);
@@ -394,41 +416,111 @@ var structuredCloneInternal = function (value, map) {
394
416
 
395
417
  mapSet(map, value, cloned);
396
418
 
397
- if (deep) switch (type) {
419
+ switch (type) {
398
420
  case 'Array':
399
421
  case 'Object':
400
422
  keys = objectKeys(value);
401
423
  for (i = 0, length = lengthOfArrayLike(keys); i < length; i++) {
402
424
  key = keys[i];
403
- createProperty(cloned, key, structuredCloneInternal(value[key], map));
425
+ createProperty(cloned, key, structuredCloneInternal(value[key], map, transferredBuffers));
404
426
  } break;
405
427
  case 'Map':
406
428
  value.forEach(function (v, k) {
407
- mapSet(cloned, structuredCloneInternal(k, map), structuredCloneInternal(v, map));
429
+ mapSet(cloned, structuredCloneInternal(k, map, transferredBuffers), structuredCloneInternal(v, map, transferredBuffers));
408
430
  });
409
431
  break;
410
432
  case 'Set':
411
433
  value.forEach(function (v) {
412
- setAdd(cloned, structuredCloneInternal(v, map));
434
+ setAdd(cloned, structuredCloneInternal(v, map, transferredBuffers));
413
435
  });
414
436
  break;
415
437
  case 'Error':
416
- createNonEnumerableProperty(cloned, 'message', structuredCloneInternal(value.message, map));
438
+ createNonEnumerableProperty(cloned, 'message', structuredCloneInternal(value.message, map, transferredBuffers));
417
439
  if (hasOwn(value, 'cause')) {
418
- createNonEnumerableProperty(cloned, 'cause', structuredCloneInternal(value.cause, map));
440
+ createNonEnumerableProperty(cloned, 'cause', structuredCloneInternal(value.cause, map, transferredBuffers));
419
441
  }
420
442
  if (name == 'AggregateError') {
421
- cloned.errors = structuredCloneInternal(value.errors, map);
443
+ cloned.errors = structuredCloneInternal(value.errors, map, transferredBuffers);
422
444
  } // break omitted
423
445
  case 'DOMException':
424
446
  if (ERROR_STACK_INSTALLABLE) {
425
- createNonEnumerableProperty(cloned, 'stack', structuredCloneInternal(value.stack, map));
447
+ createNonEnumerableProperty(cloned, 'stack', structuredCloneInternal(value.stack, map, transferredBuffers));
426
448
  }
427
449
  }
428
450
 
429
451
  return cloned;
430
452
  };
431
453
 
454
+ var replacePlaceholders = function (value, map) {
455
+ if (!isObject(value)) return value;
456
+ if (mapHas(map, value)) return mapGet(map, value);
457
+
458
+ var type, object, metadata, i, length, keys, key, replacement;
459
+
460
+ if (value instanceof Placeholder) {
461
+ type = value.type;
462
+ object = value.object;
463
+
464
+ switch (type) {
465
+ case 'ArrayBuffer':
466
+ case 'SharedArrayBuffer':
467
+ replacement = cloneBuffer(object, map, type);
468
+ break;
469
+ case 'DataView':
470
+ case 'Int8Array':
471
+ case 'Uint8Array':
472
+ case 'Uint8ClampedArray':
473
+ case 'Int16Array':
474
+ case 'Uint16Array':
475
+ case 'Int32Array':
476
+ case 'Uint32Array':
477
+ case 'Float16Array':
478
+ case 'Float32Array':
479
+ case 'Float64Array':
480
+ case 'BigInt64Array':
481
+ case 'BigUint64Array':
482
+ metadata = value.metadata;
483
+ replacement = cloneView(object, type, metadata.offset, metadata.length, map);
484
+ }
485
+ } else switch (classof(value)) {
486
+ case 'Array':
487
+ case 'Object':
488
+ keys = objectKeys(value);
489
+ for (i = 0, length = lengthOfArrayLike(keys); i < length; i++) {
490
+ key = keys[i];
491
+ value[key] = replacePlaceholders(value[key], map);
492
+ } break;
493
+ case 'Map':
494
+ replacement = new Map();
495
+ value.forEach(function (v, k) {
496
+ mapSet(replacement, replacePlaceholders(k, map), replacePlaceholders(v, map));
497
+ });
498
+ break;
499
+ case 'Set':
500
+ replacement = new Set();
501
+ value.forEach(function (v) {
502
+ setAdd(replacement, replacePlaceholders(v, map));
503
+ });
504
+ break;
505
+ case 'Error':
506
+ value.message = replacePlaceholders(value.message, map);
507
+ if (hasOwn(value, 'cause')) {
508
+ value.cause = replacePlaceholders(value.cause, map);
509
+ }
510
+ if (value.name == 'AggregateError') {
511
+ value.errors = replacePlaceholders(value.errors, map);
512
+ } // break omitted
513
+ case 'DOMException':
514
+ if (ERROR_STACK_INSTALLABLE) {
515
+ value.stack = replacePlaceholders(value.stack, map);
516
+ }
517
+ }
518
+
519
+ mapSet(map, value, replacement || value);
520
+
521
+ return replacement || value;
522
+ };
523
+
432
524
  var tryToTransfer = function (rawTransfer, map) {
433
525
  if (!isObject(rawTransfer)) throw TypeError('Transfer option cannot be converted to a sequence');
434
526
 
@@ -440,18 +532,24 @@ var tryToTransfer = function (rawTransfer, map) {
440
532
 
441
533
  var i = 0;
442
534
  var length = lengthOfArrayLike(transfer);
443
- var value, type, C, transferredArray, transferred, canvas, context;
535
+ var buffers = [];
536
+ var value, type, C, transferred, canvas, context;
444
537
 
445
- if (PROPER_TRANSFER) {
446
- transferredArray = nativeStructuredClone(transfer, { transfer: transfer });
447
- while (i < length) mapSet(map, transfer[i], transferredArray[i++]);
448
- } else while (i < length) {
538
+ while (i < length) {
449
539
  value = transfer[i++];
450
- if (mapHas(map, value)) throw new DOMException('Duplicate transferable', DATA_CLONE_ERROR);
451
540
 
452
541
  type = classof(value);
453
542
 
454
- switch (type) {
543
+ if (type === 'ArrayBuffer') {
544
+ push(buffers, value);
545
+ continue;
546
+ }
547
+
548
+ if (mapHas(map, value)) throw new DOMException('Duplicate transferable', DATA_CLONE_ERROR);
549
+
550
+ if (PROPER_TRANSFER) {
551
+ transferred = nativeStructuredClone(value, { transfer: [value] });
552
+ } else switch (type) {
455
553
  case 'ImageBitmap':
456
554
  C = global.OffscreenCanvas;
457
555
  if (!isConstructor(C)) throwUnpolyfillable(type, TRANSFERRING);
@@ -470,10 +568,6 @@ var tryToTransfer = function (rawTransfer, map) {
470
568
  value.close();
471
569
  } catch (error) { /* empty */ }
472
570
  break;
473
- case 'ArrayBuffer':
474
- if (!isCallable(value.transfer)) throwUnpolyfillable(type, TRANSFERRING);
475
- transferred = value.transfer();
476
- break;
477
571
  case 'MediaSourceHandle':
478
572
  case 'MessagePort':
479
573
  case 'OffscreenCanvas':
@@ -484,6 +578,30 @@ var tryToTransfer = function (rawTransfer, map) {
484
578
  }
485
579
 
486
580
  if (transferred === undefined) throw new DOMException('This object cannot be transferred: ' + type, DATA_CLONE_ERROR);
581
+
582
+ mapSet(map, value, transferred);
583
+ }
584
+
585
+ return buffers;
586
+ };
587
+
588
+ var tryToTransferBuffers = function (transfer, map) {
589
+ var i = 0;
590
+ var length = lengthOfArrayLike(transfer);
591
+ var value, transferred;
592
+
593
+ while (i < length) {
594
+ value = transfer[i++];
595
+
596
+ if (mapHas(map, value)) throw new DOMException('Duplicate transferable', DATA_CLONE_ERROR);
597
+
598
+ if (PROPER_TRANSFER) {
599
+ transferred = nativeStructuredClone(value, { transfer: [value] });
600
+ } else {
601
+ if (!isCallable(value.transfer)) throwUnpolyfillable('ArrayBuffer', TRANSFERRING);
602
+ transferred = value.transfer();
603
+ }
604
+
487
605
  mapSet(map, value, transferred);
488
606
  }
489
607
  };
@@ -494,13 +612,25 @@ $({ global: true, enumerable: true, sham: !PROPER_TRANSFER, forced: FORCED_REPLA
494
612
  structuredClone: function structuredClone(value /* , { transfer } */) {
495
613
  var options = validateArgumentsLength(arguments.length, 1) > 1 && !isNullOrUndefined(arguments[1]) ? anObject(arguments[1]) : undefined;
496
614
  var transfer = options ? options.transfer : undefined;
497
- var map;
615
+ var transferredBuffers = false;
616
+ var map, buffers;
498
617
 
499
618
  if (transfer !== undefined) {
500
619
  map = new Map();
501
- tryToTransfer(transfer, map);
620
+ buffers = tryToTransfer(transfer, map);
621
+ transferredBuffers = !!lengthOfArrayLike(buffers);
622
+ }
623
+
624
+ var clone = structuredCloneInternal(value, map, transferredBuffers);
625
+
626
+ // since of an issue with cloning views of transferred buffers, we a forced to transfer / clone them in 2 steps
627
+ // https://github.com/zloirock/core-js/issues/1265
628
+ if (transferredBuffers) {
629
+ map = new Map();
630
+ tryToTransferBuffers(transfer, map);
631
+ clone = replacePlaceholders(clone, map);
502
632
  }
503
633
 
504
- return structuredCloneInternal(value, map);
634
+ return clone;
505
635
  }
506
636
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "core-js",
3
- "version": "3.31.0",
3
+ "version": "3.31.1",
4
4
  "description": "Standard library",
5
5
  "keywords": [
6
6
  "ES3",