polyfill-service icon indicating copy to clipboard operation
polyfill-service copied to clipboard

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

Open 0x1af2aec8f957 opened this issue 2 years ago • 4 comments

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.

0x1af2aec8f957 avatar Aug 08 '23 07:08 0x1af2aec8f957

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

JakeChampion avatar Aug 08 '23 11:08 JakeChampion

@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.

0x1af2aec8f957 avatar Aug 08 '23 14:08 0x1af2aec8f957

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

JakeChampion avatar Aug 08 '23 15:08 JakeChampion

@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.

0x1af2aec8f957 avatar Aug 08 '23 17:08 0x1af2aec8f957