google / traceur-compiler

Traceur is a JavaScript.next-to-JavaScript-of-today compiler
Apache License 2.0
8.17k stars 580 forks source link

Use universal method of finding the global object #2132

Closed cyco closed 8 years ago

cyco commented 8 years ago

The module store, runtime and symbol polyfills need access to the global object. This was done by checking the existance of window, global, self and falling back to this if none were defined. This can fail for two reasons. First, this should be expected to be set to undefined during module definitions (as is the case for symbols.js), thus rendering the fallback useless. Secondly some JavaScript implementations (e.g. JavaScript-Core Framework) might not even define a name for the global object that could be accessed within modules. By using the Function-Constructor we create a new function in non-strict mode which has its thisArg set to the gobal object if no other thisArg is provided.

googlebot commented 8 years ago

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


cyco commented 8 years ago

I signed it!

googlebot commented 8 years ago

CLAs look good, thanks!

arv commented 8 years ago

Thank you for the patch.

One issue with this approach is that it does not work when eval is disabled (which is the case of CSP). So it needs to be wrapped in a try/catch with a fallback to the current ugly behavior.

cyco commented 8 years ago

Thanks for your feedback. I'll add the change you suggested and update the PR.

arv commented 8 years ago

I like it 👍

Can you also add an entry to AUTHORS?

cyco commented 8 years ago

Done :)

arv commented 8 years ago

Can you fix the merge conflict? Thanks.

cyco commented 8 years ago

The conflict should be resolved now.