From 7123e4dbb56b971cc0dfffa89649f0606cb220ad Mon Sep 17 00:00:00 2001 From: Yuriy Khomenko Date: Thu, 1 Oct 2020 21:18:58 +0300 Subject: [PATCH] fixed DataView clone algorithm + added new benchmark test --- src/qclone.js | 2 +- src/qcloneCircular.js | 2 +- src/qcloneStrict.js | 4 ++-- src/qcloneStrictCircular.js | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/qclone.js b/src/qclone.js index 1a84ad6..bad3642 100644 --- a/src/qclone.js +++ b/src/qclone.js @@ -71,7 +71,7 @@ function qclone(o){ // case BigInt: // return Object(o.valueOf()); case DataView: - return new DataView(o.buffer, o.byteLength, o.byteOffset) + return new DataView(new Uint8Array(new Uint8Array(o.buffer)).buffer, o.byteOffset, o.byteLength); case ArrayBuffer: //case SharedArrayBuffer: return new Uint8Array(new Uint8Array(o)).buffer; diff --git a/src/qcloneCircular.js b/src/qcloneCircular.js index 2ad25e0..b41f21e 100644 --- a/src/qcloneCircular.js +++ b/src/qcloneCircular.js @@ -96,7 +96,7 @@ function qcloneCircular(o){ // case BigInt: // return Object(o.valueOf()); case DataView: - return new DataView(o.buffer, o.byteLength, o.byteOffset); + return new DataView(new Uint8Array(new Uint8Array(o.buffer)).buffer, o.byteOffset, o.byteLength); case ArrayBuffer: //case SharedArrayBuffer: return new Uint8Array(new Uint8Array(o)).buffer; diff --git a/src/qcloneStrict.js b/src/qcloneStrict.js index cd360d3..a362798 100644 --- a/src/qcloneStrict.js +++ b/src/qcloneStrict.js @@ -16,7 +16,7 @@ function qcloneStrict(o){ if (typeof o !== 'object' || o === null)return o; switch(o.constructor){ case Object: - case undefined: + case undefined: let c = (o.constructor) ? __cr__(__gpo__(o)) : __cr__(null); let keys = [...__gopn__(o), ...__gops__(o)], length = keys.length; for(let i = 0; i < length; i++){ @@ -78,7 +78,7 @@ function qcloneStrict(o){ // case BigInt: // return Object(o.valueOf()); case DataView: - return new DataView(o.buffer, o.byteLength, o.byteOffset); + return new DataView(new Uint8Array(new Uint8Array(o.buffer)).buffer, o.byteOffset, o.byteLength); case ArrayBuffer: //case SharedArrayBuffer: return new Uint8Array(new Uint8Array(o)).buffer; diff --git a/src/qcloneStrictCircular.js b/src/qcloneStrictCircular.js index 3d371f3..0f9bd45 100644 --- a/src/qcloneStrictCircular.js +++ b/src/qcloneStrictCircular.js @@ -86,7 +86,7 @@ function qcloneStrictCircular(o){ // case BigInt: // return Object(o.valueOf()); case DataView: - return new DataView(o.buffer, o.byteLength, o.byteOffset); + return new DataView(new Uint8Array(new Uint8Array(o.buffer)).buffer, o.byteOffset, o.byteLength); case ArrayBuffer: //case SharedArrayBuffer: return new Uint8Array(new Uint8Array(o)).buffer;