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

Incorrect type for Set in IE #380

Closed
arshtepe opened this issue Feb 16, 2018 · 13 comments
Closed

Incorrect type for Set in IE #380

arshtepe opened this issue Feb 16, 2018 · 13 comments

Comments

@arshtepe
Copy link

export function getObjectType(obj) {
    return ({}).toString.call(obj)
};

getObjectType(new Set())
In normal browser result [object Set] , but in IE 11 [object Object]

@zloirock
Copy link
Owner

zloirock commented Feb 16, 2018

How do you use core-js? In some cases, it's expected behaviour.

@zloirock
Copy link
Owner

You will have [object Set] only with correct / polyfilled Object#toString with Symbol.toStringTag support. It's impossible in the version without global namespace pollution. In the global version, if you load only some parts of core-js, should be loaded Object#toString polyfill, not just Set.

@arshtepe
Copy link
Author

@zloirock I use core-js by babel-runtime@6.23.0 . I need serialize Set to object like

{
 type: getObjectType(obj),
 value: [...set]
}

and for deserialize for Set i need type.

@zloirock
Copy link
Owner

As I wrote, it's impossible in this case. If you need @@toStringTag support in Object#toString, you should use the global version. Duplicate of #199.

@zloirock
Copy link
Owner

zloirock commented Feb 16, 2018

As an option, you can try return Object(obj)[Symbol.toStringTag] || ({}).toString.call(obj).

@arshtepe
Copy link
Author

@zloirock I have checked. I have include $.set-to-string-tag

@zloirock
Copy link
Owner

zloirock commented Feb 16, 2018

One more time: for adding support @@toStringTag to Object#toString, we should monkey-patch Object#toString. It's impossible without global namespace pollution. $.set-to-string-tag (btw, which version of core-js you use? This filename convention was changed IIRC 2 years ago) adds @@toStringTag to collections prototype, so you can use a fallback as I proposed above, but does not patch Object#toString.

@arshtepe
Copy link
Author

@zloirock I have 2 files, first it is polyfill for IE and looks like

require("core-js/es7/string");
require("core-js/es6/array");
require("core-js/es6/string");
require("core-js/es7/array");
require("core-js/modules/es6.object.assign");
require("core-js/modules/$.set-to-string-tag");
window.Promise = require("core-js/library/fn/promise");// for webpack

second it is application which build by webpack + babel. Is it may be reason why it doesn't work ?

@zloirock
Copy link
Owner

zloirock commented Feb 16, 2018

Because missed core-js/fn/symbol/to-string-tag or core-js/es6/object.

@arshtepe
Copy link
Author

@zloirock in application file, I have
__webpack_require__(/*! ../modules/es6.object.to-string */ "./node_modules/babel-runtime/node_modules/core-js/library/modules/es6.object.to-string.js")

@zloirock
Copy link
Owner

core-js/library/modules/es6.object.to-string is an empty cap for non-global version. Should be core-js/modules/es6.object.to-string.

@zloirock
Copy link
Owner

BTW, please, never use core-js(/library)/modules/* if you don't completely understand how it works.

@arshtepe
Copy link
Author

@zloirock Thank you. It works.

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

No branches or pull requests

2 participants