Skip to content

Commit

Permalink
webidl: small changes (nodejs#1754)
Browse files Browse the repository at this point in the history
  • Loading branch information
KhafraDev authored and crysmags committed Feb 27, 2024
1 parent 6fbc57e commit 99fb8b7
Show file tree
Hide file tree
Showing 10 changed files with 332 additions and 317 deletions.
11 changes: 3 additions & 8 deletions lib/fetch/body.js
Expand Up @@ -331,9 +331,7 @@ function bodyMixinMethods (instance) {
},

async formData () {
if (!(this instanceof instance)) {
throw new TypeError('Illegal invocation')
}
webidl.brandCheck(this, instance)

throwIfAborted(this[kState])

Expand Down Expand Up @@ -435,7 +433,7 @@ function bodyMixinMethods (instance) {
throwIfAborted(this[kState])

// Otherwise, throw a TypeError.
webidl.errors.exception({
throw webidl.errors.exception({
header: `${instance.name}.formData`,
message: 'Could not parse content as FormData.'
})
Expand All @@ -452,11 +450,8 @@ function mixinBody (prototype) {

// https://fetch.spec.whatwg.org/#concept-body-consume-body
async function specConsumeBody (object, type, instance) {
if (!(object instanceof instance)) {
throw new TypeError('Illegal invocation')
}
webidl.brandCheck(object, instance)

// TODO: why is this needed?
throwIfAborted(object[kState])

// 1. If object is unusable, then return a promise rejected
Expand Down
44 changes: 11 additions & 33 deletions lib/fetch/file.js
Expand Up @@ -76,25 +76,19 @@ class File extends Blob {
}

get name () {
if (!(this instanceof File)) {
throw new TypeError('Illegal invocation')
}
webidl.brandCheck(this, File)

return this[kState].name
}

get lastModified () {
if (!(this instanceof File)) {
throw new TypeError('Illegal invocation')
}
webidl.brandCheck(this, File)

return this[kState].lastModified
}

get type () {
if (!(this instanceof File)) {
throw new TypeError('Illegal invocation')
}
webidl.brandCheck(this, File)

return this[kState].type
}
Expand Down Expand Up @@ -149,65 +143,49 @@ class FileLike {
}

stream (...args) {
if (!(this instanceof FileLike)) {
throw new TypeError('Illegal invocation')
}
webidl.brandCheck(this, FileLike)

return this[kState].blobLike.stream(...args)
}

arrayBuffer (...args) {
if (!(this instanceof FileLike)) {
throw new TypeError('Illegal invocation')
}
webidl.brandCheck(this, FileLike)

return this[kState].blobLike.arrayBuffer(...args)
}

slice (...args) {
if (!(this instanceof FileLike)) {
throw new TypeError('Illegal invocation')
}
webidl.brandCheck(this, FileLike)

return this[kState].blobLike.slice(...args)
}

text (...args) {
if (!(this instanceof FileLike)) {
throw new TypeError('Illegal invocation')
}
webidl.brandCheck(this, FileLike)

return this[kState].blobLike.text(...args)
}

get size () {
if (!(this instanceof FileLike)) {
throw new TypeError('Illegal invocation')
}
webidl.brandCheck(this, FileLike)

return this[kState].blobLike.size
}

get type () {
if (!(this instanceof FileLike)) {
throw new TypeError('Illegal invocation')
}
webidl.brandCheck(this, FileLike)

return this[kState].blobLike.type
}

get name () {
if (!(this instanceof FileLike)) {
throw new TypeError('Illegal invocation')
}
webidl.brandCheck(this, FileLike)

return this[kState].name
}

get lastModified () {
if (!(this instanceof FileLike)) {
throw new TypeError('Illegal invocation')
}
webidl.brandCheck(this, FileLike)

return this[kState].lastModified
}
Expand Down
42 changes: 11 additions & 31 deletions lib/fetch/formdata.js
Expand Up @@ -10,7 +10,7 @@ const { Blob } = require('buffer')
class FormData {
constructor (form) {
if (form !== undefined) {
webidl.errors.conversionFailed({
throw webidl.errors.conversionFailed({
prefix: 'FormData constructor',
argument: 'Argument 1',
types: ['undefined']
Expand All @@ -21,9 +21,7 @@ class FormData {
}

append (name, value, filename = undefined) {
if (!(this instanceof FormData)) {
throw new TypeError('Illegal invocation')
}
webidl.brandCheck(this, FormData)

if (arguments.length < 2) {
throw new TypeError(
Expand Down Expand Up @@ -56,9 +54,7 @@ class FormData {
}

delete (name) {
if (!(this instanceof FormData)) {
throw new TypeError('Illegal invocation')
}
webidl.brandCheck(this, FormData)

if (arguments.length < 1) {
throw new TypeError(
Expand All @@ -81,9 +77,7 @@ class FormData {
}

get (name) {
if (!(this instanceof FormData)) {
throw new TypeError('Illegal invocation')
}
webidl.brandCheck(this, FormData)

if (arguments.length < 1) {
throw new TypeError(
Expand All @@ -106,9 +100,7 @@ class FormData {
}

getAll (name) {
if (!(this instanceof FormData)) {
throw new TypeError('Illegal invocation')
}
webidl.brandCheck(this, FormData)

if (arguments.length < 1) {
throw new TypeError(
Expand All @@ -128,9 +120,7 @@ class FormData {
}

has (name) {
if (!(this instanceof FormData)) {
throw new TypeError('Illegal invocation')
}
webidl.brandCheck(this, FormData)

if (arguments.length < 1) {
throw new TypeError(
Expand All @@ -146,9 +136,7 @@ class FormData {
}

set (name, value, filename = undefined) {
if (!(this instanceof FormData)) {
throw new TypeError('Illegal invocation')
}
webidl.brandCheck(this, FormData)

if (arguments.length < 2) {
throw new TypeError(
Expand Down Expand Up @@ -195,9 +183,7 @@ class FormData {
}

entries () {
if (!(this instanceof FormData)) {
throw new TypeError('Illegal invocation')
}
webidl.brandCheck(this, FormData)

return makeIterator(
() => this[kState].map(pair => [pair.name, pair.value]),
Expand All @@ -207,9 +193,7 @@ class FormData {
}

keys () {
if (!(this instanceof FormData)) {
throw new TypeError('Illegal invocation')
}
webidl.brandCheck(this, FormData)

return makeIterator(
() => this[kState].map(pair => [pair.name, pair.value]),
Expand All @@ -219,9 +203,7 @@ class FormData {
}

values () {
if (!(this instanceof FormData)) {
throw new TypeError('Illegal invocation')
}
webidl.brandCheck(this, FormData)

return makeIterator(
() => this[kState].map(pair => [pair.name, pair.value]),
Expand All @@ -235,9 +217,7 @@ class FormData {
* @param {unknown} thisArg
*/
forEach (callbackFn, thisArg = globalThis) {
if (!(this instanceof FormData)) {
throw new TypeError('Illegal invocation')
}
webidl.brandCheck(this, FormData)

if (arguments.length < 1) {
throw new TypeError(
Expand Down

0 comments on commit 99fb8b7

Please sign in to comment.