-
Notifications
You must be signed in to change notification settings - Fork 461
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 tests for Stage 3 Decorator Metadata #3971
base: main
Are you sure you want to change the base?
Conversation
fca9a74
to
d615112
Compare
d615112
to
ae45c3d
Compare
test/language/expressions/class/decorator/metadata/context-metadata-prop-desc.js
Outdated
Show resolved
Hide resolved
test/language/expressions/class/decorator/metadata/metadata-attached-when-class-is-decorated.js
Outdated
Show resolved
Hide resolved
test/language/expressions/class/decorator/metadata/metadata-prop-desc.js
Outdated
Show resolved
Hide resolved
test/language/statements/class/decorator/metadata/context-metadata-prop-desc.js
Outdated
Show resolved
Hide resolved
test/language/statements/class/decorator/metadata/context-metadata.js
Outdated
Show resolved
Hide resolved
test/language/statements/class/decorator/metadata/metadata-attached-when-class-is-decorated.js
Outdated
Show resolved
Hide resolved
test/language/statements/class/decorator/metadata/metadata-prop-desc.js
Outdated
Show resolved
Hide resolved
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.
seems good! would be nice to have another review before merging.
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.
Thanks for doing this!
The only blocker would be the context metadata property descriptor (if I'm correct about that.) I had a few other suggestions for improvements elsewhere.
Note that all the comments on expressions/class/decorator/metadata/
apply to the corresponding tests in statements/class/decorator/metadata/
as well.
assert.deepEqual(kinds, { | ||
"class": true, | ||
"public method": true, | ||
"public getter": true, | ||
"public setter": true, | ||
"public field": true, | ||
"public accessor": true, | ||
"private method": true, | ||
"private getter": true, | ||
"private setter": true, | ||
"private field": true, | ||
"private accessor": true, | ||
}); |
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're trying to get rid of assert.deepEqual
(#3476). Maybe assert.compareArray(Object.entries(kinds), [...])
would work here.
/*--- | ||
esid: sec-createdecoratorcontextobject | ||
description: > | ||
Property descriptor for metadata property of decorator context object. |
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 test doesn't seem to be about the property descriptor, maybe this was accidentally copied from another test?
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.
One thing this test could additionally do that it doesn't currently do: make sure the private/kind metadata for each invocation of the decorator matches the type of thing that it decorates. Currently the test passes if each private/kind combination is hit once, but an implementation could switch two of them (e.g., private accessors are reported as public and vice versa) and the test would still pass.
(May or may not be worth it.)
/*--- | ||
esid: sec-runtime-semantics-classdefinitionevaluation | ||
description: > | ||
Metadata on a derived class inherits from the metadata of the declared super class. |
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.
Suggestion, the description could be a bit more specific here, more like the title of the test: maybe something like "Metadata on a derived class inherits from the original metadata of the declared super class, unaffected by overwriting"
/*--- | ||
esid: sec-runtime-semantics-classdefinitionevaluation | ||
description: > | ||
Metadata is only attached when a class or class element is decorated. |
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.
This description seems copied from somewhere else, maybe something like "Metadata inherits from the metadata of the super class"?
|
||
let C = @dec class C {}; | ||
const metadata = C[Symbol.metadata]; | ||
assert(Object.isExtensible(metadata)); |
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.
assert(Object.isExtensible(metadata)); | |
assert(Object.isExtensible(metadata), "Metadata is not frozen"); |
(I suggest using assertion messages at least in plain assert()
, otherwise if it fails you get "Expected false to be true" or something like that)
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.
Should we additionally verify that the object is a plain object, something like this?
assert.sameValue(Object.getPrototypeOf(metadata), Object.prototype, "Metadata's prototype is Object.prototype");
void @dec class C {}; | ||
assert.sameValue(typeof contextObj.metadata, "object"); | ||
verifyProperty(contextObj, 'metadata', { | ||
enumerable: false, |
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.
By my reading of the spec, this seems like it should be true? In CreateDecoratorContextObject we create the property with CreateDataPropertyOrThrow, which calls CreateDataProperty, which creates enumerable properties.
This adds tests for the Stage 3 Decorator Metadata proposal, per the specification PR at pzuraq/ecma262#10.
/cc: @pzuraq