Skip to content

Commit

Permalink
remove unspecified unnecessary ArrayBuffer and DataView dependenc…
Browse files Browse the repository at this point in the history
…ies of `structuredClone`
  • Loading branch information
zloirock committed Oct 24, 2023
1 parent 0dfc8b6 commit 65e9213
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Changelog
##### Unreleased
- Removed unspecified unnecessary `ArrayBuffer` and `DataView` dependencies of `structuredClone` lack of which could cause errors in some entries in IE10-
- Compat data improvements:
- Updated Opera Android 78 compat data mapping

Expand Down
23 changes: 13 additions & 10 deletions packages/core-js/modules/web.structured-clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var validateArgumentsLength = require('../internals/validate-arguments-length');
var getRegExpFlags = require('../internals/regexp-get-flags');
var MapHelpers = require('../internals/map-helpers');
var SetHelpers = require('../internals/set-helpers');
var arrayBufferTransfer = require('../internals/array-buffer-transfer');
var detachTransferable = require('../internals/detach-transferable');
var ERROR_STACK_INSTALLABLE = require('../internals/error-stack-installable');
var PROPER_STRUCTURED_CLONE_TRANSFER = require('../internals/structured-clone-proper-transfer');

Expand Down Expand Up @@ -63,7 +63,7 @@ var checkBasicSemantic = function (structuredCloneImplementation) {
var set1 = new global.Set([7]);
var set2 = structuredCloneImplementation(set1);
var number = structuredCloneImplementation(Object(7));
return set2 === set1 || !set2.has(7) || typeof number != 'object' || +number !== 7;
return set2 === set1 || !set2.has(7) || !isObject(number) || +number !== 7;
}) && structuredCloneImplementation;
};

Expand Down Expand Up @@ -145,7 +145,7 @@ var createDataTransfer = function () {
};

var cloneBuffer = function (value, map, $type) {
if (mapHas(map, value)) return mapGet(map, value);
if (map && mapHas(map, value)) return mapGet(map, value);

var type = $type || classof(value);
var clone, length, options, source, target, i;
Expand All @@ -159,10 +159,10 @@ var cloneBuffer = function (value, map, $type) {

// `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');
if (!DataView && !isCallable(value.slice)) throwUnpolyfillable('ArrayBuffer');
// detached buffers throws in `DataView` and `.slice`
try {
if (typeof value.slice == 'function' && !value.resizable) {
if (isCallable(value.slice) && !value.resizable) {
clone = value.slice(0);
} else {
length = value.byteLength;
Expand All @@ -179,7 +179,7 @@ var cloneBuffer = function (value, map, $type) {
}
}

mapSet(map, value, clone);
if (map) mapSet(map, value, clone);

return clone;
};
Expand Down Expand Up @@ -597,11 +597,14 @@ var tryToTransferBuffers = function (transfer, map) {

if (mapHas(map, value)) throw new DOMException('Duplicate transferable', DATA_CLONE_ERROR);

if (arrayBufferTransfer) {
transferred = arrayBufferTransfer(value, undefined, true);
} else {
if (!isCallable(value.transfer)) throwUnpolyfillable('ArrayBuffer', TRANSFERRING);
if (PROPER_STRUCTURED_CLONE_TRANSFER) {
transferred = nativeRestrictedStructuredClone(value, { transfer: [value] });
} else if (isCallable(value.transfer)) {
transferred = value.transfer();
} else {
if (!detachTransferable) throwUnpolyfillable('ArrayBuffer', TRANSFERRING);
transferred = cloneBuffer(value);
detachTransferable(value);
}

mapSet(map, value, transferred);
Expand Down

0 comments on commit 65e9213

Please sign in to comment.