Skip to content
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

webidl: small changes #1754

Merged
merged 4 commits into from Nov 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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