Skip to content
This repository was archived by the owner on Feb 1, 2025. It is now read-only.

Commit

Permalink
Simplify references to the global object
Browse files Browse the repository at this point in the history
Take advantage of sloppy mode, aka non-strict mode, where unbound
functions are called with the global object as `this`.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode#Securing_JavaScript
  • Loading branch information
maxnordlund committed Apr 28, 2017
1 parent 74c7626 commit b87c2fa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
5 changes: 1 addition & 4 deletions packages/regenerator-runtime/runtime-module.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// This method of obtaining a reference to the global object needs to be
// kept identical to the way it is obtained in runtime.js
var g =
typeof global === "object" ? global :
typeof window === "object" ? window :
typeof self === "object" ? self : this;
var g = (function() { return this })() || Function("return this")();

// Use `getOwnPropertyNames` because not all browsers support calling
// `hasOwnProperty` on the global `self` object in a worker. See #183.
Expand Down
10 changes: 4 additions & 6 deletions packages/regenerator-runtime/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,10 +727,8 @@
}
};
})(
// Among the various tricks for obtaining a reference to the global
// object, this seems to be the most reliable technique that does not
// use indirect eval (which violates Content Security Policy).
typeof global === "object" ? global :
typeof window === "object" ? window :
typeof self === "object" ? self : this
// In sloppy mode, unbound `this` refers to the global object, fallback to
// Function constructor if we're in global strict mode. That is sadly a form
// of indirect eval which violates Content Security Policy.
(function() { return this })() || Function("return this")()
);

0 comments on commit b87c2fa

Please sign in to comment.