kernel-checks.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //jshint eqnull:true
  2. define(function () {
  3. "use strict";
  4. function assert (fn) {
  5. try {
  6. if (fn()) return;
  7. } catch (ex) {
  8. throw new Error("Error:\n" + ex + "in assertion:\n" + fn);
  9. }
  10. throw new Error("Assertion failed:\n" + fn);
  11. }
  12. assert(function () {
  13. return !("hasOwnProperty" in Object.create(null));
  14. });
  15. assert(function () {
  16. return Object.getPrototypeOf(Object.create(null)) === null;
  17. });
  18. assert(function () {
  19. var p = {};
  20. return Object.getPrototypeOf(Object.create(p)) === p;
  21. });
  22. assert(function () {
  23. var p = {x: 4, y: 5}, q = {x: 6};
  24. var r = Object.setPrototypeOf(q, p);
  25. return r === q &&
  26. q.x === 6 &&
  27. q.y === 5;
  28. });
  29. // assert(function () {
  30. // return new Function("return this")().Object === Object;
  31. // });
  32. // assert(function () {
  33. // return Object.create(new Function("return this")()).Object === Object;
  34. // });
  35. assert(function () {
  36. return typeof globalThis !== "undefined";
  37. });
  38. assert(function () {
  39. return globalThis.Object === Object;
  40. });
  41. assert(function () {
  42. return Object.create(globalThis).Object === Object;
  43. });
  44. assert(function () {
  45. return (function () {
  46. return this;
  47. }).apply(void 0) === void 0;
  48. });
  49. assert(function () {
  50. return (function () {
  51. return this;
  52. }).apply(null) === null;
  53. });
  54. assert(function () {
  55. return (function () {
  56. return this;
  57. }).apply(3) === 3;
  58. });
  59. assert(function () {
  60. return (function () {
  61. return this;
  62. }).apply("foo") === "foo";
  63. });
  64. assert(function () {
  65. return (function () {
  66. return this;
  67. }).apply(true) === true;
  68. });
  69. assert(function () {
  70. var o = Object.freeze({});
  71. try {
  72. o.foo = "bar";
  73. } catch (ex) {
  74. }
  75. return o.foo == null;
  76. });
  77. assert(function () {
  78. return typeof Promise === "function";
  79. });
  80. assert(function () {
  81. return typeof Promise.resolve === "function";
  82. });
  83. assert(function () {
  84. return typeof Promise.reject === "function";
  85. });
  86. assert(function () {
  87. return typeof new Promise(function () {
  88. }).then === "function";
  89. });
  90. });