You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ObjectCreate.js 1.0KB

12345678910111213141516171819202122232425262728293031323334353637
  1. 'use strict';
  2. var GetIntrinsic = require('../GetIntrinsic');
  3. var $ObjectCreate = GetIntrinsic('%Object.create%', true);
  4. var $TypeError = GetIntrinsic('%TypeError%');
  5. var $SyntaxError = GetIntrinsic('%SyntaxError%');
  6. var Type = require('./Type');
  7. var hasProto = !({ __proto__: null } instanceof Object);
  8. // https://www.ecma-international.org/ecma-262/6.0/#sec-objectcreate
  9. module.exports = function ObjectCreate(proto, internalSlotsList) {
  10. if (proto !== null && Type(proto) !== 'Object') {
  11. throw new $TypeError('Assertion failed: `proto` must be null or an object');
  12. }
  13. var slots = arguments.length < 2 ? [] : internalSlotsList;
  14. if (slots.length > 0) {
  15. throw new $SyntaxError('es-abstract does not yet support internal slots');
  16. }
  17. if ($ObjectCreate) {
  18. return $ObjectCreate(proto);
  19. }
  20. if (hasProto) {
  21. return { __proto__: proto };
  22. }
  23. if (proto === null) {
  24. throw new $SyntaxError('native Object.create support is required to create null objects');
  25. }
  26. var T = function T() {};
  27. T.prototype = proto;
  28. return new T();
  29. };