tc39 / proposal-global

ECMAScript Proposal, specs, and reference implementation for `global`
http://tc39.github.io/proposal-global/
MIT License
349 stars 18 forks source link

System.environment #5

Closed petamoriken closed 8 years ago

petamoriken commented 8 years ago

Although I might not it should make the issue here, I want to hear this. I suggest that System.environment should return environment string.

i.e. in Browser: System.environment === "Browser" in WebWorker: System.environment === "Worker" in Node: System.environment === "Node"

Actually we must write below:

if(typeof window === "object") {
  // Browser
} else if(typeof importScripts === "function") {
  // WebWorker
} else if(typeof process === "object") {
  // Node
}
ljharb commented 8 years ago

What would node-webkit/electron return, which is both "node" and "browser"? What would an engine that is none of these three return, like jsc or Adobe Photoshop?

Describing the environment would be virtually impossible to specify reliably, would be dangerous to provide underspecified, and is not related to this proposal.