Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Error.isError tests #4266

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions test/built-ins/Error/isError/bigints.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (C) 2024 Jordan Harband. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-error.iserror
description: >
Returns false on bigints
features: [BigInt]
---*/

assert.sameValue(Error.isError(0n), false);
assert.sameValue(Error.isError(42n), false);
assert.sameValue(Error.isError(new BigInt(0)), false);
assert.sameValue(Error.isError(new BigInt(42)), false);
37 changes: 37 additions & 0 deletions test/built-ins/Error/isError/error-subclass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (C) 2024 Jordan Harband. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-error.iserror
description: >
Returns true on userland Error subclasses
features: [class]
---*/

class MyError extends Error {}
class MyEvalError extends EvalError {}
class MyRangeError extends RangeError {}
class MyReferenceError extends ReferenceError {}
class MySyntaxError extends SyntaxError {}
class MyTypeError extends TypeError {}
class MyURIError extends URIError {}

assert.sameValue(Error.isError(new MyError()), true);
assert.sameValue(Error.isError(new MyEvalError()), true);
assert.sameValue(Error.isError(new MyRangeError()), true);
assert.sameValue(Error.isError(new MyReferenceError()), true);
assert.sameValue(Error.isError(new MySyntaxError()), true);
assert.sameValue(Error.isError(new MyTypeError()), true);
assert.sameValue(Error.isError(new MyURIError()), true);

if (typeof AggregateError !== 'undefined') {
class MyAggregateError extends AggregateError {}

assert.sameValue(Error.isError(new MyAggregateError()), true);
}

if (typeof SuppressedError !== 'undefined') {
class MySuppressedError extends SuppressedError {}

assert.sameValue(Error.isError(new MySuppressedError()), true);
}
26 changes: 26 additions & 0 deletions test/built-ins/Error/isError/errors-other-realm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (C) 2024 Jordan Harband. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-error.iserror
description: >
Returns true on Error and Error subclass instances from a different realm
features: [cross-realm]
---*/

var other = $262.createRealm().global;

assert.sameValue(Error.isError(new other.Error()), true);
assert.sameValue(Error.isError(new other.EvalError()), true);
assert.sameValue(Error.isError(new other.RangeError()), true);
assert.sameValue(Error.isError(new other.ReferenceError()), true);
assert.sameValue(Error.isError(new other.SyntaxError()), true);
assert.sameValue(Error.isError(new other.TypeError()), true);
assert.sameValue(Error.isError(new other.URIError()), true);

if (typeof AggregateError !== 'undefined') {
assert.sameValue(Error.isError(new other.AggregateError()), true);
}
if (typeof SuppressedError !== 'undefined') {
assert.sameValue(Error.isError(new other.SuppressedError()), true);
}
23 changes: 23 additions & 0 deletions test/built-ins/Error/isError/errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (C) 2024 Jordan Harband. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-error.iserror
description: >
Returns true on Error and Error subclass instances
---*/

assert.sameValue(Error.isError(new Error()), true);
assert.sameValue(Error.isError(new EvalError()), true);
assert.sameValue(Error.isError(new RangeError()), true);
assert.sameValue(Error.isError(new ReferenceError()), true);
assert.sameValue(Error.isError(new SyntaxError()), true);
assert.sameValue(Error.isError(new TypeError()), true);
assert.sameValue(Error.isError(new URIError()), true);

if (typeof AggregateError !== 'undefined') {
assert.sameValue(Error.isError(new AggregateError()), true);
}
if (typeof SuppressedError !== 'undefined') {
assert.sameValue(Error.isError(new SuppressedError()), true);
}
21 changes: 21 additions & 0 deletions test/built-ins/Error/isError/fake-errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (C) 2024 Jordan Harband. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-error.iserror
description: >
Returns false on non-Error objects pretending to be an Error
---*/

var fakeError = {
__proto__: Error.prototype,
constructor: Error,
message: '',
stack: new Error().stack
};

if (typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol') {
fakeError[Symbol.toStringTag] = 'Error';
}

assert.sameValue(Error.isError(fakeError), false);
24 changes: 24 additions & 0 deletions test/built-ins/Error/isError/is-a-constructor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (C) 2024 Jordan Harband. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-error.iserror
description: >
Error.isError does not implement [[Construct]]
info: |
IsConstructor ( argument )

The abstract operation IsConstructor takes argument argument (an ECMAScript language value).
It determines if argument is a function object with a [[Construct]] internal method.
It performs the following steps when called:

