-
Notifications
You must be signed in to change notification settings - Fork 550
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
web: mark as uncloneable when possible (#3709)
* web: mark as uncloneable when possible This tells node that the marked instances from undici are not cloneable, so that attempts to cloning those throw `DataCloneError`. * test: add test cases for platform objects uncloneable * fix: move to webidl * fix: move it under webidl * fixup: rename it to markAsUncloneable * fix: mark more web instances uncloneable * fixup --------- Co-authored-by: Khafra <[email protected]> (cherry picked from commit 1ab2382)
- Loading branch information
Showing
12 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict' | ||
|
||
const { tspl } = require('@matteo.collina/tspl') | ||
const { test } = require('node:test') | ||
const { markAsUncloneable } = require('node:worker_threads') | ||
const { Response, Request, FormData, Headers, ErrorEvent, MessageEvent, CloseEvent, EventSource, WebSocket } = require('..') | ||
const { CacheStorage } = require('../lib/web/cache/cachestorage') | ||
const { Cache } = require('../lib/web/cache/cache') | ||
const { kConstruct } = require('../lib/core/symbols') | ||
|
||
test('unserializable web instances should be uncloneable if node exposes the api', (t) => { | ||
if (markAsUncloneable !== undefined) { | ||
t = tspl(t, { plan: 11 }) | ||
const uncloneables = [ | ||
{ Uncloneable: Response, brand: 'Response' }, | ||
{ Uncloneable: Request, value: 'http://localhost', brand: 'Request' }, | ||
{ Uncloneable: FormData, brand: 'FormData' }, | ||
{ Uncloneable: MessageEvent, value: 'dummy event', brand: 'MessageEvent' }, | ||
{ Uncloneable: CloseEvent, value: 'dummy event', brand: 'CloseEvent' }, | ||
{ Uncloneable: ErrorEvent, value: 'dummy event', brand: 'ErrorEvent' }, | ||
{ Uncloneable: EventSource, value: 'http://localhost', brand: 'EventSource' }, | ||
{ Uncloneable: Headers, brand: 'Headers' }, | ||
{ Uncloneable: WebSocket, value: 'http://localhost', brand: 'WebSocket' }, | ||
{ Uncloneable: Cache, value: kConstruct, brand: 'Cache' }, | ||
{ Uncloneable: CacheStorage, value: kConstruct, brand: 'CacheStorage' } | ||
] | ||
uncloneables.forEach((platformEntity) => { | ||
t.throws(() => structuredClone(new platformEntity.Uncloneable(platformEntity.value)), | ||
DOMException, | ||
`Cloning ${platformEntity.brand} should throw DOMException`) | ||
}) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters