Skip to content

Commit

Permalink
allow cloning resizable ArrayBuffers in the structuredClone polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Feb 21, 2023
1 parent 1fc7ae4 commit adf9681
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 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
- Allowed cloning resizable `ArrayBuffer`s in the `structuredClone` polyfill
- Fixed wrong export in `/(stable|actual|full)/instance/unshift` entries, [#1207](https://github.com/zloirock/core-js/issues/1207)

##### [3.28.0 - 2023.02.14](https://github.com/zloirock/core-js/releases/tag/v3.28.0)
Expand Down
7 changes: 4 additions & 3 deletions packages/core-js/modules/web.structured-clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ var structuredCloneInternal = function (value, map) {

var type = classof(value);
var deep = false;
var C, name, cloned, dataTransfer, i, length, keys, key, source, target;
var C, name, cloned, dataTransfer, i, length, keys, key, source, target, options;

switch (type) {
case 'Array':
Expand Down Expand Up @@ -302,11 +302,12 @@ var structuredCloneInternal = function (value, map) {
if (!C && typeof value.slice != 'function') throwUnpolyfillable(type);
// detached buffers throws in `DataView` and `.slice`
try {
if (typeof value.slice == 'function') {
if (typeof value.slice == 'function' && !value.resizable) {
cloned = value.slice(0);
} else {
length = value.byteLength;
cloned = new ArrayBuffer(length);
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++) {
Expand Down

0 comments on commit adf9681

Please sign in to comment.