diff --git a/lib/fetch/file.js b/lib/fetch/file.js index d0d8c68d793..2cb100de4be 100644 --- a/lib/fetch/file.js +++ b/lib/fetch/file.js @@ -98,10 +98,6 @@ class File extends Blob { return this[kState].type } - - get [Symbol.toStringTag] () { - return this.constructor.name - } } class FileLike { @@ -222,6 +218,10 @@ class FileLike { } Object.defineProperties(File.prototype, { + [Symbol.toStringTag]: { + value: 'File', + configurable: true + }, name: kEnumerableProperty, lastModified: kEnumerableProperty }) diff --git a/lib/fetch/formdata.js b/lib/fetch/formdata.js index d5e2ba661da..4b3cc71841a 100644 --- a/lib/fetch/formdata.js +++ b/lib/fetch/formdata.js @@ -8,8 +8,6 @@ const { Blob } = require('buffer') // https://xhr.spec.whatwg.org/#formdata class FormData { - static name = 'FormData' - constructor (form) { if (form !== undefined) { webidl.errors.conversionFailed({ @@ -196,10 +194,6 @@ class FormData { } } - get [Symbol.toStringTag] () { - return this.constructor.name - } - entries () { if (!(this instanceof FormData)) { throw new TypeError('Illegal invocation') @@ -265,6 +259,13 @@ class FormData { FormData.prototype[Symbol.iterator] = FormData.prototype.entries +Object.defineProperties(FormData.prototype, { + [Symbol.toStringTag]: { + value: 'FormData', + configurable: true + } +}) + /** * @see https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#create-an-entry * @param {string} name diff --git a/lib/fetch/headers.js b/lib/fetch/headers.js index 3b0eb833e5a..7ba397032d0 100644 --- a/lib/fetch/headers.js +++ b/lib/fetch/headers.js @@ -171,10 +171,6 @@ class Headers { } } - get [Symbol.toStringTag] () { - return this.constructor.name - } - // https://fetch.spec.whatwg.org/#dom-headers-append append (name, value) { if (!(this instanceof Headers)) { @@ -481,7 +477,11 @@ Object.defineProperties(Headers.prototype, { values: kEnumerableProperty, entries: kEnumerableProperty, forEach: kEnumerableProperty, - [Symbol.iterator]: { enumerable: false } + [Symbol.iterator]: { enumerable: false }, + [Symbol.toStringTag]: { + value: 'Headers', + configurable: true + } }) webidl.converters.HeadersInit = function (V) { diff --git a/lib/fetch/request.js b/lib/fetch/request.js index 7c3032bd5ed..38ce7bcf9c2 100644 --- a/lib/fetch/request.js +++ b/lib/fetch/request.js @@ -522,10 +522,6 @@ class Request { this[kState].body = finalBody } - get [Symbol.toStringTag] () { - return this.constructor.name - } - // Returns request’s HTTP method, which is "GET" by default. get method () { if (!(this instanceof Request)) { @@ -866,7 +862,11 @@ Object.defineProperties(Request.prototype, { attribute: kEnumerableProperty, referrerPolicy: kEnumerableProperty, referrer: kEnumerableProperty, - mode: kEnumerableProperty + mode: kEnumerableProperty, + [Symbol.toStringTag]: { + value: 'Request', + configurable: true + } }) webidl.converters.Request = webidl.interfaceConverter( diff --git a/lib/fetch/response.js b/lib/fetch/response.js index be97d67ce6f..f36e8406ad4 100644 --- a/lib/fetch/response.js +++ b/lib/fetch/response.js @@ -169,10 +169,6 @@ class Response { initializeResponse(this, init, bodyWithType) } - get [Symbol.toStringTag] () { - return this.constructor.name - } - // Returns response’s type, e.g., "cors". get type () { if (!(this instanceof Response)) { @@ -314,7 +310,11 @@ Object.defineProperties(Response.prototype, { headers: kEnumerableProperty, clone: kEnumerableProperty, body: kEnumerableProperty, - bodyUsed: kEnumerableProperty + bodyUsed: kEnumerableProperty, + [Symbol.toStringTag]: { + value: 'Response', + configurable: true + } }) Object.defineProperties(Response, { diff --git a/test/fetch/general.js b/test/fetch/general.js new file mode 100644 index 00000000000..0469875aa2d --- /dev/null +++ b/test/fetch/general.js @@ -0,0 +1,30 @@ +'use strict' + +const { test } = require('tap') +const { + File, + FormData, + Headers, + Request, + Response +} = require('../../index') + +test('Symbol.toStringTag descriptor', (t) => { + for (const cls of [ + File, + FormData, + Headers, + Request, + Response + ]) { + const desc = Object.getOwnPropertyDescriptor(cls.prototype, Symbol.toStringTag) + t.same(desc, { + value: cls.name, + writable: false, + enumerable: false, + configurable: true + }) + } + + t.end() +})