herumi / mcl-wasm

59 stars 18 forks source link

Better detection of node/browser #15

Closed evertonfraga closed 4 years ago

evertonfraga commented 4 years ago

At https://github.com/ethereumjs/ethereumjs-vm/pull/785#issuecomment-670268717, we found that exports shouldn't guide the browser/node detection. It is usually present in browser builds made with Browserify, invalidating that clause.

While as ridiculous as it sounds, there isn't a certain way to know the platform for sure, but I propose at least this better heuristic, using window instead. The likelihood of a Node project to have a window global variable seems to be super low.

Additional ways to detect platforms involve: self and global.

More on this: https://v8.dev/features/globalthis.

herumi commented 4 years ago

Thanks for the useful patch.

jochem-brouwer commented 4 years ago

Thanks for merging this @herumi. Could you also bump the package version? 😄

herumi commented 4 years ago

I've updated it.

evertonfraga commented 4 years ago

Thanks!