fix(cloneDeep): Ensure DataView's offset and length are cloned correctly (#612)

This commit is contained in:
Dongho Kim 2024-09-28 21:38:49 +09:00 committed by GitHub
parent 791c27da93
commit e88e3e2d76
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 3 deletions

View File

@ -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);

View File

@ -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);