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 ReflectShims.defineProperty is undefined in WSH #471

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 2 additions & 5 deletions es6-shim.js
Expand Up @@ -1264,10 +1264,7 @@
// Chrome defines keys/values/entries on Array, but doesn't give us
// any way to identify its iterator. So add our own shimmed field.
if (Object.getPrototypeOf) {
var ChromeArrayIterator = Object.getPrototypeOf([].values());
if (ChromeArrayIterator) { // in WSH, this is `undefined`
addIterator(ChromeArrayIterator);
}
gnh1201 marked this conversation as resolved.
Show resolved Hide resolved
addIterator(Object.getPrototypeOf([].values());
}

// note: this is positioned here because it relies on Array#entries
Expand Down Expand Up @@ -3585,7 +3582,7 @@
});
}

if (supportsDescriptors) {
if (!ReflectShims.defineProperty) { // possible alternative: if (supportsDescriptors)
Comment on lines -3588 to +3585
Copy link
Collaborator

Choose a reason for hiding this comment

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

supportsDescriptors is only true when get/set are available - but ReflectShims.defineProperty might be available in the same way Object.defineProperty might be - working fine for enumerable/configurable/writable data properties, but throwing for everything else. What does this fix?

Copy link
Contributor Author

@gnh1201 gnh1201 Jul 29, 2021

Choose a reason for hiding this comment

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

This change is a key point to solve #466 and other overrideNative related crash issues.

In WSH(polyfilled by core-js), supportsDescriptors(es6-shim) is false bacause of if(!supportsAccessors && (hasGetter || hasSetter))(es5-shim) is true.

Because of this, replacement parameter is undefined when calling overrideNative. This causes the wrong override.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This part should be run regardless of the values in supportsDescriptors.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm still a bit unclear on your explanation.

If you're in WSH, polyfilled by core-js, why are you running es5-shim and es6-shim at all? You're supposed to use core-js OR es-shims, not both.

var internalGet = function get(target, key, receiver) {
var desc = Object.getOwnPropertyDescriptor(target, key);

Expand Down