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

Fix descriptors copy #22

Merged
merged 1 commit into from
Jul 24, 2022
Merged

Fix descriptors copy #22

merged 1 commit into from
Jul 24, 2022

Conversation

ehmicky
Copy link
Contributor

@ehmicky ehmicky commented Jul 24, 2022

Fixes #20.

This ensures descriptors properties (writable, configurable, get, set) are kept when copying.
Note: we ignore non-enumerable properties, so enumerable is always true.

This is a bug fix. However, this could arguably be a breaking change for some consumers relying on the current (incorrect) behavior.

Verified

This commit was signed with the committer’s verified signature.
Byron Sebastian Thiel
configurable: true,
});
const descriptor = Object.getOwnPropertyDescriptor(object, key);
Object.defineProperty(result, key, descriptor);
}
}
} else {
// `for ... of Object.keys()` is faster than `for ... of Object.entries()`.
for (const key of Object.keys(object)) {
const value = object[key];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: value and descriptor are retrieved separately, since descriptor.value !== value when descriptor.get is present.

@sindresorhus sindresorhus merged commit de9a937 into sindresorhus:main Jul 24, 2022
@ehmicky ehmicky deleted the descriptor branch July 25, 2022 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

This changes whether a property is writable or configurable
2 participants