structuredClone() rejects DataView objects with TypeError
Describe the bug
Calling structuredClone() on a DataView instance currently throws TypeError: Data views are not supported yet. instead of returning a cloned DataView.
To Reproduce
const buffer = new ArrayBuffer(16);
const view = new DataView(buffer, 4, 8);
view.setInt32(0, 42);
const copy = structuredClone(view);This currently throws:
TypeError: Data views are not supported yet.Expected behavior
According to the WHATWG HTML Structured Clone algorithm, DataView objects are supported by the structured clone mechanism.
structuredClone(view) should return a new DataView that:
- Preserves the original
byteOffsetandbyteLength. - Contains a clone of the underlying
ArrayBuffer. - Does not share the underlying buffer with the original
DataView.
For example, modifying the original buffer after cloning should not modify the cloned DataView.
Build environment
- OS: Windows 11
- Target triple: x86_64-pc-windows-msvc
- Rustc version: rustc 1.96.0
Additional context
In core/wintertc/src/store/from.rs, DataView objects are currently rejected with:
} else if let Ok(_dataview) = JsDataView::from_object(object.clone()) {
return Err(js_error!(TypeError: "Data views are not supported yet."));
}The deserialization logic for DataView is already present in core/wintertc/src/store/to.rs, and ValueStoreInner::DataView already exists in core/wintertc/src/store/mod.rs.
This appears to leave the serialization side in store/from.rs as the missing part of the implementation.
Source: boa-dev/boa