-
Notifications
You must be signed in to change notification settings - Fork 532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
web: mark as uncloneable when possible #3709
base: main
Are you sure you want to change the base?
Conversation
This tells node that the marked instances from undici are not cloneable, so that attempts to cloning those throw `DataCloneError`.
I am hesitant to write a test here, as it would be like testing the behaviour of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
I really think having a test would be useful, add it. |
Why is Headers unclonable? |
AFAIK, any cloneable that wants to be cloned in node runtime needs to
One example you can find in node is https:/nodejs/node/blob/00b2f07f9ddeb8ffd2fb2108b0ed9ffa81ea000d/lib/internal/webstreams/transfer.js#L49 I don't think the above are exposed, so undici classes are not cloneable in node from that sense. |
I didn't mean to close this. Sorry. |
How can we access those symbols from userland? |
@ronag it's because webidl platform objects cannot be cloned:
Notice that the webidl for Headers does not include serializable: [[Exposed](https://webidl.spec.whatwg.org/#Exposed)=(Window,Worker)]
interface Headers {
...
} |
I should've mentioned, this is more to tell Node to treat undici instances as a platform object, as this api will attach a private attribute that Node can recognize. Without it, Node will try to find the
I think whether/how we make some classes cloneable in undici should be a separate and broader discussion, since it might involve whether/how Node exposes its internal symbols. |
I also added the test. It works fine on my local but won't be effective on current CI, as the API hasn't been released. The API is on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why "maybeMarkAsUncloneable"? If in the future all supported platforms have markAsUncloneable, then do we need to rename this function and all the places where it is called?
More likely that we forget that in 3 years.
Good point. I updated the naming. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RSLGTM
btw. cloneable or clonable, is the spelling right?
Yeah, it's correct. In node it's always |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this also need to be done for EventSource, WebSocket, WebsocketStream, CloseEvent, ErrorEvent, MessageEvent, Cache, CacheStorage, and possibly others?
Rationale
This tells node that the marked instances from undici are not cloneable, so that attempts to cloning those throw
DataCloneError
.This is a follow-up work from nodejs/node#55234
Changes
Marked the following as uncloneable.
Features
Bug Fixes
Breaking Changes and Deprecations
Status