mirror of
https://github.com/tc39/test262.git
synced 2025-05-28 02:30:29 +02:00
* Reject exceptional input to `isConstructor` Prior to this commit, the `isConstructor` harness function would return `false` when invoked with a value that lacked a [[Call]] internal method. While it's true that such values are not constructors, there are no tests which benefit from using `isConstructor` to make such an assertion. Extend `isConstructor` to throw an error when invoked with a non-function object. Update a test which was misleadingly invoking the function with the value `undefined`. * fixup! Reject exceptional input to `isConstructor`
22 lines
514 B
JavaScript
22 lines
514 B
JavaScript
// 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.
|
|
defines: [isConstructor]
|
|
---*/
|
|
|
|
function isConstructor(f) {
|
|
if (typeof f !== "function") {
|
|
throw new Test262Error("isConstructor invoked with a non-function value");
|
|
}
|
|
|
|
try {
|
|
Reflect.construct(function(){}, [], f);
|
|
} catch (e) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|