Skip to content

Commit adf9681

Browse files
committed
allow cloning resizable ArrayBuffers in the structuredClone polyfill
1 parent 1fc7ae4 commit adf9681

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## Changelog
22
##### Unreleased
3+
- Allowed cloning resizable `ArrayBuffer`s in the `structuredClone` polyfill
34
- Fixed wrong export in `/(stable|actual|full)/instance/unshift` entries, [#1207](https://github.com/zloirock/core-js/issues/1207)
45

56
##### [3.28.0 - 2023.02.14](https://github.com/zloirock/core-js/releases/tag/v3.28.0)

packages/core-js/modules/web.structured-clone.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ var structuredCloneInternal = function (value, map) {
147147

148148
var type = classof(value);
149149
var deep = false;
150-
var C, name, cloned, dataTransfer, i, length, keys, key, source, target;
150+
var C, name, cloned, dataTransfer, i, length, keys, key, source, target, options;
151151

152152
switch (type) {
153153
case 'Array':
@@ -302,11 +302,12 @@ var structuredCloneInternal = function (value, map) {
302302
if (!C && typeof value.slice != 'function') throwUnpolyfillable(type);
303303
// detached buffers throws in `DataView` and `.slice`
304304
try {
305-
if (typeof value.slice == 'function') {
305+
if (typeof value.slice == 'function' && !value.resizable) {
306306
cloned = value.slice(0);
307307
} else {
308308
length = value.byteLength;
309-
cloned = new ArrayBuffer(length);
309+
options = 'maxByteLength' in value ? { maxByteLength: value.maxByteLength } : undefined;
310+
cloned = new ArrayBuffer(length, options);
310311
source = new C(value);
311312
target = new C(cloned);
312313
for (i = 0; i < length; i++) {

0 commit comments

Comments
 (0)