From ffa6138d75366687b1aa07763cf3d1f7d9961d62 Mon Sep 17 00:00:00 2001 From: Mike Stay Date: Wed, 2 Oct 2013 12:38:25 -0600 Subject: [PATCH] Make getGlobal() work in strict mode An update of https://github.com/metaweta/jasmine/commit/fb3e1acb09b4dbb9ccdbc15ce64b4a0e471f4541 ES5 strict mode does not promote an undefined 'this' to the global object. The only way to get the global object in strict mode is to say 'this' while in the global scope. --- src/core/base.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/core/base.js b/src/core/base.js index d36326b3..ca475099 100644 --- a/src/core/base.js +++ b/src/core/base.js @@ -1,3 +1,4 @@ +getJasmineRequireObj().global = this; getJasmineRequireObj().base = function(j$) { j$.unimplementedMethod_ = function() { throw new Error("unimplemented method"); @@ -6,13 +7,11 @@ getJasmineRequireObj().base = function(j$) { j$.MAX_PRETTY_PRINT_DEPTH = 40; j$.DEFAULT_TIMEOUT_INTERVAL = 5000; - j$.getGlobal = function() { - function getGlobal() { - return this; - } - - return getGlobal(); - }; + j$.getGlobal = (function(global) { + return function() { + return global; + }; + })(this.global); // Here, this === getJasmineRequireObj() j$.getEnv = function(options) { var env = j$.currentEnv_ = j$.currentEnv_ || new j$.Env(options);