-
Notifications
You must be signed in to change notification settings - Fork 461
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
265 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.equal(Error.isError(0n), false); | ||
assert.equal(Error.isError(42n), false); | ||
assert.equal(Error.isError(new BigInt(0)), false); | ||
assert.equal(Error.isError(new BigInt(42)), false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// 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 | ||
---*/ | ||
|
||
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.equal(Error.isError(new MyError()), true); | ||
assert.equal(Error.isError(new MyEvalError()), true); | ||
assert.equal(Error.isError(new MyRangeError()), true); | ||
assert.equal(Error.isError(new MyReferenceError()), true); | ||
assert.equal(Error.isError(new MySyntaxError()), true); | ||
assert.equal(Error.isError(new MyTypeError()), true); | ||
assert.equal(Error.isError(new MyURIError()), true); | ||
|
||
if (typeof AggregateError !== 'undefined') { | ||
class MyAggregateError extends AggregateError {} | ||
|
||
assert.equal(Error.isError(new MyAggregateError()), true); | ||
} | ||
|
||
if (typeof SuppressedError !== 'undefined') { | ||
class MySuppressedError extends SuppressedError {} | ||
|
||
assert.equal(Error.isError(new MySuppressedError()), true); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.equal(Error.isError(new other.Error()), true); | ||
assert.equal(Error.isError(new other.EvalError()), true); | ||
assert.equal(Error.isError(new other.RangeError()), true); | ||
assert.equal(Error.isError(new other.ReferenceError()), true); | ||
assert.equal(Error.isError(new other.SyntaxError()), true); | ||
assert.equal(Error.isError(new other.TypeError()), true); | ||
assert.equal(Error.isError(new other.URIError()), true); | ||
|
||
if (typeof AggregateError !== 'undefined') { | ||
assert.equal(Error.isError(new other.AggregateError()), true); | ||
} | ||
if (typeof SuppressedError !== 'undefined') { | ||
assert.equal(Error.isError(new other.SuppressedError()), true); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.equal(Error.isError(new Error()), true); | ||
assert.equal(Error.isError(new EvalError()), true); | ||
assert.equal(Error.isError(new RangeError()), true); | ||
assert.equal(Error.isError(new ReferenceError()), true); | ||
assert.equal(Error.isError(new SyntaxError()), true); | ||
assert.equal(Error.isError(new TypeError()), true); | ||
assert.equal(Error.isError(new URIError()), true); | ||
|
||
if (typeof AggregateError !== 'undefined') { | ||
assert.equal(Error.isError(new AggregateError()), true); | ||
} | ||
if (typeof SuppressedError !== 'undefined') { | ||
assert.equal(Error.isError(new SuppressedError()), true); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.equal(Error.isError(fakeError), false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(function () { new Error.isError(); }); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
31
test/built-ins/Error/isError/non-error-objects-other-realm.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.equal(Error.isError(new other.Object()), false); | ||
assert.equal(Error.isError(new other.Array()), false); | ||
assert.equal(Error.isError(new other.Function('')), false); | ||
assert.equal(Error.isError(new other.RegExp('a')), false); | ||
|
||
assert.equal(Error.isError(other.Error), false); | ||
assert.equal(Error.isError(other.EvalError), false); | ||
assert.equal(Error.isError(other.RangeError), false); | ||
assert.equal(Error.isError(other.ReferenceError), false); | ||
assert.equal(Error.isError(other.SyntaxError), false); | ||
assert.equal(Error.isError(other.TypeError), false); | ||
assert.equal(Error.isError(other.URIError), false); | ||
|
||
if (typeof other.AggregateError !== 'undefined') { | ||
assert.equal(Error.isError(other.AggregateError), false); | ||
} | ||
if (typeof other.SuppressedError !== 'undefined') { | ||
assert.equal(Error.isError(other.SuppressedError), false); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.equal(Error.isError({}), false); | ||
assert.equal(Error.isError([]), false); | ||
assert.equal(Error.isError(function () {}), false); | ||
assert.equal(Error.isError(/a/g), false); | ||
|
||
assert.equal(Error.isError(Error), false); | ||
assert.equal(Error.isError(EvalError), false); | ||
assert.equal(Error.isError(RangeError), false); | ||
assert.equal(Error.isError(ReferenceError), false); | ||
assert.equal(Error.isError(SyntaxError), false); | ||
assert.equal(Error.isError(TypeError), false); | ||
assert.equal(Error.isError(URIError), false); | ||
|
||
if (typeof AggregateError !== 'undefined') { | ||
assert.equal(Error.isError(AggregateError), false); | ||
} | ||
if (typeof SuppressedError !== 'undefined') { | ||
assert.equal(Error.isError(SuppressedError), false); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.equal(Error.isError(), false); | ||
assert.equal(Error.isError(undefined), false); | ||
assert.equal(Error.isError(null), false); | ||
assert.equal(Error.isError(true), false); | ||
assert.equal(Error.isError(false), false); | ||
assert.equal(Error.isError(0), false); | ||
assert.equal(Error.isError(-0), false); | ||
assert.equal(Error.isError(NaN), false); | ||
assert.equal(Error.isError(Infinity), false); | ||
assert.equal(Error.isError(-Infinity), false); | ||
assert.equal(Error.isError(42), false); | ||
assert.equal(Error.isError(''), false); | ||
assert.equal(Error.isError('foo'), false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.equal(Error.isError(new Symbol()), false); |