1
0

create.js 1004 B

123456789101112131415161718192021222324252627282930313233343536
  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, props, desc;
  9. if (!shim) return create;
  10. if (shim.level !== 1) return create;
  11. nullObject = {};
  12. props = {};
  13. desc = { configurable: false, enumerable: false, writable: true,
  14. value: undefined };
  15. Object.getOwnPropertyNames(Object.prototype).forEach(function (name) {
  16. if (name === '__proto__') {
  17. props[name] = { configurable: true, enumerable: false, writable: true,
  18. value: undefined };
  19. return;
  20. }
  21. props[name] = desc;
  22. });
  23. Object.defineProperties(nullObject, props);
  24. Object.defineProperty(shim, 'nullPolyfill', { configurable: false,
  25. enumerable: false, writable: false, value: nullObject });
  26. return function (prototype, props) {
  27. return create((prototype === null) ? nullObject : prototype, props);
  28. };
  29. }());