-
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
266 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.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); |
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,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); | ||
} |
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.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); | ||
} |
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.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); | ||
} |
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.sameValue(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(TypeError, 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.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); | ||
} |
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.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); | ||
} |
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.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); |
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.sameValue(Error.isError(new Symbol()), false); |