2
0

kernel-checks.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 new Function("return this")().Object === Object;
  17. });
  18. assert(function () {
  19. return Object.create(new Function("return this")()).Object === Object;
  20. });
  21. assert(function () {
  22. return (function () {
  23. return this;
  24. }).apply(void 0) === void 0;
  25. });
  26. assert(function () {
  27. return (function () {
  28. return this;
  29. }).apply(null) === null;
  30. });
  31. assert(function () {
  32. return (function () {
  33. return this;
  34. }).apply(3) === 3;
  35. });
  36. assert(function () {
  37. return (function () {
  38. return this;
  39. }).apply("foo") === "foo";
  40. });
  41. assert(function () {
  42. return (function () {
  43. return this;
  44. }).apply(true) === true;
  45. });
  46. assert(function () {
  47. var o = Object.freeze({});
  48. try {
  49. o.foo = "bar";
  50. } catch (ex) {
  51. }
  52. return o.foo == null;
  53. });
  54. assert(function () {
  55. return typeof Promise === "function";
  56. });
  57. assert(function () {
  58. return typeof Promise.resolve === "function";
  59. });
  60. assert(function () {
  61. return typeof Promise.reject === "function";
  62. });
  63. assert(function () {
  64. return typeof new Promise(function () {
  65. }).then === "function";
  66. });
  67. });