global object in strict mode

John J Barton johnjbarton at johnjbarton.com
Thu Aug 23 18:57:07 PDT 2012


Thanks!

 I guess I should ended my question this way: ...and because
developers want to write code that works in browsers and not, perhaps
ES can have a solution that is not as silly as the ones we are using
now.

jjb

On Thu, Aug 23, 2012 at 6:41 PM, Andrea Giammarchi
<andrea.giammarchi at gmail.com> wrote:
> the non eval solution for ES3 is
>
> var global = function(){return this}();
>
> and not with eval ...
>
> In ES5 usually window is not writable/configurable but enumerable so
> theoretically you can rely in the `window` object unless your code is not
> evaluated through eval inside a function with a window variable redefined.
>
> On Thu, Aug 23, 2012 at 11:59 PM, John J Barton
> <johnjbarton at johnjbarton.com> wrote:
>>
>> Long ago this list had a subject:
>>
>> How to retrieve the global object in strict mode?
>> https://mail.mozilla.org/pipermail/es5-discuss/2011-February/003919.html
>>
>> Roughly the conclusion was:
>>
>>   var global = ("global", eval)("this");
>>
>> However Content Security Policy
>>
>>
>> https://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html
>>
>> bans 'eval', (as well as all similar forms) making this solution fail.
>>
>> Is there a non-eval based solution?
>>
>> jjb
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>
>


More information about the es-discuss mailing list