-
Notifications
You must be signed in to change notification settings - Fork 346
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] hooks: useSubEnv and useChildSubEnv should apply on prototype chain #1447
base: master
Are you sure you want to change the base?
[FIX] hooks: useSubEnv and useChildSubEnv should apply on prototype chain #1447
Conversation
…hain Before this commit: When using useSubEnv or useChildSubEnv, only owned properties of the extensions are assigned to the new env. After this commit: Properties from the whole prototype chain of the extension are assigned to the env.
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.
Curious about the reason behind this change. It doesn't seem obvious to me that it should behave this way. The caller can flatten the object before calling use(Child)SubEnv if needed. This seems to encourage patterns that would lead to confusing behaviour, eg useSubEnv(new SomeClass())
where the env will have all the properties and methods of SomeClass but will not be instanceof SomeClass
and if the prototype of SomeClass
is modified/patched the sub-env will not reflect the changes to the prototype.
for (const key in descrs) { | ||
descrs[key].configurable = 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.
This doesn't seem to do anything?
while (extension !== Object.prototype) { | ||
const descrs = Object.getOwnPropertyDescriptors(extension); | ||
Object.defineProperties(env, descrs); |
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.
Oh and because we're doing this while climbing the prototype chain, properties on the prototype will shadow properties on the object instead of the other way around which is undesirable in any case.
Not easy to do in some cases. Here, we are in a situation where we want to do |
Doing |
Before this commit:
When using useSubEnv or useChildSubEnv, only owned properties of the extensions are assigned to the new env.
After this commit:
Properties from the whole prototype chain of the extension are assigned to the env.