mdn / content

The content behind MDN Web Docs
https://developer.mozilla.org
Other
9.13k stars 22.45k forks source link

Improve `messageerror` example to show a case in which the event is fired #35064

Open nicolo-ribaudo opened 1 month ago

nicolo-ribaudo commented 1 month ago

MDN URL

https://developer.mozilla.org/en-US/docs/Web/API/Worker/messageerror_event

What specific section or headline is this issue about?

Example

What information was incorrect, unhelpful, or incomplete?

I was trying to figure out what code can cause a messageerror event, and after failing to figure it out by myself I decided to go read on MDN.

Unfortunately MDN is very vague: it says that the error is fired when something cannot be deserialized, but it does not actually say in which case something can fail being deserialized.

What did you expect to see?

The example should have to different threads:

Do you have any supporting links, references, or citations?

No response

Do you have anything more you want to share?

No response

Josh-Cena commented 1 month ago

I saw the following cases where deserialization can fail (but serialization completed nonetheless):

  • (For any data type) If the interface identified by interfaceName is not exposed in targetRealm, then throw a "DataCloneError" DOMException.

  • (For SharedArrayBuffer) If targetRealm's corresponding agent cluster is not serialized.[[AgentCluster]], then throw a "DataCloneError" DOMException.

  • And of course, if any deserialization steps for objects defined in other specs threw an exception.

I'm not sure if there exists a good example that developers would actually care about: for example I don't know what brings two workers into the same agent cluster and whether you can even transfer stuff between non-same-cluster agents at all. But it seems like the non-exposed case is interesting enough?