Description
From @michaelficarra on October 6, 2015 23:38
At times, it is necessary to obtain a reference to the global object. In different environments, this object has non-standard, writable self-references: global
in node, window
in certain browser contexts, self
in other browser contexts, etc. It is not a good practice to rely upon these references. For this reason, a particular pattern using the Function
constructor is the only reliable method (of which I'm aware) for obtaining a reference to the global object in any context (strict/sloppy mode, module/script).
var honestToGodGlobalObject = Function("return this")();
Because this is a use of the Function
constructor, CSP does not allow this pattern without adding 'unsafe-eval'
to my policy. How can we make an exception to allow this pattern or something equivalent?
Copied from original issue: w3c/webappsec#501