Skip to content

Commit e2e3fd2

Browse files
jazellyKhafraDev
andauthored
web: mark as uncloneable when possible (#3709) (#3744)
* 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)
1 parent 5344aa5 commit e2e3fd2

File tree

12 files changed

+58
-0
lines changed

12 files changed

+58
-0
lines changed

lib/web/cache/cache.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class Cache {
3737
webidl.illegalConstructor()
3838
}
3939

40+
webidl.util.markAsUncloneable(this)
4041
this.#relevantRequestResponseList = arguments[1]
4142
}
4243

lib/web/cache/cachestorage.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class CacheStorage {
1616
if (arguments[0] !== kConstruct) {
1717
webidl.illegalConstructor()
1818
}
19+
20+
webidl.util.markAsUncloneable(this)
1921
}
2022

2123
async match (request, options = {}) {

lib/web/eventsource/eventsource.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ class EventSource extends EventTarget {
105105
// 1. Let ev be a new EventSource object.
106106
super()
107107

108+
webidl.util.markAsUncloneable(this)
109+
108110
const prefix = 'EventSource constructor'
109111
webidl.argumentLengthCheck(arguments, 1, prefix)
110112

lib/web/fetch/formdata.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const File = globalThis.File ?? NativeFile
1414
// https://xhr.spec.whatwg.org/#formdata
1515
class FormData {
1616
constructor (form) {
17+
webidl.util.markAsUncloneable(this)
18+
1719
if (form !== undefined) {
1820
throw webidl.errors.conversionFailed({
1921
prefix: 'FormData constructor',

lib/web/fetch/headers.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,8 @@ class Headers {
359359
#headersList
360360

361361
constructor (init = undefined) {
362+
webidl.util.markAsUncloneable(this)
363+
362364
if (init === kConstruct) {
363365
return
364366
}

lib/web/fetch/request.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ let patchMethodWarning = false
8282
class Request {
8383
// https://fetch.spec.whatwg.org/#dom-request
8484
constructor (input, init = {}) {
85+
webidl.util.markAsUncloneable(this)
8586
if (input === kConstruct) {
8687
return
8788
}

lib/web/fetch/response.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class Response {
110110

111111
// https://fetch.spec.whatwg.org/#dom-response
112112
constructor (body = null, init = {}) {
113+
webidl.util.markAsUncloneable(this)
113114
if (body === kConstruct) {
114115
return
115116
}

lib/web/fetch/webidl.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
const { types, inspect } = require('node:util')
4+
const { markAsUncloneable } = require('node:worker_threads')
45
const { toUSVString } = require('../../core/util')
56

67
/** @type {import('../../../types/webidl').Webidl} */
@@ -86,6 +87,7 @@ webidl.util.Type = function (V) {
8687
}
8788
}
8889

90+
webidl.util.markAsUncloneable = markAsUncloneable || (() => {})
8991
// https://webidl.spec.whatwg.org/#abstract-opdef-converttoint
9092
webidl.util.ConvertToInt = function (V, bitLength, signedness, opts) {
9193
let upperBound

lib/web/websocket/events.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class MessageEvent extends Event {
1414
constructor (type, eventInitDict = {}) {
1515
if (type === kConstruct) {
1616
super(arguments[1], arguments[2])
17+
webidl.util.markAsUncloneable(this)
1718
return
1819
}
1920

@@ -26,6 +27,7 @@ class MessageEvent extends Event {
2627
super(type, eventInitDict)
2728

2829
this.#eventInit = eventInitDict
30+
webidl.util.markAsUncloneable(this)
2931
}
3032

3133
get data () {
@@ -112,6 +114,7 @@ class CloseEvent extends Event {
112114
super(type, eventInitDict)
113115

114116
this.#eventInit = eventInitDict
117+
webidl.util.markAsUncloneable(this)
115118
}
116119

117120
get wasClean () {
@@ -142,6 +145,7 @@ class ErrorEvent extends Event {
142145
webidl.argumentLengthCheck(arguments, 1, prefix)
143146

144147
super(type, eventInitDict)
148+
webidl.util.markAsUncloneable(this)
145149

146150
type = webidl.converters.DOMString(type, prefix, 'type')
147151
eventInitDict = webidl.converters.ErrorEventInit(eventInitDict ?? {})

lib/web/websocket/websocket.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class WebSocket extends EventTarget {
5151
constructor (url, protocols = []) {
5252
super()
5353

54+
webidl.util.markAsUncloneable(this)
55+
5456
const prefix = 'WebSocket constructor'
5557
webidl.argumentLengthCheck(arguments, 1, prefix)
5658

0 commit comments

Comments
 (0)