| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
There was a problem hiding this comment.
I’ve labelled this semver-major since it looks like a pretty clear behavioural change to me, even if it seems to make a lot of sense from the first look at it.
Fixes #10258.
Could you add a Fixes: https://github.com/nodejs/node/issues/10258 line at the end of the commit message? :)
Sorry, something went wrong.
There was a problem hiding this comment.
So, this is not related to the changes you are making here, but I would have a couple of suggestions:
I guess you could probably make arguments both for including lastIndex here and for leaving it out, and I’m tempted to say “drop it”. I probably wouldn’t expect this behaviour.
Maybe instead of the global, multiline and ignoreCase checks a single check for .flags would be a good idea? There are new flags like u that would currently be ignored.
(If you think these suggestions make sense, it’s probably best to keep that for a separate commit/separate PR.)
Sorry, something went wrong.
There was a problem hiding this comment.
Good suggestion, I think I will just submit another commit in this PR.
Sorry, something went wrong.
There was a problem hiding this comment.
The indentation seems off here?
Also, could you update the instanceof checks here to use getTag, too? (probably also best kept for a separate commit or PR)
Sorry, something went wrong.
There was a problem hiding this comment.
Oops, why my make lint doesn't scream at me about this :/? I will update these indentations, thanks. And the tag checks can go into another commit I think.
Sorry, something went wrong.
There was a problem hiding this comment.
nit: Can I suggest that you update this to use the full URL here?
Sorry, something went wrong.
There was a problem hiding this comment.
Is the eslint-disable tag to that deepEqual can be used here?
Sorry, something went wrong.
There was a problem hiding this comment.
no-restricted-properties is the one I get from make lint, I can't find a specific eslint-disable tag for deepEqual, do you know what that is?
Sorry, something went wrong.
There was a problem hiding this comment.
@joyeecheung Nope, and to be clear, I wasn’t requesting you to change anything here, just making sure that I understood why the line is there in the first place
Sorry, something went wrong.
There was a problem hiding this comment.
Oh yes, this disable tag is for all the deepEquals below :).
Sorry, something went wrong.
There was a problem hiding this comment.
I think it's fine the way you did it, but if you want to get even more granular with the linting options, you can disable the check on just the lines that need it by either using // eslint-disable-line no-restricted-properties or // eslint-disable-next-line no-restricted-properties (depending on if you can fit the comment on the same line or if it needs to go on the line right before the assert.deepEqual()).
Sorry, something went wrong.
There was a problem hiding this comment.
Thank you for the tips!
Sorry, something went wrong.
There was a problem hiding this comment.
The indentation is off here, and there’s a assert.throws pitfall: You can’t specify a string to check the error message against; only a constructor, RegExp or function that checks the argument work here. (You can probably just wrap the expression in new RegExp or something)
(edit: link to docs: https://nodejs.org/api/assert.html#assert_assert_throws_block_error_message)
Sorry, something went wrong.
There was a problem hiding this comment.
Sorry for not reading the docs more thoroughly. I'll wrap them up in new RegExp, thanks!
Sorry, something went wrong.
There was a problem hiding this comment.
Sorry for not reading the docs more thoroughly.
@joyeecheung If it helps… that mistake is something found a lot in our own tests, at least until very recently ;)
Sorry, something went wrong.
There was a problem hiding this comment.
typos: returns and checks (here and below)
Sorry, something went wrong.
|
@addaleax Thanks for the review, I've updated this PR, PTAL. |
Sorry, something went wrong.
|
Thanks! This looks pretty good so far, I’ll have time for a full review of this later. CI: https://ci.nodejs.org/job/node-test-commit/6668/ |
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks for doing this! Mostly seems good to me. Not sure if we'd have to "unlock" the API, but (as of right now, at least) I'd be in favor of doing that. Some small comments.
Sorry, something went wrong.
There was a problem hiding this comment.
These numbers (7.2) correspond to the sections of a specification that assert followed in its initial implementation. http://wiki.commonjs.org/wiki/Unit_Testing/1.0
If we're going to change the algorithm, I'd recommend removing the numbers, since we're not following the spec anymore.
Sorry, something went wrong.
There was a problem hiding this comment.
Didn't know this is a thing :O I will remove those numbers. Thanks.
Sorry, something went wrong.
There was a problem hiding this comment.
Instead of removing this test, would it make sense to change it to assert.doesNotThrow?
Sorry, something went wrong.
There was a problem hiding this comment.
Good suggestion. I will update these. Thanks.
Sorry, something went wrong.
There was a problem hiding this comment.
Same here: assert.doesNotThrow()?
Sorry, something went wrong.
|
@Trott Thank you for the review, I have updated this PR, PTAL. |
Sorry, something went wrong.
|
@nodejs/ctc Would we need to "unlock" the assert module to land this? I think the answer is: "technically yes" but there might be some wiggle room on something like this? |
Sorry, something went wrong.
|
Added the blocked label until the "Locked API" issue is sorted out. |
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM if CI is ✅ and CITGM is ✨
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM. Maybe read me adding the “semver-major” label more as a precaution than anything else; I am fine considering this a bugfix.
Sorry, something went wrong.
Extend the assert-throws-arguments custom ESLint rule to also check for the use of template literals as a second argument to assert.throws. PR-URL: nodejs#10301 Ref: nodejs#10282 (comment) Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Italo A. Casas <me@italoacasas.com>
Extend the assert-throws-arguments custom ESLint rule to also check for the use of template literals as a second argument to assert.throws. PR-URL: nodejs#10301 Ref: nodejs#10282 (comment) Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Italo A. Casas <me@italoacasas.com>
Extend the assert-throws-arguments custom ESLint rule to also check for the use of template literals as a second argument to assert.throws. PR-URL: #10301 Ref: #10282 (comment) Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Italo A. Casas <me@italoacasas.com>
There was a problem hiding this comment.
I've left a few comments, but in general, it'd be awesome if new code in node core was robust against user modification of the language builtins.
Sorry, something went wrong.
There was a problem hiding this comment.
why is this == and a few lines above, ===? I assume this should be ===?
Sorry, something went wrong.
There was a problem hiding this comment.
Oops, it's mistake, thanks for catching that.
Sorry, something went wrong.
There was a problem hiding this comment.
For the sake of robustness, please cache Object.prototype.toString at module level, and don't rely on nobody having monkeyed with Object.prototype at runtime :-)
Sorry, something went wrong.
There was a problem hiding this comment.
It's safer to cache Date.prototype.getTime at module level, and .call it here - rather than relying both on .getTime not being shadowed on these two objects, and on Date.prototype being unbroken.
Sorry, something went wrong.
There was a problem hiding this comment.
Similarly, Object.keys should be cached at module level, not runtime-looked-up on Object
Sorry, something went wrong.
Refactors _deepEqual and fixes a few code paths that lead to behaviors contradicting what the doc says. Before this commit certain types of objects (Buffers, Dates, etc.) are not checked properly, and can get away with different prototypes AND different enumerable owned properties because _deepEqual would jump to premature conclusion for them. Since we no longer follow CommonJS unit testing spec, the checks for primitives and object prototypes are moved forward for faster failure. Improve regexp and float* array checks: * Don't compare lastIndex of regexps, because they are not enumerable, so according to the docs they should not be compared * Compare flags of regexps instead of separate properties * Use built-in tags to test for float* arrays instead of using instanceof Use full link to the archived GitHub repository. Use util.objectToString for future improvements to that function that makes sure the call won't be tampered with. Refs: nodejs#10282 (comment) Refs: nodejs#10258 (comment)
Refactors _deepEqual and fixes a few code paths that lead to behaviors contradicting what the doc says. Before this commit certain types of objects (Buffers, Dates, etc.) are not checked properly, and can get away with different prototypes AND different enumerable owned properties because _deepEqual would jump to premature conclusion for them. Since we no longer follow CommonJS unit testing spec, the checks for primitives and object prototypes are moved forward for faster failure. Improve regexp and float* array checks: * Don't compare lastIndex of regexps, because they are not enumerable, so according to the docs they should not be compared * Compare flags of regexps instead of separate properties * Use built-in tags to test for float* arrays instead of using instanceof Use full link to the archived GitHub repository. Use util.objectToString for future improvements to that function that makes sure the call won't be tampered with. PR-URL: #11128 Refs: #10282 (comment) Refs: #10258 (comment) Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
|
@ChALkeR Yeah this is not blocked anymore. Thanks! Did a rebase locally, haven't decided about #10282 (comment), I'll push it later. |
Sorry, something went wrong.
|
Rebased with documentation and a few more test cases (for faked global and process) |
Sorry, something went wrong.
Add checks for the built-in type tags to catch objects with faked prototypes. See https://tc39.github.io/ecma262/#sec-object.prototype.tostring for a partial list of built-in tags. Fixes: nodejs#10258
There was a problem hiding this comment.
Still LGTM :)
Sorry, something went wrong.
| ( `===` ). | ||
| 2. [`[[Prototype]]`][prototype-spec] of objects are compared using | ||
| the [Strict Equality Comparison][] too. | ||
| 3. [Type tags][Object.prototype.toString()] of objects should be the same. |
There was a problem hiding this comment.
I can’t find the definition of [Object.prototype.toString()] … am I missing something?
Sorry, something went wrong.
There was a problem hiding this comment.
Uh, forgot to put the reference link below :P
Sorry, something went wrong.
| // AssertionError: { a: 1 } deepStrictEqual { a: '1' } | ||
| // because 1 !== '1' using strict equality | ||
|
|
||
| // The following objects don't have owned properties |
There was a problem hiding this comment.
typo: own properties?
Sorry, something went wrong.
|
@addaleax Thanks for the review, fixed the typo and the missing link. |
Sorry, something went wrong.
|
The last CITGM run is also a bit old, so: CITGM: https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/641/ |
Sorry, something went wrong.
|
Went ahead and landed this in efec14a :) |
Sorry, something went wrong.
Add checks for the built-in type tags to catch objects with faked prototypes. See https://tc39.github.io/ecma262/#sec-object.prototype.tostring for a partial list of built-in tags. Fixes: #10258 PR-URL: #10282 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
Add checks for the built-in type tags to catch objects with faked prototypes. See https://tc39.github.io/ecma262/#sec-object.prototype.tostring for a partial list of built-in tags. Fixes: nodejs#10258 PR-URL: nodejs#10282 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
| Back | FazBrowse Home | New Git URL |
For a write-up on this PR, see #10282 (comment)
The less-breaking part of this PR has been moved to #11128
Checklist
Affected core subsystem(s)
assert, test
Description of change
Add checks for the built-in tags and refactor _deepEqual,
most user-land modules do this for a strict, deep comparison.
nodejs/node-v0.x-archive#7178 already added
this check for argument objects, even in non-strict tests.
Fixes #10258.
Docs updates are postponed due to #7815.
See https://tc39.github.io/ecma262/#sec-object.prototype.tostring
for a partial list of the tags.