5a15be8001f6c3a1ffdd8ff0689d919535bb6f2d31d92d0e7a288003152001dafc85333f53c5f02d795e37c8dead088e6a4826b464094fafadcedf6fd8bd89 1.0 KB

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