Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Make getGlobal() work in strict mode #317

Closed
wants to merge 1 commit into from

2 participants

@metaweta

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.

@metaweta metaweta Make getGlobal() work in strict mode
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.
fb3e1ac
@slackersoft
Owner

Hey, this looks useful but base.js has changed quite a bit for 2.0. getGlobal is now defined from within a function on the getJasmineRequireObj() so the assignment that you have here isn't going to work anymore.

If you want to take a look at the current state of base.js and either update this pull request or send in a new one that will work with the new code, we'll take a look

@metaweta

New pull request at #437

@slackersoft
Owner

Cool, we'll take a look. Closing this one

@slackersoft slackersoft closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 16, 2013
  1. @metaweta

    Make getGlobal() work in strict mode

    metaweta authored
    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.
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 5 deletions.
  1. +6 −5 src/core/base.js
View
11 src/core/base.js
@@ -51,12 +51,13 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
*/
jasmine.CATCH_EXCEPTIONS = true;
+/**
+ * ECMAScript 5 strict mode doesn't promote undefined to the global object,
+ * so if you want to run jasmine in strict mode, this is the only way to
+ * get the global obje
+jasmine.global = this;
jasmine.getGlobal = function() {
- function getGlobal() {
- return this;
- }
-
- return getGlobal();
+ return jasmine.global;
};
/**
Something went wrong with that request. Please try again.