Browse Source

Use `global` global variable.

As it is not defined in browser, polyfill it there.
Herby Vojčík 6 years ago
parent
commit
181d8d429f
3 changed files with 13 additions and 4 deletions
  1. 1 0
      internal/index.html
  2. 1 2
      support/helpers.js
  3. 11 2
      support/kernel-checks.js

+ 1 - 0
internal/index.html

@@ -21,6 +21,7 @@
     startLegacy.parentNode.removeChild(startLegacy);
     var startHelios = document.getElementById("starthelios");
     startHelios.parentNode.removeChild(startHelios);
+    var global = typeof global === "undefined" ? window : global || window;
     require(["require", "amber/es2015-polyfills"], function (require) {
         var loadHelpers = new Promise(function (resolve, reject) {
             setTimeout(function () {

+ 1 - 2
support/helpers.js

@@ -35,8 +35,7 @@ define(["amber/boot", "require"], function (boot, require) {
 
     function settingsInLocalStorage () {
         //jshint evil:true
-        var global = new Function('return this')(),
-            storage = 'localStorage' in global && global.localStorage;
+        var storage = 'localStorage' in global && global.localStorage;
 
         if (storage) {
             var fromStorage;

+ 11 - 2
support/kernel-checks.js

@@ -22,11 +22,20 @@ define(function () {
         var p = {};
         return Object.getPrototypeOf(Object.create(p)) === p;
     });
+    // assert(function () {
+    //     return new Function("return this")().Object === Object;
+    // });
+    // assert(function () {
+    //     return Object.create(new Function("return this")()).Object === Object;
+    // });
     assert(function () {
-        return new Function("return this")().Object === Object;
+        return typeof global !== "undefined";
     });
     assert(function () {
-        return Object.create(new Function("return this")()).Object === Object;
+        return global.Object === Object;
+    });
+    assert(function () {
+        return Object.create(global).Object === Object;
     });
     assert(function () {
         return (function () {