1
0

kernel-checks.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. // return new Function("return this")().Object === Object;
  24. // });
  25. // assert(function () {
  26. // return Object.create(new Function("return this")()).Object === Object;
  27. // });
  28. assert(function () {
  29. return typeof global !== "undefined";
  30. });
  31. assert(function () {
  32. return global.Object === Object;
  33. });
  34. assert(function () {
  35. return Object.create(global).Object === Object;
  36. });
  37. assert(function () {
  38. return (function () {
  39. return this;
  40. }).apply(void 0) === void 0;
  41. });
  42. assert(function () {
  43. return (function () {
  44. return this;
  45. }).apply(null) === null;
  46. });
  47. assert(function () {
  48. return (function () {
  49. return this;
  50. }).apply(3) === 3;
  51. });
  52. assert(function () {
  53. return (function () {
  54. return this;
  55. }).apply("foo") === "foo";
  56. });
  57. assert(function () {
  58. return (function () {
  59. return this;
  60. }).apply(true) === true;
  61. });
  62. assert(function () {
  63. var o = Object.freeze({});
  64. try {
  65. o.foo = "bar";
  66. } catch (ex) {
  67. }
  68. return o.foo == null;
  69. });
  70. assert(function () {
  71. return typeof Promise === "function";
  72. });
  73. assert(function () {
  74. return typeof Promise.resolve === "function";
  75. });
  76. assert(function () {
  77. return typeof Promise.reject === "function";
  78. });
  79. assert(function () {
  80. return typeof new Promise(function () {
  81. }).then === "function";
  82. });
  83. });