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

Is there an error in the judgment criteria in Object.defineProperty? #2764

Open
0x1af2aec8f957 opened this issue Aug 8, 2023 · 4 comments
Open

Comments

@0x1af2aec8f957
Copy link

The request link I am using: https://polyfill.io/v3/polyfill.js?flags=always

Errors during use:

image

This method is not used in my code, it may be used by other third-party libraries. But it can work normally in modern browsers without introducing polyfill.

@JakeChampion
Copy link
Collaborator

We do not recommend using only flags=always - it will cause issues. If wanting to always serve polyfills, we highly recommend using it in combination with gated like so, flags=always,gated, that way we will only apply a polyfill if the feature was not already present in the browser

@0x1af2aec8f957
Copy link
Author

@JakeChampion Thank you for your suggestion. I actually used only the method I needed to fill in, but in any case, the code I marked in the figure is incorrect.

@JakeChampion
Copy link
Collaborator

Could you please explain what is incorrect, it looks correct to me

@0x1af2aec8f957
Copy link
Author

0x1af2aec8f957 commented Aug 8, 2023

@JakeChampion

// https://polyfill.io/v3/polyfill.js?flags=always
...
var getterType = 'get' in descriptor && typeof descriptor.get; // getterType can never be undefined
var setterType = 'set' in descriptor && typeof descriptor.set; // setterType can never be undefined

if (getterType) { // This judgment means that the following judgment should not have undefined
    if (getterType === undefined) { // getterType can never be undefined, but it may be "undefined"
        return object;
    }
    ...
}

if (setterType) {
    if (setterType === undefined) {
        return object;
    }
    ...
}

In the image of my original question, the comments I added in the above code are well explained.
Perhaps I misunderstood the above code judgment? But it was indeed executed like this.
It should be noted that the undefined here is actually two different things: one is the data type, and the other is the string.

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

No branches or pull requests

2 participants