main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | var GetIntrinsic = require('../GetIntrinsic.js');
|
---|
4 |
|
---|
5 | var $construct = GetIntrinsic('%Reflect.construct%', true);
|
---|
6 |
|
---|
7 | var DefinePropertyOrThrow = require('./DefinePropertyOrThrow');
|
---|
8 | try {
|
---|
9 | DefinePropertyOrThrow({}, '', { '[[Get]]': function () {} });
|
---|
10 | } catch (e) {
|
---|
11 | // Accessor properties aren't supported
|
---|
12 | DefinePropertyOrThrow = null;
|
---|
13 | }
|
---|
14 |
|
---|
15 | // https://262.ecma-international.org/6.0/#sec-isconstructor
|
---|
16 |
|
---|
17 | if (DefinePropertyOrThrow && $construct) {
|
---|
18 | var isConstructorMarker = {};
|
---|
19 | var badArrayLike = {};
|
---|
20 | DefinePropertyOrThrow(badArrayLike, 'length', {
|
---|
21 | '[[Get]]': function () {
|
---|
22 | throw isConstructorMarker;
|
---|
23 | },
|
---|
24 | '[[Enumerable]]': true
|
---|
25 | });
|
---|
26 |
|
---|
27 | module.exports = function IsConstructor(argument) {
|
---|
28 | try {
|
---|
29 | // `Reflect.construct` invokes `IsConstructor(target)` before `Get(args, 'length')`:
|
---|
30 | $construct(argument, badArrayLike);
|
---|
31 | } catch (err) {
|
---|
32 | return err === isConstructorMarker;
|
---|
33 | }
|
---|
34 | };
|
---|
35 | } else {
|
---|
36 | module.exports = function IsConstructor(argument) {
|
---|
37 | // unfortunately there's no way to truly check this without try/catch `new argument` in old environments
|
---|
38 | return typeof argument === 'function' && !!argument.prototype;
|
---|
39 | };
|
---|
40 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.