kernel-checks.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 (function () {
  30. return this;
  31. }).apply(void 0) === void 0;
  32. });
  33. assert(function () {
  34. return (function () {
  35. return this;
  36. }).apply(null) === null;
  37. });
  38. assert(function () {
  39. return (function () {
  40. return this;
  41. }).apply(3) === 3;
  42. });
  43. assert(function () {
  44. return (function () {
  45. return this;
  46. }).apply("foo") === "foo";
  47. });
  48. assert(function () {
  49. return (function () {
  50. return this;
  51. }).apply(true) === true;
  52. });
  53. assert(function () {
  54. var o = Object.freeze({});
  55. try {
  56. o.foo = "bar";
  57. } catch (ex) {
  58. }
  59. return o.foo == null;
  60. });
  61. assert(function () {
  62. return typeof Promise === "function";
  63. });
  64. assert(function () {
  65. return typeof Promise.resolve === "function";
  66. });
  67. assert(function () {
  68. return typeof Promise.reject === "function";
  69. });
  70. assert(function () {
  71. return typeof new Promise(function () {
  72. }).then === "function";
  73. });
  74. });