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

Suggest adding non-enumerable properties support when implementing Object.assign under IE8 #541

Closed
aleen42 opened this issue May 7, 2019 · 15 comments
Labels

Comments

@aleen42
Copy link
Contributor

aleen42 commented May 7, 2019

Under IE8, there are some non-enumerable properties like toString, which is actually not standard. However, the shim for Object.assign has not solved the problem for us, like what described here, and I hope the source shim can do this for us.

@aleen42
Copy link
Contributor Author

aleen42 commented May 7, 2019

The solved code snippet is shown as followed:

let fn = Object.assign;
Object.assign = function () {
    const [target, ...sources] = [].slice.call(arguments, 0);
    const result = fn.apply(this, [target, ...sources]);

    [
        'valueOf',
        'isPrototypeOf',
        'toString',
        'hasOwnProperty',
        'toLocaleString',
        'propertyIsEnumerable',
    ].forEach(property => {
        if (property === 'propertyIsEnumerable'
            || !({[property] : null}).propertyIsEnumerable(property)) {
            /** non-enumerable properties */
            sources.forEach(source => source
                                      && source.hasOwnProperty(property)
                                      && (result[property] = source[property]));
        }
    });

    return result;
};

@aleen42 aleen42 changed the title Suggest adding non-enumerable properties support when implementing Object.assign Suggest adding non-enumerable properties support when implementing Object.assign under IE8 May 7, 2019
@zloirock
Copy link
Owner

zloirock commented May 7, 2019

A workaround like this should be already used in enumerable keys related core-js features.

@aleen42
Copy link
Contributor Author

aleen42 commented May 7, 2019

Has that feature been already released?

@zloirock
Copy link
Owner

zloirock commented May 7, 2019

Yes. I'll test it a little later.

@aleen42
Copy link
Contributor Author

aleen42 commented May 7, 2019

Thanks for your responses.

@zloirock
Copy link
Owner

zloirock commented May 7, 2019

Looks like a bug. Object.keys works with those keys fine, but Object.assign not. But they should use the same way of getting enumerable keys internally.

@zloirock
Copy link
Owner

zloirock commented May 7, 2019

Seems the problem in one propertyIsEnumerable extra check.

@aleen42
Copy link
Contributor Author

aleen42 commented May 7, 2019

Check it and wait for upgrading.

zloirock added a commit that referenced this issue May 10, 2019
@zloirock zloirock added the ie label May 11, 2019
zloirock added a commit that referenced this issue May 18, 2019
@aleen42
Copy link
Contributor Author

aleen42 commented May 27, 2019

@zloirock, The problem is still existed with using @3.1.2.

A simple case described here can be used as a test case.

@zloirock
Copy link
Owner

zloirock commented May 27, 2019

@aleen42 your test case passed in 3.1.2, but I can confirm that 2.6.8 still has this problem.

@zloirock
Copy link
Owner

Nope, 2.6.8 also works fine, some problems with the cache in the testing platform.

@aleen42
Copy link
Contributor Author

aleen42 commented May 28, 2019

With using 2.6.8:

image

@aleen42
Copy link
Contributor Author

aleen42 commented May 28, 2019

Are you sure you have run your test under IE8?

@zloirock
Copy link
Owner

@aleen42
image

@aleen42
Copy link
Contributor Author

aleen42 commented May 28, 2019

wired, the case I tested was where I only required the core-js/shim file rather than the client/shim under 2.6.8. It seemed client/shim was OK for me.

It is my fault where I have a sub dependencie which depends on another low version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants