Skip to content

Commit

Permalink
fix: move it under webidl
Browse files Browse the repository at this point in the history
  • Loading branch information
jazelly committed Oct 10, 2024
1 parent 110dab1 commit ad9f128
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 24 deletions.
4 changes: 2 additions & 2 deletions lib/web/eventsource/eventsource.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const { pipeline } = require('node:stream')
const { fetching } = require('../fetch')
const { makeRequest } = require('../fetch/request')
const { webidl, maybeMarkAsUncloneable } = require('../fetch/webidl')
const { webidl } = require('../fetch/webidl')
const { EventSourceStream } = require('./eventsource-stream')
const { parseMIMEType } = require('../fetch/data-url')
const { createFastMessageEvent } = require('../websocket/events')
Expand Down Expand Up @@ -109,7 +109,7 @@ class EventSource extends EventTarget {
// 1. Let ev be a new EventSource object.
super()

maybeMarkAsUncloneable(this)
webidl.util.maybeMarkAsUncloneable(this)

const prefix = 'EventSource constructor'
webidl.argumentLengthCheck(arguments, 1, prefix)
Expand Down
4 changes: 2 additions & 2 deletions lib/web/fetch/formdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const { iteratorMixin } = require('./util')
const { kEnumerableProperty } = require('../../core/util')
const { webidl, maybeMarkAsUncloneable } = require('./webidl')
const { webidl } = require('./webidl')
const { File: NativeFile } = require('node:buffer')
const nodeUtil = require('node:util')

Expand All @@ -14,7 +14,7 @@ class FormData {
#state = []

constructor (form) {
maybeMarkAsUncloneable(this)
webidl.util.maybeMarkAsUncloneable(this)

if (form !== undefined) {
throw webidl.errors.conversionFailed({
Expand Down
4 changes: 2 additions & 2 deletions lib/web/fetch/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const {
isValidHeaderName,
isValidHeaderValue
} = require('./util')
const { webidl, maybeMarkAsUncloneable } = require('./webidl')
const { webidl } = require('./webidl')
const assert = require('node:assert')
const util = require('node:util')

Expand Down Expand Up @@ -420,7 +420,7 @@ class Headers {
#headersList

constructor (init = undefined) {
maybeMarkAsUncloneable(this)
webidl.util.maybeMarkAsUncloneable(this)

if (init === kConstruct) {
return
Expand Down
4 changes: 2 additions & 2 deletions lib/web/fetch/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const {
requestDuplex
} = require('./constants')
const { kEnumerableProperty, normalizedMethodRecordsBase, normalizedMethodRecords } = util
const { webidl, maybeMarkAsUncloneable } = require('./webidl')
const { webidl } = require('./webidl')
const { URLSerializer } = require('./data-url')
const { kConstruct } = require('../../core/symbols')
const assert = require('node:assert')
Expand Down Expand Up @@ -92,7 +92,7 @@ class Request {

// https://fetch.spec.whatwg.org/#dom-request
constructor (input, init = undefined) {
maybeMarkAsUncloneable(this)
webidl.util.maybeMarkAsUncloneable(this)

if (input === kConstruct) {
return
Expand Down
4 changes: 2 additions & 2 deletions lib/web/fetch/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const {
redirectStatusSet,
nullBodyStatus
} = require('./constants')
const { webidl, maybeMarkAsUncloneable } = require('./webidl')
const { webidl } = require('./webidl')
const { FormData } = require('./formdata')
const { URLSerializer } = require('./data-url')
const { kConstruct } = require('../../core/symbols')
Expand Down Expand Up @@ -113,7 +113,7 @@ class Response {

// https://fetch.spec.whatwg.org/#dom-response
constructor (body = null, init = undefined) {
maybeMarkAsUncloneable(this)
webidl.util.maybeMarkAsUncloneable(this)

if (body === kConstruct) {
return
Expand Down
15 changes: 7 additions & 8 deletions lib/web/fetch/webidl.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ webidl.util.TypeValueToString = function (o) {
}
}

webidl.util.maybeMarkAsUncloneable = function (target) {
if (markAsUncloneable !== undefined) {
markAsUncloneable(target)
}
}

// https://webidl.spec.whatwg.org/#abstract-opdef-converttoint
webidl.util.ConvertToInt = function (V, bitLength, signedness, opts) {
let upperBound
Expand Down Expand Up @@ -700,13 +706,6 @@ webidl.converters['record<ByteString, ByteString>'] = webidl.recordConverter(

webidl.converters.Blob = webidl.interfaceConverter(Blob)

function maybeMarkAsUncloneable (target) {
if (markAsUncloneable !== undefined) {
markAsUncloneable(target)
}
}

module.exports = {
webidl,
maybeMarkAsUncloneable
webidl
}
8 changes: 4 additions & 4 deletions lib/web/websocket/events.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { webidl, maybeMarkAsUncloneable } = require('../fetch/webidl')
const { webidl } = require('../fetch/webidl')
const { kEnumerableProperty } = require('../../core/util')
const { kConstruct } = require('../../core/symbols')
const { MessagePort } = require('node:worker_threads')
Expand All @@ -14,7 +14,7 @@ class MessageEvent extends Event {
constructor (type, eventInitDict = {}) {
if (type === kConstruct) {
super(arguments[1], arguments[2])
maybeMarkAsUncloneable(this)
webidl.util.maybeMarkAsUncloneable(this)
return
}

Expand All @@ -27,7 +27,7 @@ class MessageEvent extends Event {
super(type, eventInitDict)

this.#eventInit = eventInitDict
maybeMarkAsUncloneable(this)
webidl.util.maybeMarkAsUncloneable(this)
}

get data () {
Expand Down Expand Up @@ -114,7 +114,7 @@ class CloseEvent extends Event {
super(type, eventInitDict)

this.#eventInit = eventInitDict
maybeMarkAsUncloneable(this)
webidl.util.maybeMarkAsUncloneable(this)
}

get wasClean () {
Expand Down
4 changes: 2 additions & 2 deletions lib/web/websocket/websocket.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { webidl, maybeMarkAsUncloneable } = require('../fetch/webidl')
const { webidl } = require('../fetch/webidl')
const { URLSerializer } = require('../fetch/data-url')
const { environmentSettingsObject } = require('../fetch/util')
const { staticPropertyDescriptors, states, sentCloseFrameState, sendHints, opcodes } = require('./constants')
Expand Down Expand Up @@ -100,7 +100,7 @@ class WebSocket extends EventTarget {
constructor (url, protocols = []) {
super()

maybeMarkAsUncloneable(this)
webidl.util.maybeMarkAsUncloneable(this)

const prefix = 'WebSocket constructor'
webidl.argumentLengthCheck(arguments, 1, prefix)
Expand Down

0 comments on commit ad9f128

Please sign in to comment.