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

toString function is override, toString(undefined) return [object Window], not as expect #30

Closed
missjing opened this issue Jul 24, 2018 · 2 comments
Labels
bug Something isn't working help wanted We'd appreciate some help with this

Comments

@missjing
Copy link

a few months ago, we use the polyfill service to generate a resource for Map&Set: https://cdn.polyfill.io/v2/polyfill.js?features=Map,Set&flags=always,gated. In order to solve the 'Map/Set is not defined' problems on old browsers, like Android 4.4

but, recently, we met a new problem, something not act as expect
in ios 8.1, we found the 'toString' function act different as other new ios versions
when we loaded the polyfill resource above, we found the toString was override
https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Symbol/polyfill.js#L215

image

toString(undefined) return [object Window], not [object undefined], this result caused other problem in our project, so we wish u can solve this problem.

finally, simulate the problem code line
image

@JakeChampion JakeChampion transferred this issue from polyfillpolyfill/polyfill-service Jan 23, 2019
@JakeChampion JakeChampion added bug Something isn't working help wanted We'd appreciate some help with this labels Apr 3, 2019
@JakeChampion
Copy link
Owner

I think this would be solved by making the function run in strict mode because in strict mode an undefined context/this does not get changed to the global object.

We would change:
https://github.com/Financial-Times/polyfill-library/blob/master/polyfills/Symbol/polyfill.js#L215-L218

to this:

descriptor.value = function () {
	'use strict';
	var str = toString.call(this);
	return (str === '[object String]' && onlySymbols(this)) ? '[object Symbol]' : str;
};

@JakeChampion
Copy link
Owner

This was fixed in #193

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working help wanted We'd appreciate some help with this
Projects
None yet
Development

No branches or pull requests

2 participants