create.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Workaround for http://code.google.com/p/v8/issues/detail?id=2804
  2. "use strict";
  3. var create = Object.create, shim;
  4. if (!require("./set-prototype-of/is-implemented")()) {
  5. shim = require("./set-prototype-of/shim");
  6. }
  7. module.exports = (function () {
  8. var nullObject, polyProps, desc;
  9. if (!shim) return create;
  10. if (shim.level !== 1) return create;
  11. nullObject = {};
  12. polyProps = {};
  13. desc = {
  14. configurable: false,
  15. enumerable: false,
  16. writable: true,
  17. value: undefined
  18. };
  19. Object.getOwnPropertyNames(Object.prototype).forEach(function (name) {
  20. if (name === "__proto__") {
  21. polyProps[name] = {
  22. configurable: true,
  23. enumerable: false,
  24. writable: true,
  25. value: undefined
  26. };
  27. return;
  28. }
  29. polyProps[name] = desc;
  30. });
  31. Object.defineProperties(nullObject, polyProps);
  32. Object.defineProperty(shim, "nullPolyfill", {
  33. configurable: false,
  34. enumerable: false,
  35. writable: false,
  36. value: nullObject
  37. });
  38. return function (prototype, props) {
  39. return create(prototype === null ? nullObject : prototype, props);
  40. };
  41. }());