1
0
Kaynağa Gözat

kernel: checks for underlying platform features

Herbert Vojčík 7 yıl önce
ebeveyn
işleme
de3d26c217
2 değiştirilmiş dosya ile 51 ekleme ve 2 silme
  1. 2 2
      support/boot.js
  2. 49 0
      support/kernel-checks.js

+ 2 - 2
support/boot.js

@@ -40,8 +40,8 @@
 //jshint eqnull:true
 
 define([
-    'require', './brikz', './kernel-fundamentals', './kernel-language', './compatibility' /* TODO remove */
-], function (require, Brikz, configureWithFundamentals, configureWithHierarchy) {
+    'require', './kernel-checks', './brikz', './kernel-fundamentals', './kernel-language', './compatibility' /* TODO remove */
+], function (require, _, Brikz, configureWithFundamentals, configureWithHierarchy) {
     "use strict";
 
     require(['./kernel-runtime']); // preload

+ 49 - 0
support/kernel-checks.js

@@ -0,0 +1,49 @@
+//jshint eqnull:true
+
+define(function () {
+    "use strict";
+
+    function assert (fn) {
+        try {
+            if (fn()) return;
+        } catch (ex) {
+            throw new Error("Error:\n" + ex + "in assertion:\n" + fn);
+        }
+        throw new Error("Assertion failed:\n" + fn);
+    }
+
+    assert(function () {
+        return !("hasOwnProperty" in Object.create(null));
+    });
+    assert(function () {
+        return new Function("return this")().Object === Object;
+    });
+    assert(function () {
+        return Object.create(new Function("return this")()).Object === Object;
+    });
+    assert(function () {
+        return (function () {
+                return this;
+            }).apply(void 0) === void 0;
+    });
+    assert(function () {
+        return (function () {
+                return this;
+            }).apply(null) === null;
+    });
+    assert(function () {
+        return (function () {
+                return this;
+            }).apply(3) === 3;
+    });
+    assert(function () {
+        return (function () {
+                return this;
+            }).apply("foo") === "foo";
+    });
+    assert(function () {
+        return (function () {
+                return this;
+            }).apply(true) === true;
+    });
+});