Skip to content

structuredClone parity questions #159

@syntacion

Description

@syntacion

While looking through Web Platform Tests's test suite for structured clones, I noticed a few more differences between msgpackr's implementation and the specs:

  1. -0: -0 is separate from 0. We can easily add a check, but maybe we also don't want to unnecessarily bloat it to 5 bytes?
  2. __proto__ keys: msgpackr silently replaces them with __proto_, presumably to avoid prototype pollution. I wonder if it might be better to use Object.defineProperty to set it instead? JSON.stringify and JSON.parse is able to handle these keys without issues, so I think msgpackr should try to do the same.
  3. sparse array: Currently entirely unsupported by msgpackr.
  4. sliced TypedArrays: If multiple TypedArrays reference the same buffer, the buffer is only used once. More strangely, structuredClone(new Uint8Array(1000000).subarray(0, 100)).buffer.byteLength === 1000000.

Do you think it makes sense to try to match structuredClone in each of these areas? Maybe put them behind an option?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions