main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
837 bytes
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var GetIntrinsic = require('get-intrinsic');
|
---|
| 4 |
|
---|
| 5 | var $species = GetIntrinsic('%Symbol.species%', true);
|
---|
| 6 | var $TypeError = require('es-errors/type');
|
---|
| 7 |
|
---|
| 8 | var IsConstructor = require('./IsConstructor');
|
---|
| 9 | var Type = require('./Type');
|
---|
| 10 |
|
---|
| 11 | // https://262.ecma-international.org/6.0/#sec-speciesconstructor
|
---|
| 12 |
|
---|
| 13 | module.exports = function SpeciesConstructor(O, defaultConstructor) {
|
---|
| 14 | if (Type(O) !== 'Object') {
|
---|
| 15 | throw new $TypeError('Assertion failed: Type(O) is not Object');
|
---|
| 16 | }
|
---|
| 17 | var C = O.constructor;
|
---|
| 18 | if (typeof C === 'undefined') {
|
---|
| 19 | return defaultConstructor;
|
---|
| 20 | }
|
---|
| 21 | if (Type(C) !== 'Object') {
|
---|
| 22 | throw new $TypeError('O.constructor is not an Object');
|
---|
| 23 | }
|
---|
| 24 | var S = $species ? C[$species] : void 0;
|
---|
| 25 | if (S == null) {
|
---|
| 26 | return defaultConstructor;
|
---|
| 27 | }
|
---|
| 28 | if (IsConstructor(S)) {
|
---|
| 29 | return S;
|
---|
| 30 | }
|
---|
| 31 | throw new $TypeError('no constructor found');
|
---|
| 32 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.