davidbau / seedrandom

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

Avoid using eval() to get global object. #65

Closed louh closed 4 years ago

louh commented 5 years ago

Following up from #64, this PR avoids using eval() to get the global object, which causes this package to be unusable if a server has set Content-Security Policy (CSP) protocols. I use the Universal Module Definition (UMD) pattern, bringing back the way we inject the global object into the function via its arguments.

I should also note that there is a stage-3 ECMAScript proposal for globalThis, which is meant to address exactly this problem. Some browsers and environments have begun to implement globalThis but even if we were to use it now, we would still need a fallback to self or this. Let me know if you would like to use globalThis now, but I can also understand waiting for the proposal to be finalized first.

Let me know if there's anything else I should do to finish this PR! Thanks!

coveralls commented 5 years ago

Coverage Status

Coverage decreased (-0.01%) to 94.444% when pulling 48437ba9ed984821f1a978bc284e79d313f89cb5 on louh:louh/global into d5ebbe4c88e446a116f128af088a24c6a82f7f77 on davidbau:released.

coveralls commented 5 years ago

Coverage Status

Coverage decreased (-0.01%) to 94.444% when pulling 48437ba9ed984821f1a978bc284e79d313f89cb5 on louh:louh/global into d5ebbe4c88e446a116f128af088a24c6a82f7f77 on davidbau:released.

DiskImage commented 4 years ago

@davidbau any plans to merge this in soon? I'm also on a project that needs this eval removed for CSP reasons and it would be great to not have to maintain a fork in parallel to this!

davidbau commented 4 years ago

Look great. Thanks for the PR!

yuntonyx commented 4 years ago

Amazing, thank you @louh and @davidbau !