Skip to content

webidl changes #3175

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

Merged
merged 4 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/web/cache/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -810,17 +810,17 @@ const cacheQueryOptionConverters = [
{
key: 'ignoreSearch',
converter: webidl.converters.boolean,
defaultValue: false
defaultValue: () => false
},
{
key: 'ignoreMethod',
converter: webidl.converters.boolean,
defaultValue: false
defaultValue: () => false
},
{
key: 'ignoreVary',
converter: webidl.converters.boolean,
defaultValue: false
defaultValue: () => false
}
]

Expand Down
18 changes: 9 additions & 9 deletions lib/web/cookies/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ webidl.converters.DeleteCookieAttributes = webidl.dictionaryConverter([
{
converter: webidl.nullableConverter(webidl.converters.DOMString),
key: 'path',
defaultValue: null
defaultValue: () => null
},
{
converter: webidl.nullableConverter(webidl.converters.DOMString),
key: 'domain',
defaultValue: null
defaultValue: () => null
}
])

Expand All @@ -137,32 +137,32 @@ webidl.converters.Cookie = webidl.dictionaryConverter([
return new Date(value)
}),
key: 'expires',
defaultValue: null
defaultValue: () => null
},
{
converter: webidl.nullableConverter(webidl.converters['long long']),
key: 'maxAge',
defaultValue: null
defaultValue: () => null
},
{
converter: webidl.nullableConverter(webidl.converters.DOMString),
key: 'domain',
defaultValue: null
defaultValue: () => null
},
{
converter: webidl.nullableConverter(webidl.converters.DOMString),
key: 'path',
defaultValue: null
defaultValue: () => null
},
{
converter: webidl.nullableConverter(webidl.converters.boolean),
key: 'secure',
defaultValue: null
defaultValue: () => null
},
{
converter: webidl.nullableConverter(webidl.converters.boolean),
key: 'httpOnly',
defaultValue: null
defaultValue: () => null
},
{
converter: webidl.converters.USVString,
Expand All @@ -172,7 +172,7 @@ webidl.converters.Cookie = webidl.dictionaryConverter([
{
converter: webidl.sequenceConverter(webidl.converters.DOMString),
key: 'unparsed',
defaultValue: []
defaultValue: () => new Array(0)
}
])

Expand Down
2 changes: 1 addition & 1 deletion lib/web/eventsource/eventsource.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ webidl.converters.EventSourceInitDict = webidl.dictionaryConverter([
{
key: 'withCredentials',
converter: webidl.converters.boolean,
defaultValue: false
defaultValue: () => false
},
{
key: 'dispatcher', // undici only
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 @@ -569,12 +569,12 @@ webidl.converters.ResponseInit = webidl.dictionaryConverter([
{
key: 'status',
converter: webidl.converters['unsigned short'],
defaultValue: 200
defaultValue: () => 200
},
{
key: 'statusText',
converter: webidl.converters.ByteString,
defaultValue: ''
defaultValue: () => ''
},
{
key: 'headers',
Expand Down
32 changes: 16 additions & 16 deletions lib/web/fetch/webidl.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ webidl.errors.invalidArgument = function (context) {
}

// https://webidl.spec.whatwg.org/#implements
webidl.brandCheck = function (V, I, opts = undefined) {
webidl.brandCheck = function (V, I, opts) {
if (opts?.strict !== false) {
if (!(V instanceof I)) {
throw new TypeError('Illegal invocation')
Expand Down Expand Up @@ -83,7 +83,7 @@ webidl.util.Type = function (V) {
}

// https://webidl.spec.whatwg.org/#abstract-opdef-converttoint
webidl.util.ConvertToInt = function (V, bitLength, signedness, opts = {}) {
webidl.util.ConvertToInt = function (V, bitLength, signedness, opts) {
let upperBound
let lowerBound

Expand Down Expand Up @@ -127,7 +127,7 @@ webidl.util.ConvertToInt = function (V, bitLength, signedness, opts = {}) {

// 6. If the conversion is to an IDL type associated
// with the [EnforceRange] extended attribute, then:
if (opts.enforceRange === true) {
if (opts?.enforceRange === true) {
// 1. If x is NaN, +∞, or −∞, then throw a TypeError.
if (
Number.isNaN(x) ||
Expand Down Expand Up @@ -159,7 +159,7 @@ webidl.util.ConvertToInt = function (V, bitLength, signedness, opts = {}) {
// 7. If x is not NaN and the conversion is to an IDL
// type associated with the [Clamp] extended
// attribute, then:
if (!Number.isNaN(x) && opts.clamp === true) {
if (!Number.isNaN(x) && opts?.clamp === true) {
// 1. Set x to min(max(x, lowerBound), upperBound).
x = Math.min(Math.max(x, lowerBound), upperBound)

Expand Down Expand Up @@ -335,8 +335,8 @@ webidl.recordConverter = function (keyConverter, valueConverter) {
}

webidl.interfaceConverter = function (i) {
return (V, opts = {}) => {
if (opts.strict !== false && !(V instanceof i)) {
return (V, opts) => {
if (opts?.strict !== false && !(V instanceof i)) {
throw webidl.errors.exception({
header: i.name,
message: `Expected ${webidl.util.Stringify(V)} to be an instance of ${i.name}.`
Expand Down Expand Up @@ -379,7 +379,7 @@ webidl.dictionaryConverter = function (converters) {
// Only use defaultValue if value is undefined and
// a defaultValue options was provided.
if (hasDefault && value !== null) {
value = value ?? defaultValue
value ??= defaultValue()
}

// A key can be optional and have no default value.
Expand Down Expand Up @@ -417,12 +417,12 @@ webidl.nullableConverter = function (converter) {
}

// https://webidl.spec.whatwg.org/#es-DOMString
webidl.converters.DOMString = function (V, opts = {}) {
webidl.converters.DOMString = function (V, opts) {
// 1. If V is null and the conversion is to an IDL type
// associated with the [LegacyNullToEmptyString]
// extended attribute, then return the DOMString value
// that represents the empty string.
if (V === null && opts.legacyNullToEmptyString) {
if (V === null && opts?.legacyNullToEmptyString) {
return ''
}

Expand Down Expand Up @@ -519,7 +519,7 @@ webidl.converters['unsigned short'] = function (V, opts) {
}

// https://webidl.spec.whatwg.org/#idl-ArrayBuffer
webidl.converters.ArrayBuffer = function (V, opts = {}) {
webidl.converters.ArrayBuffer = function (V, opts) {
// 1. If Type(V) is not Object, or V does not have an
// [[ArrayBufferData]] internal slot, then throw a
// TypeError.
Expand All @@ -540,7 +540,7 @@ webidl.converters.ArrayBuffer = function (V, opts = {}) {
// with the [AllowShared] extended attribute, and
// IsSharedArrayBuffer(V) is true, then throw a
// TypeError.
if (opts.allowShared === false && types.isSharedArrayBuffer(V)) {
if (opts?.allowShared === false && types.isSharedArrayBuffer(V)) {
throw webidl.errors.exception({
header: 'ArrayBuffer',
message: 'SharedArrayBuffer is not allowed.'
Expand All @@ -563,7 +563,7 @@ webidl.converters.ArrayBuffer = function (V, opts = {}) {
return V
}

webidl.converters.TypedArray = function (V, T, opts = {}) {
webidl.converters.TypedArray = function (V, T, opts) {
// 1. Let T be the IDL type V is being converted to.

// 2. If Type(V) is not Object, or V does not have a
Expand All @@ -585,7 +585,7 @@ webidl.converters.TypedArray = function (V, T, opts = {}) {
// with the [AllowShared] extended attribute, and
// IsSharedArrayBuffer(V.[[ViewedArrayBuffer]]) is
// true, then throw a TypeError.
if (opts.allowShared === false && types.isSharedArrayBuffer(V.buffer)) {
if (opts?.allowShared === false && types.isSharedArrayBuffer(V.buffer)) {
throw webidl.errors.exception({
header: 'ArrayBuffer',
message: 'SharedArrayBuffer is not allowed.'
Expand All @@ -608,7 +608,7 @@ webidl.converters.TypedArray = function (V, T, opts = {}) {
return V
}

webidl.converters.DataView = function (V, opts = {}) {
webidl.converters.DataView = function (V, opts) {
// 1. If Type(V) is not Object, or V does not have a
// [[DataView]] internal slot, then throw a TypeError.
if (webidl.util.Type(V) !== 'Object' || !types.isDataView(V)) {
Expand All @@ -622,7 +622,7 @@ webidl.converters.DataView = function (V, opts = {}) {
// with the [AllowShared] extended attribute, and
// IsSharedArrayBuffer(V.[[ViewedArrayBuffer]]) is true,
// then throw a TypeError.
if (opts.allowShared === false && types.isSharedArrayBuffer(V.buffer)) {
if (opts?.allowShared === false && types.isSharedArrayBuffer(V.buffer)) {
throw webidl.errors.exception({
header: 'ArrayBuffer',
message: 'SharedArrayBuffer is not allowed.'
Expand All @@ -646,7 +646,7 @@ webidl.converters.DataView = function (V, opts = {}) {
}

// https://webidl.spec.whatwg.org/#BufferSource
webidl.converters.BufferSource = function (V, opts = {}) {
webidl.converters.BufferSource = function (V, opts) {
if (types.isAnyArrayBuffer(V)) {
return webidl.converters.ArrayBuffer(V, { ...opts, allowShared: false })
}
Expand Down
12 changes: 6 additions & 6 deletions lib/web/fileapi/progressevent.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,32 @@ webidl.converters.ProgressEventInit = webidl.dictionaryConverter([
{
key: 'lengthComputable',
converter: webidl.converters.boolean,
defaultValue: false
defaultValue: () => false
},
{
key: 'loaded',
converter: webidl.converters['unsigned long long'],
defaultValue: 0
defaultValue: () => 0
},
{
key: 'total',
converter: webidl.converters['unsigned long long'],
defaultValue: 0
defaultValue: () => 0
},
{
key: 'bubbles',
converter: webidl.converters.boolean,
defaultValue: false
defaultValue: () => false
},
{
key: 'cancelable',
converter: webidl.converters.boolean,
defaultValue: false
defaultValue: () => false
},
{
key: 'composed',
converter: webidl.converters.boolean,
defaultValue: false
defaultValue: () => false
}
])

Expand Down
32 changes: 15 additions & 17 deletions lib/web/websocket/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,17 +222,17 @@ const eventInit = [
{
key: 'bubbles',
converter: webidl.converters.boolean,
defaultValue: false
defaultValue: () => false
},
{
key: 'cancelable',
converter: webidl.converters.boolean,
defaultValue: false
defaultValue: () => false
},
{
key: 'composed',
converter: webidl.converters.boolean,
defaultValue: false
defaultValue: () => false
}
]

Expand All @@ -241,31 +241,29 @@ webidl.converters.MessageEventInit = webidl.dictionaryConverter([
{
key: 'data',
converter: webidl.converters.any,
defaultValue: null
defaultValue: () => null
},
{
key: 'origin',
converter: webidl.converters.USVString,
defaultValue: ''
defaultValue: () => ''
},
{
key: 'lastEventId',
converter: webidl.converters.DOMString,
defaultValue: ''
defaultValue: () => ''
},
{
key: 'source',
// Node doesn't implement WindowProxy or ServiceWorker, so the only
// valid value for source is a MessagePort.
converter: webidl.nullableConverter(webidl.converters.MessagePort),
defaultValue: null
defaultValue: () => null
},
{
key: 'ports',
converter: webidl.converters['sequence<MessagePort>'],
get defaultValue () {
return []
}
defaultValue: () => new Array(0)
}
])

Expand All @@ -274,17 +272,17 @@ webidl.converters.CloseEventInit = webidl.dictionaryConverter([
{
key: 'wasClean',
converter: webidl.converters.boolean,
defaultValue: false
defaultValue: () => false
},
{
key: 'code',
converter: webidl.converters['unsigned short'],
defaultValue: 0
defaultValue: () => 0
},
{
key: 'reason',
converter: webidl.converters.USVString,
defaultValue: ''
defaultValue: () => ''
}
])

Expand All @@ -293,22 +291,22 @@ webidl.converters.ErrorEventInit = webidl.dictionaryConverter([
{
key: 'message',
converter: webidl.converters.DOMString,
defaultValue: ''
defaultValue: () => ''
},
{
key: 'filename',
converter: webidl.converters.USVString,
defaultValue: ''
defaultValue: () => ''
},
{
key: 'lineno',
converter: webidl.converters['unsigned long'],
defaultValue: 0
defaultValue: () => 0
},
{
key: 'colno',
converter: webidl.converters['unsigned long'],
defaultValue: 0
defaultValue: () => 0
},
{
key: 'error',
Expand Down
Loading