core-js-pure
Advanced tools
Comparing version 3.31.0 to 3.31.1
@@ -397,4 +397,6 @@ require('../modules/es.symbol'); | ||
require('../modules/esnext.string.dedent'); | ||
require('../modules/esnext.string.is-well-formed'); | ||
require('../modules/esnext.string.match-all'); | ||
require('../modules/esnext.string.replace-all'); | ||
require('../modules/esnext.string.to-well-formed'); | ||
require('../modules/esnext.symbol.async-dispose'); | ||
@@ -452,5 +454,3 @@ require('../modules/esnext.symbol.dispose'); | ||
require('../modules/web.url-search-params.size'); | ||
require('../modules/esnext.string.is-well-formed'); | ||
require('../modules/esnext.string.to-well-formed'); | ||
module.exports = require('../internals/path'); |
@@ -7,7 +7,7 @@ var IS_PURE = require('../internals/is-pure'); | ||
})('versions', []).push({ | ||
version: '3.31.0', | ||
version: '3.31.1', | ||
mode: IS_PURE ? 'pure' : 'global', | ||
copyright: '© 2014-2023 Denis Pushkarev (zloirock.ru)', | ||
license: 'https://github.com/zloirock/core-js/blob/v3.31.0/LICENSE', | ||
license: 'https://github.com/zloirock/core-js/blob/v3.31.1/LICENSE', | ||
source: 'https://github.com/zloirock/core-js' | ||
}); |
@@ -16,3 +16,3 @@ var $ = require('../internals/export'); | ||
// https://github.com/tc39/proposal-error-cause | ||
// https://tc39.es/ecma262/#sec-aggregate-error | ||
$({ global: true, constructor: true, arity: 2, forced: FORCED }, { | ||
@@ -19,0 +19,0 @@ AggregateError: wrapErrorConstructorWithCause(AGGREGATE_ERROR, function (init) { |
@@ -9,3 +9,3 @@ 'use strict'; | ||
// `Array.prototype.at` method | ||
// https://github.com/tc39/proposal-relative-indexing-method | ||
// https://tc39.es/ecma262/#sec-array.prototype.at | ||
$({ target: 'Array', proto: true }, { | ||
@@ -12,0 +12,0 @@ at: function at(index) { |
@@ -7,3 +7,3 @@ 'use strict'; | ||
// `Array.prototype.findLastIndex` method | ||
// https://github.com/tc39/proposal-array-find-from-last | ||
// https://tc39.es/ecma262/#sec-array.prototype.findlastindex | ||
$({ target: 'Array', proto: true }, { | ||
@@ -10,0 +10,0 @@ findLastIndex: function findLastIndex(callbackfn /* , that = undefined */) { |
@@ -7,3 +7,3 @@ 'use strict'; | ||
// `Array.prototype.findLast` method | ||
// https://github.com/tc39/proposal-array-find-from-last | ||
// https://tc39.es/ecma262/#sec-array.prototype.findlast | ||
$({ target: 'Array', proto: true }, { | ||
@@ -10,0 +10,0 @@ findLast: function findLast(callbackfn /* , that = undefined */) { |
@@ -10,3 +10,3 @@ 'use strict'; | ||
// `Array.prototype.toReversed` method | ||
// https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.toReversed | ||
// https://tc39.es/ecma262/#sec-array.prototype.toreversed | ||
$({ target: 'Array', proto: true }, { | ||
@@ -13,0 +13,0 @@ toReversed: function toReversed() { |
@@ -14,3 +14,3 @@ 'use strict'; | ||
// `Array.prototype.toSorted` method | ||
// https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.toSorted | ||
// https://tc39.es/ecma262/#sec-array.prototype.tosorted | ||
$({ target: 'Array', proto: true }, { | ||
@@ -17,0 +17,0 @@ toSorted: function toSorted(compareFn) { |
@@ -15,3 +15,3 @@ 'use strict'; | ||
// `Array.prototype.toSpliced` method | ||
// https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.toSpliced | ||
// https://tc39.es/ecma262/#sec-array.prototype.tospliced | ||
$({ target: 'Array', proto: true }, { | ||
@@ -18,0 +18,0 @@ toSpliced: function toSpliced(start, deleteCount /* , ...items */) { |
@@ -9,3 +9,3 @@ 'use strict'; | ||
// `Array.prototype.with` method | ||
// https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.with | ||
// https://tc39.es/ecma262/#sec-array.prototype.with | ||
$({ target: 'Array', proto: true }, { | ||
@@ -12,0 +12,0 @@ 'with': function (index, value) { |
@@ -27,3 +27,2 @@ /* eslint-disable no-unused-vars -- required for functions `.length` */ | ||
// https://tc39.es/ecma262/#sec-nativeerror | ||
// https://github.com/tc39/proposal-error-cause | ||
exportGlobalErrorCauseWrapper('Error', function (init) { | ||
@@ -30,0 +29,0 @@ return function Error(message) { return apply(init, this, arguments); }; |
@@ -5,5 +5,5 @@ var $ = require('../internals/export'); | ||
// `Object.hasOwn` method | ||
// https://github.com/tc39/proposal-accessible-object-hasownproperty | ||
// https://tc39.es/ecma262/#sec-object.hasown | ||
$({ target: 'Object', stat: true }, { | ||
hasOwn: hasOwn | ||
}); |
@@ -17,3 +17,3 @@ 'use strict'; | ||
// `String.prototype.at` method | ||
// https://github.com/tc39/proposal-relative-indexing-method | ||
// https://tc39.es/ecma262/#sec-string.prototype.at | ||
$({ target: 'String', proto: true, forced: FORCED }, { | ||
@@ -20,0 +20,0 @@ at: function at(index) { |
@@ -145,3 +145,57 @@ var IS_PURE = require('../internals/is-pure'); | ||
var structuredCloneInternal = function (value, map) { | ||
var cloneBuffer = function (value, map, $type) { | ||
if (mapHas(map, value)) return mapGet(map, value); | ||
var type = $type || classof(value); | ||
var clone, length, options, source, target, i; | ||
if (type === 'SharedArrayBuffer') { | ||
if (nativeRestrictedStructuredClone) clone = nativeRestrictedStructuredClone(value); | ||
// SharedArrayBuffer should use shared memory, we can't polyfill it, so return the original | ||
else clone = value; | ||
} else { | ||
var DataView = global.DataView; | ||
// `ArrayBuffer#slice` is not available in IE10 | ||
// `ArrayBuffer#slice` and `DataView` are not available in old FF | ||
if (!DataView && typeof value.slice != 'function') throwUnpolyfillable('ArrayBuffer'); | ||
// detached buffers throws in `DataView` and `.slice` | ||
try { | ||
if (typeof value.slice == 'function' && !value.resizable) { | ||
clone = value.slice(0); | ||
} else { | ||
length = value.byteLength; | ||
options = 'maxByteLength' in value ? { maxByteLength: value.maxByteLength } : undefined; | ||
clone = new ArrayBuffer(length, options); | ||
source = new DataView(value); | ||
target = new DataView(clone); | ||
for (i = 0; i < length; i++) { | ||
target.setUint8(i, source.getUint8(i)); | ||
} | ||
} | ||
} catch (error) { | ||
throw new DOMException('ArrayBuffer is detached', DATA_CLONE_ERROR); | ||
} | ||
} | ||
mapSet(map, value, clone); | ||
return clone; | ||
}; | ||
var cloneView = function (value, type, offset, length, map) { | ||
var C = global[type]; | ||
// in some old engines like Safari 9, typeof C is 'object' | ||
// on Uint8ClampedArray or some other constructors | ||
if (!isObject(C)) throwUnpolyfillable(type); | ||
return new C(cloneBuffer(value.buffer, map), offset, length); | ||
}; | ||
var Placeholder = function (object, type, metadata) { | ||
this.object = object; | ||
this.type = type; | ||
this.metadata = metadata; | ||
}; | ||
var structuredCloneInternal = function (value, map, transferredBuffers) { | ||
if (isSymbol(value)) throwUncloneable('Symbol'); | ||
@@ -155,4 +209,3 @@ if (!isObject(value)) return value; | ||
var type = classof(value); | ||
var deep = false; | ||
var C, name, cloned, dataTransfer, i, length, keys, key, source, target, options; | ||
var C, name, cloned, dataTransfer, i, length, keys, key; | ||
@@ -162,15 +215,11 @@ switch (type) { | ||
cloned = Array(lengthOfArrayLike(value)); | ||
deep = true; | ||
break; | ||
case 'Object': | ||
cloned = {}; | ||
deep = true; | ||
break; | ||
case 'Map': | ||
cloned = new Map(); | ||
deep = true; | ||
break; | ||
case 'Set': | ||
cloned = new Set(); | ||
deep = true; | ||
break; | ||
@@ -218,8 +267,12 @@ case 'RegExp': | ||
} | ||
deep = true; | ||
break; | ||
case 'DOMException': | ||
cloned = new DOMException(value.message, value.name); | ||
deep = true; | ||
break; | ||
case 'ArrayBuffer': | ||
case 'SharedArrayBuffer': | ||
cloned = transferredBuffers | ||
? new Placeholder(value, type) | ||
: cloneBuffer(value, map, type); | ||
break; | ||
case 'DataView': | ||
@@ -233,2 +286,3 @@ case 'Int8Array': | ||
case 'Uint32Array': | ||
case 'Float16Array': | ||
case 'Float32Array': | ||
@@ -238,12 +292,6 @@ case 'Float64Array': | ||
case 'BigUint64Array': | ||
C = global[type]; | ||
// in some old engines like Safari 9, typeof C is 'object' | ||
// on Uint8ClampedArray or some other constructors | ||
if (!isObject(C)) throwUnpolyfillable(type); | ||
cloned = new C( | ||
// this is safe, since arraybuffer cannot have circular references | ||
structuredCloneInternal(value.buffer, map), | ||
value.byteOffset, | ||
type === 'DataView' ? value.byteLength : value.length | ||
); | ||
length = type === 'DataView' ? value.byteLength : value.length; | ||
cloned = transferredBuffers | ||
? new Placeholder(value, type, { offset: value.byteOffset, length: length }) | ||
: cloneView(value, type, value.byteOffset, length, map); | ||
break; | ||
@@ -253,6 +301,6 @@ case 'DOMQuad': | ||
cloned = new DOMQuad( | ||
structuredCloneInternal(value.p1, map), | ||
structuredCloneInternal(value.p2, map), | ||
structuredCloneInternal(value.p3, map), | ||
structuredCloneInternal(value.p4, map) | ||
structuredCloneInternal(value.p1, map, transferredBuffers), | ||
structuredCloneInternal(value.p2, map, transferredBuffers), | ||
structuredCloneInternal(value.p3, map, transferredBuffers), | ||
structuredCloneInternal(value.p4, map, transferredBuffers) | ||
); | ||
@@ -278,3 +326,3 @@ } catch (error) { | ||
for (i = 0, length = lengthOfArrayLike(value); i < length; i++) { | ||
dataTransfer.items.add(structuredCloneInternal(value[i], map)); | ||
dataTransfer.items.add(structuredCloneInternal(value[i], map, transferredBuffers)); | ||
} | ||
@@ -288,3 +336,3 @@ cloned = dataTransfer.files; | ||
cloned = new ImageData( | ||
structuredCloneInternal(value.data, map), | ||
structuredCloneInternal(value.data, map, transferredBuffers), | ||
value.width, | ||
@@ -317,28 +365,2 @@ value.height, | ||
break; | ||
case 'ArrayBuffer': | ||
C = global.DataView; | ||
// `ArrayBuffer#slice` is not available in IE10 | ||
// `ArrayBuffer#slice` and `DataView` are not available in old FF | ||
if (!C && typeof value.slice != 'function') throwUnpolyfillable(type); | ||
// detached buffers throws in `DataView` and `.slice` | ||
try { | ||
if (typeof value.slice == 'function' && !value.resizable) { | ||
cloned = value.slice(0); | ||
} else { | ||
length = value.byteLength; | ||
options = 'maxByteLength' in value ? { maxByteLength: value.maxByteLength } : undefined; | ||
cloned = new ArrayBuffer(length, options); | ||
source = new C(value); | ||
target = new C(cloned); | ||
for (i = 0; i < length; i++) { | ||
target.setUint8(i, source.getUint8(i)); | ||
} | ||
} | ||
} catch (error) { | ||
throw new DOMException('ArrayBuffer is detached', DATA_CLONE_ERROR); | ||
} break; | ||
case 'SharedArrayBuffer': | ||
// SharedArrayBuffer should use shared memory, we can't polyfill it, so return the original | ||
cloned = value; | ||
break; | ||
case 'Blob': | ||
@@ -407,3 +429,3 @@ try { | ||
if (deep) switch (type) { | ||
switch (type) { | ||
case 'Array': | ||
@@ -414,7 +436,7 @@ case 'Object': | ||
key = keys[i]; | ||
createProperty(cloned, key, structuredCloneInternal(value[key], map)); | ||
createProperty(cloned, key, structuredCloneInternal(value[key], map, transferredBuffers)); | ||
} break; | ||
case 'Map': | ||
value.forEach(function (v, k) { | ||
mapSet(cloned, structuredCloneInternal(k, map), structuredCloneInternal(v, map)); | ||
mapSet(cloned, structuredCloneInternal(k, map, transferredBuffers), structuredCloneInternal(v, map, transferredBuffers)); | ||
}); | ||
@@ -424,16 +446,16 @@ break; | ||
value.forEach(function (v) { | ||
setAdd(cloned, structuredCloneInternal(v, map)); | ||
setAdd(cloned, structuredCloneInternal(v, map, transferredBuffers)); | ||
}); | ||
break; | ||
case 'Error': | ||
createNonEnumerableProperty(cloned, 'message', structuredCloneInternal(value.message, map)); | ||
createNonEnumerableProperty(cloned, 'message', structuredCloneInternal(value.message, map, transferredBuffers)); | ||
if (hasOwn(value, 'cause')) { | ||
createNonEnumerableProperty(cloned, 'cause', structuredCloneInternal(value.cause, map)); | ||
createNonEnumerableProperty(cloned, 'cause', structuredCloneInternal(value.cause, map, transferredBuffers)); | ||
} | ||
if (name == 'AggregateError') { | ||
cloned.errors = structuredCloneInternal(value.errors, map); | ||
cloned.errors = structuredCloneInternal(value.errors, map, transferredBuffers); | ||
} // break omitted | ||
case 'DOMException': | ||
if (ERROR_STACK_INSTALLABLE) { | ||
createNonEnumerableProperty(cloned, 'stack', structuredCloneInternal(value.stack, map)); | ||
createNonEnumerableProperty(cloned, 'stack', structuredCloneInternal(value.stack, map, transferredBuffers)); | ||
} | ||
@@ -445,2 +467,72 @@ } | ||
var replacePlaceholders = function (value, map) { | ||
if (!isObject(value)) return value; | ||
if (mapHas(map, value)) return mapGet(map, value); | ||
var type, object, metadata, i, length, keys, key, replacement; | ||
if (value instanceof Placeholder) { | ||
type = value.type; | ||
object = value.object; | ||
switch (type) { | ||
case 'ArrayBuffer': | ||
case 'SharedArrayBuffer': | ||
replacement = cloneBuffer(object, map, type); | ||
break; | ||
case 'DataView': | ||
case 'Int8Array': | ||
case 'Uint8Array': | ||
case 'Uint8ClampedArray': | ||
case 'Int16Array': | ||
case 'Uint16Array': | ||
case 'Int32Array': | ||
case 'Uint32Array': | ||
case 'Float16Array': | ||
case 'Float32Array': | ||
case 'Float64Array': | ||
case 'BigInt64Array': | ||
case 'BigUint64Array': | ||
metadata = value.metadata; | ||
replacement = cloneView(object, type, metadata.offset, metadata.length, map); | ||
} | ||
} else switch (classof(value)) { | ||
case 'Array': | ||
case 'Object': | ||
keys = objectKeys(value); | ||
for (i = 0, length = lengthOfArrayLike(keys); i < length; i++) { | ||
key = keys[i]; | ||
value[key] = replacePlaceholders(value[key], map); | ||
} break; | ||
case 'Map': | ||
replacement = new Map(); | ||
value.forEach(function (v, k) { | ||
mapSet(replacement, replacePlaceholders(k, map), replacePlaceholders(v, map)); | ||
}); | ||
break; | ||
case 'Set': | ||
replacement = new Set(); | ||
value.forEach(function (v) { | ||
setAdd(replacement, replacePlaceholders(v, map)); | ||
}); | ||
break; | ||
case 'Error': | ||
value.message = replacePlaceholders(value.message, map); | ||
if (hasOwn(value, 'cause')) { | ||
value.cause = replacePlaceholders(value.cause, map); | ||
} | ||
if (value.name == 'AggregateError') { | ||
value.errors = replacePlaceholders(value.errors, map); | ||
} // break omitted | ||
case 'DOMException': | ||
if (ERROR_STACK_INSTALLABLE) { | ||
value.stack = replacePlaceholders(value.stack, map); | ||
} | ||
} | ||
mapSet(map, value, replacement || value); | ||
return replacement || value; | ||
}; | ||
var tryToTransfer = function (rawTransfer, map) { | ||
@@ -457,14 +549,20 @@ if (!isObject(rawTransfer)) throw TypeError('Transfer option cannot be converted to a sequence'); | ||
var length = lengthOfArrayLike(transfer); | ||
var value, type, C, transferredArray, transferred, canvas, context; | ||
var buffers = []; | ||
var value, type, C, transferred, canvas, context; | ||
if (PROPER_TRANSFER) { | ||
transferredArray = nativeStructuredClone(transfer, { transfer: transfer }); | ||
while (i < length) mapSet(map, transfer[i], transferredArray[i++]); | ||
} else while (i < length) { | ||
while (i < length) { | ||
value = transfer[i++]; | ||
if (mapHas(map, value)) throw new DOMException('Duplicate transferable', DATA_CLONE_ERROR); | ||
type = classof(value); | ||
switch (type) { | ||
if (type === 'ArrayBuffer') { | ||
push(buffers, value); | ||
continue; | ||
} | ||
if (mapHas(map, value)) throw new DOMException('Duplicate transferable', DATA_CLONE_ERROR); | ||
if (PROPER_TRANSFER) { | ||
transferred = nativeStructuredClone(value, { transfer: [value] }); | ||
} else switch (type) { | ||
case 'ImageBitmap': | ||
@@ -488,6 +586,2 @@ C = global.OffscreenCanvas; | ||
break; | ||
case 'ArrayBuffer': | ||
if (!isCallable(value.transfer)) throwUnpolyfillable(type, TRANSFERRING); | ||
transferred = value.transfer(); | ||
break; | ||
case 'MediaSourceHandle': | ||
@@ -503,6 +597,30 @@ case 'MessagePort': | ||
if (transferred === undefined) throw new DOMException('This object cannot be transferred: ' + type, DATA_CLONE_ERROR); | ||
mapSet(map, value, transferred); | ||
} | ||
return buffers; | ||
}; | ||
var tryToTransferBuffers = function (transfer, map) { | ||
var i = 0; | ||
var length = lengthOfArrayLike(transfer); | ||
var value, transferred; | ||
while (i < length) { | ||
value = transfer[i++]; | ||
if (mapHas(map, value)) throw new DOMException('Duplicate transferable', DATA_CLONE_ERROR); | ||
if (PROPER_TRANSFER) { | ||
transferred = nativeStructuredClone(value, { transfer: [value] }); | ||
} else { | ||
if (!isCallable(value.transfer)) throwUnpolyfillable('ArrayBuffer', TRANSFERRING); | ||
transferred = value.transfer(); | ||
} | ||
mapSet(map, value, transferred); | ||
} | ||
}; | ||
// `structuredClone` method | ||
@@ -514,11 +632,23 @@ // https://html.spec.whatwg.org/multipage/structured-data.html#dom-structuredclone | ||
var transfer = options ? options.transfer : undefined; | ||
var map; | ||
var transferredBuffers = false; | ||
var map, buffers; | ||
if (transfer !== undefined) { | ||
map = new Map(); | ||
tryToTransfer(transfer, map); | ||
buffers = tryToTransfer(transfer, map); | ||
transferredBuffers = !!lengthOfArrayLike(buffers); | ||
} | ||
return structuredCloneInternal(value, map); | ||
var clone = structuredCloneInternal(value, map, transferredBuffers); | ||
// since of an issue with cloning views of transferred buffers, we a forced to transfer / clone them in 2 steps | ||
// https://github.com/zloirock/core-js/issues/1265 | ||
if (transferredBuffers) { | ||
map = new Map(); | ||
tryToTransferBuffers(transfer, map); | ||
clone = replacePlaceholders(clone, map); | ||
} | ||
return clone; | ||
} | ||
}); |
{ | ||
"name": "core-js-pure", | ||
"version": "3.31.0", | ||
"version": "3.31.1", | ||
"description": "Standard library", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
1008978
23622
2