wintercg / proposal-common-minimum-api

https://common-min-api.proposal.wintercg.org/
Other
227 stars 13 forks source link

Are you sure that `self` is web compatible and that adding it to some environments will not break anything? #28

Closed zloirock closed 1 year ago

zloirock commented 2 years ago

For example, I'm worried about NodeJS - in some cases, someone detects the environment as NodeJS like typeof self === 'undefined' && typeof process === 'object'.

Related: https://github.com/zloirock/core-js/pull/1118

ljharb commented 2 years ago

It's definitely not; we explored this in the globalThis proposal.

zloirock commented 2 years ago

@ljharb could you provide the results of this research? For example, here you provide only some links to global and window.

ljharb commented 2 years ago

https://github.com/tc39/proposal-global/issues/11#issuecomment-220802575

There's a number of examples of window and self both implying a browser, such as https://github.com/Microsoft/automatic-graph-layout/blob/ab371280000f4d85eeedc1899e6faaa66ccad009/GraphLayout/MsaglSharpkit/WebMsagl/Msagl/sharpkit_pre.js . In addition, var self = this is too common a pattern for self to be a safe bet.

zloirock commented 2 years ago

And here is no self in examples.

ljharb commented 2 years ago

"such as" - that was one example. I recall seeing hundreds of them with a trivial github search; you're welcome to do the same.

zloirock commented 2 years ago

Just searching something on GitHub - is not proper research. I hope that it was not your motivation at the time of this proposal? After exploring some examples of such code, I found that they are used only on tests or not used at all. However, sure, with a big chance somewhere it's used in some code where it can break something.

ljharb commented 2 years ago

If you're aware of another way to do research that isn't fantastically expensive, I'd love to know about it.

zloirock commented 2 years ago

I'm awaiting at least some real examples of what it can break. At least some links to GitHub with an explanation. Otherwise, it's just empty words, not "research". I don't think that it's fantastically expensive. I found some tenths of such cases on GitHub for some minutes - but I don't see the danger in any one of them - however, sure, it's not exhaustively - otherwise, this issue wouldn't be here in this form.

zloirock commented 2 years ago

However, for NodeJS it's not principal since they can implement it in a new major release - it's not browsers and breaking changes are possible.

zloirock commented 2 years ago

@jasnell @lucacasonato

zloirock commented 1 year ago

The final attempt to get feedback, @jasnell @lucacasonato.

jasnell commented 1 year ago

We've removed self