Skip to content

Commit

Permalink
fixed DataView clone algorithm + added new benchmark test
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuriy-Khomenko committed Oct 1, 2020
1 parent 01a9325 commit 7123e4d
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/qclone.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/qcloneCircular.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/qcloneStrict.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++){
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/qcloneStrictCircular.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7123e4d

Please sign in to comment.