Skip to content

Commit 1ab2382

Browse files
jazellyKhafraDev
andauthored
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]>
1 parent ba085df commit 1ab2382

File tree

12 files changed

+61
-0
lines changed

12 files changed

+61
-0
lines changed

lib/web/cache/cache.js

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

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

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
@@ -109,6 +109,8 @@ class EventSource extends EventTarget {
109109
// 1. Let ev be a new EventSource object.
110110
super()
111111

112+
webidl.util.markAsUncloneable(this)
113+
112114
const prefix = 'EventSource constructor'
113115
webidl.argumentLengthCheck(arguments, 1, prefix)
114116

lib/web/fetch/formdata.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class FormData {
1414
#state = []
1515

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
@@ -436,6 +436,8 @@ class Headers {
436436
* @returns
437437
*/
438438
constructor (init = undefined) {
439+
webidl.util.markAsUncloneable(this)
440+
439441
if (init === kConstruct) {
440442
return
441443
}

lib/web/fetch/request.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ class Request {
9292

9393
// https://fetch.spec.whatwg.org/#dom-request
9494
constructor (input, init = undefined) {
95+
webidl.util.markAsUncloneable(this)
96+
9597
if (input === kConstruct) {
9698
return
9799
}

lib/web/fetch/response.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ class Response {
112112

113113
// https://fetch.spec.whatwg.org/#dom-response
114114
constructor (body = null, init = undefined) {
115+
webidl.util.markAsUncloneable(this)
116+
115117
if (body === kConstruct) {
116118
return
117119
}

lib/web/fetch/webidl.js

Lines changed: 3 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
const UNDEFINED = 1
@@ -131,6 +132,8 @@ webidl.util.TypeValueToString = function (o) {
131132
}
132133
}
133134

135+
webidl.util.markAsUncloneable = markAsUncloneable || (() => {})
136+
134137
// https://webidl.spec.whatwg.org/#abstract-opdef-converttoint
135138
webidl.util.ConvertToInt = function (V, bitLength, signedness, opts) {
136139
let upperBound

lib/web/websocket/events.js

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

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

2728
this.#eventInit = eventInitDict
29+
webidl.util.markAsUncloneable(this)
2830
}
2931

3032
get data () {
@@ -111,6 +113,7 @@ class CloseEvent extends Event {
111113
super(type, eventInitDict)
112114

113115
this.#eventInit = eventInitDict
116+
webidl.util.markAsUncloneable(this)
114117
}
115118

116119
get wasClean () {
@@ -141,6 +144,7 @@ class ErrorEvent extends Event {
141144
webidl.argumentLengthCheck(arguments, 1, prefix)
142145

143146
super(type, eventInitDict)
147+
webidl.util.markAsUncloneable(this)
144148

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

lib/web/websocket/websocket.js

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

103+
webidl.util.markAsUncloneable(this)
104+
103105
const prefix = 'WebSocket constructor'
104106
webidl.argumentLengthCheck(arguments, 1, prefix)
105107

0 commit comments

Comments
 (0)