Skip to content

Do not use constructor.name to check object #667

@yumetodo

Description

@yumetodo

isAbortSignal and isBlob use constructor.name only to check.

https://github.com/bitinn/node-fetch/blob/bf8b4e8db350ec76dbb9236620f774fcc21b8c12/src/request.js#L36-L43

https://github.com/bitinn/node-fetch/blob/95286f52bb866283bc69521a04efe1de37b26a33/src/body.js#L364-L378

However, constructor.name can be rewrited. So, for example, webpack4 with production mode will break constructor.name of AbortSignal that will be rewritten to "s".

image

So, Expected signal to be an instanceof AbortSignal Error was occured (ref: yumetodo/vscode-google-photos-uploader#11 )

isURLSearchParams is adopting good implementation (ref: #296 (comment), 302992d ). Object.prototype.toString() will call Symbol.toStringTag propaty which is not writable(see MDN)

https://github.com/bitinn/node-fetch/blob/95286f52bb866283bc69521a04efe1de37b26a33/src/body.js#L346-L362

Of course, I know that there are two workarounds for webpack4:

  1. Set optimization.minimize to false (ref: function constructor name changed after bundled as a library webpack/webpack#6841 (comment))
  2. Specify minimizer manually and set keep_fnames to true (ref: Keep function names in build for production mode CartoDB/carto-vl#1066)

However, rely on constructor.name is a bad idea, I think.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions