mirror of
https://github.com/toss/es-toolkit.git
synced 2024-11-24 11:45:26 +03:00
fix(cloneDeep): Ensure DataView's offset and length are cloned correctly (#612)
This commit is contained in:
parent
791c27da93
commit
e88e3e2d76
@ -329,8 +329,8 @@ describe('cloneDeep', () => {
|
||||
});
|
||||
|
||||
it('should clone DataViews', () => {
|
||||
const buffer = new Uint8Array([1, 2]).buffer;
|
||||
const view = new DataView(buffer);
|
||||
const buffer = new Uint8Array([0, 1, 2]).buffer;
|
||||
const view = new DataView(buffer, 1, 2);
|
||||
|
||||
const cloned = cloneDeep(view);
|
||||
|
||||
|
@ -141,7 +141,7 @@ function cloneDeepImpl<T>(obj: T, stack = new Map<any, any>()): T {
|
||||
}
|
||||
|
||||
if (obj instanceof DataView) {
|
||||
const result = new DataView(obj.buffer.slice(0));
|
||||
const result = new DataView(obj.buffer.slice(0), obj.byteOffset, obj.byteLength);
|
||||
stack.set(obj, result);
|
||||
|
||||
copyProperties(result, obj, stack);
|
||||
|
Loading…
Reference in New Issue
Block a user