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

Editorial: Align checks order in [[DefineOwnProperty]] overrides with ordinary method #2333

Conversation

shvaikalesh
Copy link
Member

With the current spec, if an engine precisely implements ValidateAndApplyPropertyDescriptor and module namespace object's [[DefineOwnProperty]] method, with descriptive error message for each failure, it would report different errors (given there is > 1 cause of failure) for the same (CurrentDescriptor, Descriptor) pair when called on ordinary object vs module namespace object.

Test case:

module.js:

export let test = 42;

index.js:

import("module.js").then(ns => {
    const desc = { get() {}, configurable: true };
    Object.defineProperty(ns, "test", desc); // => TypeError: Cannot change module namespace object's binding to accessor
    const plain = {};
    Object.defineProperty(plain, "test", Object.getOwnPropertyDescriptor(ns, "test"));
    Object.defineProperty(plain, "test", desc); // => TypeError: Attempting to change configurable attribute of unconfigurable property.
});

This change aligns descriptor validation order of TypedArray's and module namespace object's [[DefineOwnProperty]] methods with ValidateAndApplyPropertyDescriptor. For own non-configurable data descriptor, that is [[Configurable]] => [[Enumerable]] => IsAccessorDescriptor => [[Writable]] => [[Value]].

The discrepancy this PR fixes is currently observable only in JSC.

Copy link
Contributor

@bakkot bakkot left a comment

Choose a reason for hiding this comment

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

I'm neutral on this change, but it seems fine.

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.

i agree that the order of these steps is unobservable

@ljharb ljharb added editorial change ready to merge Editors believe this PR needs no further reviews, and is ready to land. labels Mar 2, 2021
@ljharb ljharb force-pushed the reorder-checks-in-defineownproperty-overrides branch from d7ee6d7 to d9fea48 Compare March 3, 2021 21:13
@ljharb ljharb merged commit d9fea48 into tc39:master Mar 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editorial change ready to merge Editors believe this PR needs no further reviews, and is ready to land.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants