2017-12-21 21:08:29 +01:00
|
|
|
// Copyright (C) 2017 André Bargull. All rights reserved.
|
|
|
|
// This code is governed by the BSD license found in the LICENSE file.
|
|
|
|
|
|
|
|
/*---
|
|
|
|
description: |
|
|
|
|
Test if a given function is a constructor function.
|
2019-09-25 02:22:26 +02:00
|
|
|
defines: [isConstructor]
|
2022-12-06 22:12:39 +01:00
|
|
|
features: [Reflect.construct]
|
2017-12-21 21:08:29 +01:00
|
|
|
---*/
|
|
|
|
|
|
|
|
function isConstructor(f) {
|
2022-12-16 04:53:34 +01:00
|
|
|
if (typeof f !== "function") {
|
|
|
|
throw new Test262Error("isConstructor invoked with a non-function value");
|
|
|
|
}
|
|
|
|
|
2017-12-21 21:08:29 +01:00
|
|
|
try {
|
|
|
|
Reflect.construct(function(){}, [], f);
|
|
|
|
} catch (e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|