OrdinaryCreateFromConstructor.js 808 B

1234567891011121314151617181920
  1. 'use strict';
  2. var GetIntrinsic = require('get-intrinsic');
  3. var $TypeError = GetIntrinsic('%TypeError%');
  4. var GetPrototypeFromConstructor = require('./GetPrototypeFromConstructor');
  5. var IsArray = require('./IsArray');
  6. var ObjectCreate = require('./ObjectCreate');
  7. // https://ecma-international.org/ecma-262/6.0/#sec-ordinarycreatefromconstructor
  8. module.exports = function OrdinaryCreateFromConstructor(constructor, intrinsicDefaultProto) {
  9. GetIntrinsic(intrinsicDefaultProto); // throws if not a valid intrinsic
  10. var proto = GetPrototypeFromConstructor(constructor, intrinsicDefaultProto);
  11. var slots = arguments.length < 3 ? [] : arguments[2];
  12. if (!IsArray(slots)) {
  13. throw new $TypeError('Assertion failed: if provided, `internalSlotsList` must be a List');
  14. }
  15. return ObjectCreate(proto, slots);
  16. };