Skip to content

structuredClone() rejects DataView objects with TypeError #5530

Description

@MayankSharma-2812

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 byteOffset and byteLength.
  • 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions