Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

rbuckton
Copy link
Contributor

@rbuckton rbuckton commented Dec 6, 2023

This adds tests for the Stage 3 Decorator Metadata proposal, per the specification PR at pzuraq/ecma262#10.

/cc: @pzuraq

Copy link
Member

@ljharb ljharb left a 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.

@ljharb ljharb requested a review from a team February 28, 2024 16:27
Copy link
Contributor

@ptomato ptomato left a 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.

Comment on lines +48 to +60
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,
});
Copy link
Contributor

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.
Copy link
Contributor

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?

Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)

Copy link
Contributor

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,
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants