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

Remove 'includes' API, fix CI build failure #2574

Merged
merged 4 commits into from Dec 9, 2019

Conversation

Alanscut
Copy link
Collaborator

@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
@@ -26,7 +26,8 @@ function isArray(val) {
* @returns {boolean} True if value is a Buffer, otherwise false
*/
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
Collaborator 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
Collaborator 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
Collaborator

@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
Collaborator 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:

lib/utils.js Outdated Show resolved Hide resolved
@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.

None yet

3 participants