create.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 = { configurable: false, enumerable: false, writable: true, value: undefined };
  14. Object.getOwnPropertyNames(Object.prototype).forEach(function (name) {
  15. if (name === "__proto__") {
  16. polyProps[name] = {
  17. configurable: true,
  18. enumerable: false,
  19. writable: true,
  20. value: undefined
  21. };
  22. return;
  23. }
  24. polyProps[name] = desc;
  25. });
  26. Object.defineProperties(nullObject, polyProps);
  27. Object.defineProperty(shim, "nullPolyfill", {
  28. configurable: false,
  29. enumerable: false,
  30. writable: false,
  31. value: nullObject
  32. });
  33. return function (prototype, props) {
  34. return create(prototype === null ? nullObject : prototype, props);
  35. };
  36. })();