Open Bug 1904148 Opened 3 months ago Updated 1 month ago

Support RawJSONObject in structuredClone

Categories

(Core :: JavaScript Engine, task, P3)

task

Tracking

()

People

(Reporter: bthrall, Unassigned)

References

(Blocks 1 open bug)

Details

Currently, trying to structuredClone a RawJSONObject results in 'DataCloneError: RawJSON object could not be cloned'.

This is correct, as I read the structuredClone spec.

Should we fix this? As far as I know, there's no technical reason we couldn't clone a RawJSONObject.

(In reply to Bryan Thrall [:bthrall] from comment #0)

Currently, trying to structuredClone a RawJSONObject results in 'DataCloneError: RawJSON object could not be cloned'.

This is correct, as I read the structuredClone spec.

Yes, as I read the spec: these are not platform objects (they aren't defined in WebIDL, they don't implement an interface), which means cloneability defers to the StructuredSerialize operation. With a literal reading of the spec, step 22 of https://html.spec.whatwg.org/multipage/structured-data.html#structuredserializeinternal will fail because of the existence of an [[IsRawJSON]] internal slot.

(But with a literal reading, step 22 will fail for... well, everything: the JS spec says "All objects have an internal slot named [[PrivateElements]],...". Oops! I think this is mostly just an artifact of structured clone straddling between whatwg and tc39.)

Should we fix this? As far as I know, there's no technical reason we couldn't clone a RawJSONObject.

We should probably file an issue with the proposal. I may as well just do that. Though we could probably go ahead and implement in parallel; I at least don't see any particular reason to exclude it.

Oh, wait. I don't think I know how to file an issue, because the change would currently need to go into the whatwg spec.

Ok, filed https://github.com/whatwg/html/issues/10424

I don't know anything about their process.

Filed https://github.com/whatwg/html/issues/10425 for the general issue of the specs not quite lining up, though I don't think anything can really be done about that without moving structured cloning into the JS spec. Which may happen. And will probably create mismatches at the new boundary.

Based on the response to https://github.com/whatwg/html/issues/10425 (they added mention of [[PrivateElements]] to the spec), it seems like we are waiting on them to take action on https://github.com/whatwg/html/issues/10424.

We don't have to support structuredClone for RawJSONObject to release the JSON.parse with source feature, so we could just wait.

You need to log in before you can comment on or make changes to this bug.