-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
assert: don't compare object prototype
property
#636
Conversation
IMO if we're going to deviate from CommonJS spec, then the docs for |
This is how they do it in ringo: https://github.com/ringo/ringojs/blob/f06dd6d0c235a0c22fc50ec6ca59209e560da396/modules/assert.js#L92 |
Can anyone review this? @chrisdickinson or @cjihrig maybe? |
A comment in the source code doesn't really cut it. |
@seishun it's not a about the comment. Some facts:
|
The code looks fine, but this goes against what I would consider "deep equal." I think a larger conversation needs to happen around the |
Can you elaborate? Do you mean this particular change or overall |
It doesn't explain what "deep equality" means either, which makes it "obvious" that it uses the algorithm from the buggy and dead spec. Let's not follow ringojs in confusing users even more. |
I mean that I would expect a |
I'm not comfortable providing sign-off on this, I'm more of a -0 on this @vkurchatkin do you see this as a necessary part of #639? |
@rvagg no, I don't. But since they share implementation |
As discussed at TC meeting, CommonJS spec is not relevant anymore. I will land this as soon as I see a couple of LGTMs. |
@@ -130,7 +130,7 @@ assert.doesNotThrow(makeBlock(a.deepEqual, nb1, nb2)); | |||
|
|||
nameBuilder2.prototype = Object; | |||
nb2 = new nameBuilder2('Ryan', 'Dahl'); | |||
assert.throws(makeBlock(a.deepEqual, nb1, nb2), a.AssertionError); | |||
assert.doesNotThrow(makeBlock(a.deepEqual, nb1, nb2), a.AssertionError); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minus , a.AssertionError
and perhaps drop the assert.doesNotThrow
call entirely? The exception can just bubble up.
Left a comment. Otherwise LGTM. |
All own enumerable properties are compared already. Comparing `prototype` property specifically can cause weird behaviour.
3168b52
to
b0c697e
Compare
removed |
I think that |
All own enumerable properties are compared already. Comparing `prototype` property specifically can cause weird behaviour. PR-URL: #636 Reviewed-By: Ben Noordhuis <[email protected]>
Thanks! landed in e7573f9 |
In the last TC meeting, I think there was some discussion about holding off on this until 2.0.0. |
I'm pretty sure it wasn't. There was some confusion with #621 though . That WAS a breaking change, this is merely a bugfix |
OK, cool. Sorry for the confusion. |
Notable changes: * stream: - Simpler stream construction, see nodejs/readable-stream#102 for details. This extends the streams base objects to make their constructors accept default implementation methods, reducing the boilerplate required to implement custom streams. An updated version of readable-stream will eventually be released to match this change in core. (@sonewman) * dns: - `lookup()` now supports an `'all'` boolean option, default to `false` but when turned on will cause the method to return an array of *all* resolved names for an address, see, #744 (@silverwind) * assert: - Remove `prototype` property comparison in `deepEqual()`, considered a bugfix, see #636 (@vkurchatkin) - Introduce a `deepStrictEqual()` method to mirror `deepEqual()` but performs strict equality checks on primitives, see #639 (@vkurchatkin) * **tracing**: - Add LTTng (Linux Trace Toolkit Next Generation) when compiled with the `--with-lttng` option. Trace points match those available for DTrace and ETW. #702 (@thekemkid) * npm upgrade to 2.5.1 * **libuv** upgrade to 1.4.0 * Add new collaborators: - Aleksey Smolenchuk (@lxe) - Shigeki Ohtsu (@shigeki)
May i add that i consider First of all, the API is horrible. Logically, either two things are equal or they're not, but As i try to show in jseq, the concept of 'equality' can lead to some hairy questions when it meets the reality of a language like JavaScript with its I suggest to introduce |
I agree that non-strict equality is not really useful for assertions (or more like not useful at all). On the other hand, shallow equality is important. There is no way to know if objects should be treated as values or having identity. It is unlikely that something would be added (or removed) to |
I fully understand the part where one wants to avoid breaking existing code and, therefore, keeps 'strange methods with strange behaviors' around and just adds new methods with 'better behavior'. Although if this principle is the only evolutional guideline then NodeJS will become ever more PHP-ish over the years ( I don't get where the difference between shallow and deep equality is important. This is really a semantic problem, and i guess where we can meet is saying that |
@cjihrig "I mean that I would expect a deepEqual implementation to examine the prototype, either using === or a call to objEquiv()"—goes to show how hairy equality can become. I'd say that if some properties of all the properties |
All own enumerable properties are compared already. Comparing
prototype
property specifically can cause weird behaviour.an alternative to #621
Example:
The first assertion is ok, the second throws. It is unexpected and has no logical explanation.
Changed test was failing because of the following
nameBuilder2.prototype = Object;
. Not sure if it is a mistake, or a test for CommonJS bug.R=@iojs/collaborators