Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Fix CSP issue while obtaining ref to global #353

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/visitors/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const VARS = {
asset.addDependency('process');
return 'var process = require("process");';
},
global: () => 'var global = (1,eval)("this");',
global: () => 'var global = typeof global === "object" ? global : typeof window === "object" ? window :typeof self === "object" ? self : this;',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other implementations seem to default to {} instead of this. Trade-offs / concerns with either approach?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In global context this always refers to the global object. As we check before with typeof global === "object" whether the global object exists, it might be a better solution to use {}. I don't feel expert enough to give a definitive answer though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A cosmetic nitpick: there's a space missing in :typeof.

__dirname: asset =>
`var __dirname = ${JSON.stringify(Path.dirname(asset.name))};`,
__filename: asset => `var __filename = ${JSON.stringify(asset.name)};`,
Expand Down