If Type(argument) is not Object, return false.
If argument has a [[Construct]] internal method, return true.
Return false.
includes: [isConstructor.js]
features: [Reflect.construct]
---*/

assert.sameValue(isConstructor(Error.isError), false, 'isConstructor(Error.isError) must return false');
assert.throws(TypeError, function () { new Error.isError(); });

11 changes: 11 additions & 0 deletions test/built-ins/Error/isError/name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (C) 2024 Jordan Harband. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-error.iserror
description: >
The initial value of Error.isError.name is "isError".
---*/

assert.sameValue(Error.isError.name, 'isError');

31 changes: 31 additions & 0 deletions test/built-ins/Error/isError/non-error-objects-other-realm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (C) 2024 Jordan Harband. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-error.iserror
description: >
Returns false on non-Error objects from a different realm
features: [cross-realm]
---*/

var other = $262.createRealm().global;

assert.sameValue(Error.isError(new other.Object()), false);
assert.sameValue(Error.isError(new other.Array()), false);
assert.sameValue(Error.isError(new other.Function('')), false);
assert.sameValue(Error.isError(new other.RegExp('a')), false);

assert.sameValue(Error.isError(other.Error), false);
assert.sameValue(Error.isError(other.EvalError), false);
assert.sameValue(Error.isError(other.RangeError), false);
assert.sameValue(Error.isError(other.ReferenceError), false);
assert.sameValue(Error.isError(other.SyntaxError), false);
assert.sameValue(Error.isError(other.TypeError), false);
assert.sameValue(Error.isError(other.URIError), false);

if (typeof other.AggregateError !== 'undefined') {
assert.sameValue(Error.isError(other.AggregateError), false);
}
if (typeof other.SuppressedError !== 'undefined') {
assert.sameValue(Error.isError(other.SuppressedError), false);
}
28 changes: 28 additions & 0 deletions test/built-ins/Error/isError/non-error-objects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (C) 2024 Jordan Harband. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-error.iserror
description: >
Returns false on non-Error objects
---*/

assert.sameValue(Error.isError({}), false);
assert.sameValue(Error.isError([]), false);
assert.sameValue(Error.isError(function () {}), false);
assert.sameValue(Error.isError(/a/g), false);

assert.sameValue(Error.isError(Error), false);
assert.sameValue(Error.isError(EvalError), false);
assert.sameValue(Error.isError(RangeError), false);
assert.sameValue(Error.isError(ReferenceError), false);
assert.sameValue(Error.isError(SyntaxError), false);
assert.sameValue(Error.isError(TypeError), false);
assert.sameValue(Error.isError(URIError), false);

if (typeof AggregateError !== 'undefined') {
assert.sameValue(Error.isError(AggregateError), false);
}
if (typeof SuppressedError !== 'undefined') {
assert.sameValue(Error.isError(SuppressedError), false);
}
22 changes: 22 additions & 0 deletions test/built-ins/Error/isError/primitives.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (C) 2024 Jordan Harband. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-error.iserror
description: >
Returns false on primitives
---*/

assert.sameValue(Error.isError(), false);
assert.sameValue(Error.isError(undefined), false);
assert.sameValue(Error.isError(null), false);
assert.sameValue(Error.isError(true), false);
assert.sameValue(Error.isError(false), false);
assert.sameValue(Error.isError(0), false);
assert.sameValue(Error.isError(-0), false);
assert.sameValue(Error.isError(NaN), false);
assert.sameValue(Error.isError(Infinity), false);
assert.sameValue(Error.isError(-Infinity), false);
assert.sameValue(Error.isError(42), false);
assert.sameValue(Error.isError(''), false);
assert.sameValue(Error.isError('foo'), false);
18 changes: 18 additions & 0 deletions test/built-ins/Error/isError/prop-desc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (C) 2024 Jordan Harband. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-error.iserror
description: Property descriptor for Error.isError
info: |
Every other data property described in clauses 18 through 26 and in Annex B.2
has the attributes { [[Writable]]: true, [[Enumerable]]: false,
[[Configurable]]: true } unless otherwise specified.
includes: [propertyHelper.js]
---*/

verifyProperty(Error, "isError", {
writable: true,
enumerable: false,
configurable: true
});
11 changes: 11 additions & 0 deletions test/built-ins/Error/isError/symbols.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (C) 2024 Jordan Harband. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-error.iserror
description: >
Returns false on symbols
features: [Symbol]
---*/

assert.sameValue(Error.isError(new Symbol()), false);
Loading