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
Add Object.getOwnPropertyDescriptors tests #484
Add Object.getOwnPropertyDescriptors tests #484
Conversation
author: Jordan Harband | ||
---*/ | ||
|
||
var F = function G() {}; |
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.
The G
identifier is not relevant for this test
Looking good, @ljharb! I left some in-line notes for minor alterations. One patch-wide suggestion concerns the |
Oh, and one more test! For
We're want something like, assert.sameValue(
Object.getPrototypeOf(Object.getOwnPropertyDescriptors({})),
Object.prototype
); |
Thanks, I'll make the requested changes |
Updated! |
here's one you could try: var i = 0;
var descriptors = [
{ enumerable: false, value: "A1", writable: true, configurable: true },
{ enumerable: true, value: "A2", writable: true, configurable: true }
];
var log = "";
var proxy = new Proxy({}, {
ownKeys() {
log += "ownKeys|";
return ["DUPLICATE", "DUPLICATE", "DUPLICATE"];
},
getOwnPropertyDescriptor(t, name) {
log += "getOwnPropertyDescriptor:" + name + "|";
return descriptors[i++];
}
});
var result = Object.getOwnPropertyDescriptors(proxy);
assert.sameValue(result.hasOwnProperty("DUPLICATE"), true);
assert.sameValue(result.DUPLICATE, undefined);
assert.sameValue(log, "ownKeys|getOwnPropertyDescriptor:DUPLICATE|getOwnPropertyDescriptor:DUPLICATE|getOwnPropertyDescriptor:DUPLICATE|"); This exposes some currently broken code in v8, and from IRC discussions, v8 will probably have to fix its bug :d |
@jugglinmike just noticed your edit - IDs updated to "id". |
|
||
assert.sameValue( | ||
Object.keys(result).length, | ||
Object.getOwnPropertyNames(f).length, |
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.
@ljharb, what do you think about using the constant 2
here instead of Object.getOwnPropertyNames
? That way, we won't depend on the correctness of the function.
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.
sure, np
73f5f40
to
90f8b4e
Compare
90f8b4e
to
30faaeb
Compare
30faaeb
to
a07be18
Compare
a07be18
to
53d109c
Compare
53d109c
to
b264c5c
Compare
@goyakin @jugglinmike friendly ping! :-D |
I disagree. These tests are themselves for the a helper function. Introducing a helper to test a helper seems a little too abstract (and would necessitate tests for the helper for the tests for the helper :P). |
construct: function () {}, | ||
}); | ||
|
||
function assertTrapSucceeds(trap) { |
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.
It's not enough to check that the trap didn't throw because we also want to be
sure that the specified function was invoked. If you want to enforce a loose
contract, you could assert this with a counter variable for each provided trap.
If you don't mind stricter tests (or just want to avoid all those counters),
you could
-var traps = allowProxyTraps({
-var input = {
getPrototypeOf: function () {},
setPrototypeOf: function () {},
...
apply: function () {},
construct: function () {},
-});
+};
+var traps = allowProxyTraps(input);
...and then
-function assertTrapSucceeds(trap) {
+function assertCustom(trap) {
+ if (input[trap] !== traps[trap]) {
+ throw new Test262Error('Expected custom trap');
+ }
+}
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.
That's a fair point - although I'd say it is enough here since there's a parallel test that asserts that it does throw when an override isn't defined. I'll update with this change.
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.
Updated!
I can see how testing a helper for a helper might be weird, but we don't have to have the additional tests. We enumerate the traps manually in two places and need to manually verify that all of them are covered in both anyway. Moreover, when a new trap is added, we won't have to look for all the files where all traps are used if we have the helper. We currently need all traps only in two files, so this isn't much of a problem though. |
Looks good to me! |
5a0dc67
to
f162c8d
Compare
ownKeys: overrides.ownKeys || throwTest262Error('[[OwnPropertyKeys]] trap called'), | ||
apply: overrides.apply || throwTest262Error('[[Call]] trap called'), | ||
construct: overrides.construct || throwTest262Error('[[Construct]] trap called') | ||
}; |
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.
We need to return traps
from the function 😉
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.
whoops again :-) thanks, fixed
f162c8d
to
a6fad62
Compare
Add Object.getOwnPropertyDescriptors tests
Thank you! Onward towards stage 4! |
|
||
var result = Object.getOwnPropertyDescriptors(obj); | ||
|
||
assert.sameValue(Object.keys(result).length, 3, 'obj has 3 descriptors'); |
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.
Object.keys() does not include Symbols, only Strings --- so this doesn't really work. See https://build.chromium.org/p/tryserver.v8/builders/v8_linux64_asan_rel/builds/14411/steps/Test262%20-%20no%20variants/logs/symbols-included/text
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.
#518 fixes this issue.
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.
alright, leave a note on my PR I guess
Tests for the stage 3 proposal for
Object.getOwnPropertyDescriptors
.