Skip to content

Conversation

@Alanscut
Copy link
Contributor

@Alanscut Alanscut commented Nov 27, 2019

Changes:

  1. Error message: "Object doesn't support property or method 'includes' to equal."

  2. Reason: 'includes' belongs to the API of ES7, ie11 does not support it.

    https://github.com/axios/axios/blob/master/lib/utils.js#L29

  3. Related PR Remove dependency on is-buffer #1816

lib/utils.js Outdated
*/
function isBuffer(val) {
return ![undefined, null].includes(val) && val.constructor === Buffer;
if (val === null || val === void 0 || val.constructor === null || val.constructor === void 0 ) return false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the difference between using void 0 and undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined is not a reserved word in javascript, so it can be rewritten. void 0 is stricter.

Copy link
Collaborator

@yasuf yasuf Dec 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we rely on type of x === 'undefined' throughout the file, might be better to be consistent, also are there cases where the constructor can be null? could it be sufficient to just check !isUndefined(val.constructor), also we can just use our own helper? isUndefined, what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree to use isUndefined, and I suggest to replace all the other undefined judgement with our own helper function isUndefined, if you agree, then I will submit a PR.

if constructor has been overwriten with null (extreme paticular case), then typeof val.constructor.isBuffer === 'function' will report an error.

Copy link
Contributor

@chinesedfan chinesedfan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Alanscut Can we simply copy the implementation from is-buffer, as well as its tests? Of course, with a reference comment. That looks clear and simple. And don't change the position of function isUndefined if not necessary.

@Alanscut
Copy link
Contributor Author

Alanscut commented Dec 6, 2019

@Alanscut Can we simply copy the implementation from is-buffer, as well as its tests? Of course, with a reference comment. That looks clear and simple. And don't change the position of function isUndefined if not necessary.

@chinesedfan because we have to obey the 3 rules of eslint:

@Alanscut Alanscut merged commit 13c948e into axios:master Dec 9, 2019
@axios axios locked and limited conversation to collaborators May 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants