-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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.deepStrictEqual() fails to compare ES6 style object properties #11803
Comments
With the changes in the new V8 API, accessor properties are not flattened anymore (patch hopefully coming soon as we are working on it with @fhinkel :)) and descriptors can have attributes that are functions (getters/setters). E.g. the following test will not throw with the new API: I wrote a piece of code that fixed the issue:
Happy to contribute it to assert.js. I was not able to figure out how to weave it into the existing code, though. |
cc/ @fhinkel |
You define two different functions as the |
I think this again raises the issue on whether we should add support for new ES features in assert...(see #11113). Similar to descriptors, the assertions don't work on Maps, Sets either.. Also related: last CTC minutes on this https://github.com/nodejs/CTC/blob/master/meetings/2017-02-01.md#assert-enforce-type-check-in-deepstrictequal-node10282 |
@AnnaMag If I understand your code correctly, you would say that |
(Also just noticed the comments above https://github.com/nodejs/node/blob/master/lib/assert.js#L200 are not correct...at least not until #10282 is merged, uh..) |
@addaleax, correct... might not be in line with the overall design. What I am after is to have a way to test whether ES6 property descriptors work correctly in the vm. After removing CopyProperties() and using the 5.5 V8 API, this test (among others) |
@AnnaMag I think if the bug has been fixed, https://github.com/nodejs/node/blob/master/test/known_issues/test-vm-getters.js should pass now ? Because |
@joyeecheung, exactly, it should pass :) Yet it does not, which is the very thing that made me check the code to find out why:
This is the same for What also happens is that even if it did work, it would not compare the values of the accessors (only attribute keys), as (as far as I understand it), comparing functions in JS requires a hack, e.g. .toString(). |
Ah – sorry, I think I understand how this relates to the Since the test is supposed to be a test for #2734, I think it would be okay to fix this up in the test itself (replacing |
@joyeecheung, the code snippet with common definition of Summing up, https://github.com/nodejs/node/blob/master/test/known_issues/test-vm-getters.js is not a valid test then. Is PR a good idea here? |
Looks like it, yes… I’m not sure but I don’t think we’ll want to turn the prototype-equals-prototype check into a deep comparison, and that’s the only alternative I can think of right now. Maybe @fhinkel or @joyeecheung have better ideas but fixing up the test seems like the best option to me. |
Very helpful @addaleax, thanks! |
@addaleax Unfortunately, deep comparison of prototypes doesn't work with API that conforms to WebIDL(e.g. WHATWG URL), because the properties are defined as enumerable owned properties on the prototype, so if we enumerate through the prototype, for example, |
@AnnaMag Since the strict assertions use assert.deepStrictEqual(Object.keys(result), Object.keys(descriptor));
for (const prop in Object.keys(result)) {
assert.strictEqual(result[prop], descriptor[prop]);
} This throws
in the master at the moment(which is exactly what #2734 is about..) Also on comparing accessors: the assertions are testing the output of accessors, not the accessors themselves..at the moment they just care about the equality of the output, not how the output is obtained. |
@joyeecheung, many thanks! I was referring to the code snippet you gave as an example:
That should work on master, right? |
@AnnaMag Yes, on master and 7.6.0, this passes: 'use strict';
const assert = require('assert');
function foo() { return 'foo'; }
const x = {};
Object.defineProperty(x, 'prop', {
get: foo
});
const y = {};
Object.defineProperty(y, 'prop', {
get: foo
});
const descriptorx = Object.getOwnPropertyDescriptor(x, 'prop');
const descriptory = Object.getOwnPropertyDescriptor(y, 'prop');
assert.deepStrictEqual(x, y); // ok
assert.deepStrictEqual(descriptorx, descriptory); // ok |
Can we close this and you adjust the test accordingly? |
I believe so. I will do a PR for the test. |
Remove the CopyProperties() hack in the vm module, i.e., Contextify. Use different V8 API methods, that allow interception of DefineProperty() and do not flatten accessor descriptors to property descriptors. Move many known issues to test cases. Factor out the last test in test-vm-context.js for nodejs#10223 into its own file, test-vm-strict-assign.js. Part of this CL is taken from a stalled PR by https://github.com/AnnaMag nodejs#13265 This PR requires a backport of https://chromium.googlesource.com/v8/v8/+/37a3a15c3e52e2146e45f41c427f24414e4d7f6f Refs: nodejs#6283 Refs: nodejs#15114 Refs: nodejs#13265 Fixes: nodejs#2734 Fixes: nodejs#10223 Fixes: nodejs#11803 Fixes: nodejs#11902
Remove the CopyProperties() hack in the vm module, i.e., Contextify. Use different V8 API methods, that allow interception of DefineProperty() and do not flatten accessor descriptors to property descriptors. Move many known issues to test cases. Factor out the last test in test-vm-context.js for nodejs#10223 into its own file, test-vm-strict-assign.js. Part of this CL is taken from a stalled PR by https://github.com/AnnaMag nodejs#13265 This PR requires a backport of https://chromium.googlesource.com/v8/v8/+/37a3a15c3e52e2146e45f41c427f24414e4d7f6f PR-URL: nodejs#16293 Fixes: nodejs#2734 Fixes: nodejs#10223 Fixes: nodejs#11803 Fixes: nodejs#11902 Ref: nodejs#6283 Ref: nodejs#15114 Ref: nodejs#13265 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
Remove the CopyProperties() hack in the vm module, i.e., Contextify. Use different V8 API methods, that allow interception of DefineProperty() and do not flatten accessor descriptors to property descriptors. Move many known issues to test cases. Factor out the last test in test-vm-context.js for nodejs/node#10223 into its own file, test-vm-strict-assign.js. Part of this CL is taken from a stalled PR by https://github.com/AnnaMag nodejs/node#13265 This PR requires a backport of https://chromium.googlesource.com/v8/v8/+/37a3a15c3e52e2146e45f41c427f24414e4d7f6f PR-URL: nodejs/node#16293 Fixes: nodejs/node#2734 Fixes: nodejs/node#10223 Fixes: nodejs/node#11803 Fixes: nodejs/node#11902 Ref: nodejs/node#6283 Ref: nodejs/node#15114 Ref: nodejs/node#13265 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
Remove the CopyProperties() hack in the vm module, i.e., Contextify. Use different V8 API methods, that allow interception of DefineProperty() and do not flatten accessor descriptors to property descriptors. Move many known issues to test cases. Factor out the last test in test-vm-context.js for nodejs/node#10223 into its own file, test-vm-strict-assign.js. Part of this CL is taken from a stalled PR by https://github.com/AnnaMag nodejs/node#13265 This PR requires a backport of https://chromium.googlesource.com/v8/v8/+/37a3a15c3e52e2146e45f41c427f24414e4d7f6f PR-URL: nodejs/node#16293 Fixes: nodejs/node#2734 Fixes: nodejs/node#10223 Fixes: nodejs/node#11803 Fixes: nodejs/node#11902 Ref: nodejs/node#6283 Ref: nodejs/node#15114 Ref: nodejs/node#13265 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
The following assertion fails when objects are property descriptors:
What seems to happen is that (in both cases)
Object.getPrototypeOf(descriptor)
results in
{}
, which leads to the conditionhttps://github.com/nodejs/node/blob/master/lib/assert.js#L200
returning false. Same is true for
assert.strictEqual()
The text was updated successfully, but these errors were encountered: