davidbau / seedrandom

seeded random number generator for Javascript
2.04k stars 160 forks source link

Update global detection to work with strict mode builds. #46

Closed jared-stilwell closed 7 years ago

jared-stilwell commented 7 years ago

The logic for grabbing the global object causes issues when seedrandom.js is included in minified browser payloads that explicitly use strict mode globally. Update this technique to use the function constructor which does not inherit its strictness from the caller.

coveralls commented 7 years ago

Coverage Status

Coverage remained the same at 94.684% when pulling 2e9d0b5719d05e304f04317bc2272286aeda84ab on jared-stilwell:strict-mode-global into 616a9504fe360d63515c4a051d6d2f3089004329 on davidbau:released.

davidbau commented 7 years ago

Does this idiom work? (http://stackoverflow.com/a/14387057/265298)

var global = (0, eval)('this');

If it does work, let's use it (with a comment+link to that SO note), since it's slightly more succinct.

jared-stilwell commented 7 years ago

Did some anecdotal browser testing around the approach you suggested. Seems to work just as well. I'll update the PR.

For reference:

coveralls commented 7 years ago

Coverage Status

Coverage remained the same at 94.684% when pulling f82020a5c648bc012f3db9f44339f4adff675346 on jared-stilwell:strict-mode-global into 616a9504fe360d63515c4a051d6d2f3089004329 on davidbau:released.

coveralls commented 7 years ago

Coverage Status

Coverage remained the same at 94.684% when pulling 0ca9b788dcb398ea55176437ecc24f01cabcfd24 on jared-stilwell:strict-mode-global into 616a9504fe360d63515c4a051d6d2f3089004329 on davidbau:released.

coveralls commented 7 years ago

Coverage Status

Coverage remained the same at 94.684% when pulling 0ca9b788dcb398ea55176437ecc24f01cabcfd24 on jared-stilwell:strict-mode-global into 616a9504fe360d63515c4a051d6d2f3089004329 on davidbau:released.

coveralls commented 7 years ago

Coverage Status

Coverage remained the same at 94.684% when pulling 0ca9b788dcb398ea55176437ecc24f01cabcfd24 on jared-stilwell:strict-mode-global into 616a9504fe360d63515c4a051d6d2f3089004329 on davidbau:released.

coveralls commented 7 years ago

Coverage Status

Coverage remained the same at 94.684% when pulling 0ca9b788dcb398ea55176437ecc24f01cabcfd24 on jared-stilwell:strict-mode-global into 616a9504fe360d63515c4a051d6d2f3089004329 on davidbau:released.

coveralls commented 7 years ago

Coverage Status

Coverage remained the same at 94.684% when pulling 0ca9b788dcb398ea55176437ecc24f01cabcfd24 on jared-stilwell:strict-mode-global into 616a9504fe360d63515c4a051d6d2f3089004329 on davidbau:released.

jared-stilwell commented 7 years ago

Apologies for the coverage spam. Took several laps to get the git history cleaned up.

I glanced through the README and didn't see anything about which branch PRs should be made against, however it is entirely likely I missed something. Should I edit this PR to target the master branch instead of the released branch?

coveralls commented 7 years ago

Coverage Status

Coverage remained the same at 94.684% when pulling 4615901a32b51d4627823e29a807ad8328d9cf48 on jared-stilwell:strict-mode-global into 616a9504fe360d63515c4a051d6d2f3089004329 on davidbau:released.