Parcourir la source

Use `global` global variable.

As it is not defined in browser, polyfill it there.
Herby Vojčík il y a 6 ans
Parent
commit
181d8d429f
3 fichiers modifiés avec 13 ajouts et 4 suppressions
  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 () {