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.

GetPrototypeFromConstructor.js 923B

12345678910111213141516171819202122232425262728
  1. 'use strict';
  2. var GetIntrinsic = require('../GetIntrinsic');
  3. var $Function = GetIntrinsic('%Function%');
  4. var $TypeError = GetIntrinsic('%TypeError%');
  5. var Get = require('./Get');
  6. var IsConstructor = require('./IsConstructor');
  7. var Type = require('./Type');
  8. // https://ecma-international.org/ecma-262/6.0/#sec-getprototypefromconstructor
  9. module.exports = function GetPrototypeFromConstructor(constructor, intrinsicDefaultProto) {
  10. var intrinsic = GetIntrinsic(intrinsicDefaultProto); // throws if not a valid intrinsic
  11. if (!IsConstructor(constructor)) {
  12. throw new $TypeError('Assertion failed: `constructor` must be a constructor');
  13. }
  14. var proto = Get(constructor, 'prototype');
  15. if (Type(proto) !== 'Object') {
  16. if (!(constructor instanceof $Function)) {
  17. // ignore other realms, for now
  18. throw new $TypeError('cross-realm constructors not currently supported');
  19. }
  20. proto = intrinsic;
  21. }
  22. return proto;
  23. };