mirror of https://github.com/tc39/test262.git
Add tests for stage 3 proposal error cause (#2965)
* Add tests for error cause * Correct invocation of Proxy constructor Co-authored-by: Mike Pennisi <mike@mikepennisi.com>
This commit is contained in:
parent
eca69e2c95
commit
3e4e07c836
|
@ -0,0 +1,49 @@
|
||||||
|
// Copyright (C) 2021 Chengzhong Wu. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: InstallErrorCause on abrupt completions
|
||||||
|
info: |
|
||||||
|
Error ( message [ , options ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
4. Perform ? InstallErrorCause(O, options).
|
||||||
|
...
|
||||||
|
|
||||||
|
20.5.8.1 InstallErrorCause ( O, options )
|
||||||
|
|
||||||
|
1. If Type(options) is Object and ? HasProperty(options, "cause") is true, then
|
||||||
|
a. Let cause be ? Get(options, "cause").
|
||||||
|
b. Perform ! CreateNonEnumerableDataPropertyOrThrow(O, "cause", cause).
|
||||||
|
...
|
||||||
|
|
||||||
|
esid: sec-error-message
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var message = "my-message";
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CHECK#0
|
||||||
|
assert.throws(Test262Error, function () {
|
||||||
|
var options = new Proxy({}, {
|
||||||
|
has(target, prop) {
|
||||||
|
if (prop === "cause") {
|
||||||
|
throw new Test262Error("HasProperty");
|
||||||
|
}
|
||||||
|
return prop in target;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
var error = new Error(message, options);
|
||||||
|
}, "HasProperty");
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CHECK#1
|
||||||
|
assert.throws(Test262Error, function () {
|
||||||
|
var options = {
|
||||||
|
get cause() {
|
||||||
|
throw new Test262Error("Get Cause");
|
||||||
|
},
|
||||||
|
};
|
||||||
|
var error = new Error(message, options);
|
||||||
|
}, "Get Cause");
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
|
@ -0,0 +1,36 @@
|
||||||
|
// Copyright (C) 2021 Chengzhong Wu. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Error constructor creates own cause property
|
||||||
|
info: |
|
||||||
|
Error ( message [ , options ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
4. Perform ? InstallErrorCause(O, options).
|
||||||
|
...
|
||||||
|
|
||||||
|
20.5.8.1 InstallErrorCause ( O, options )
|
||||||
|
|
||||||
|
1. If Type(options) is Object and ? HasProperty(options, "cause") is true, then
|
||||||
|
a. Let cause be ? Get(options, "cause").
|
||||||
|
b. Perform ! CreateNonEnumerableDataPropertyOrThrow(O, "cause", cause).
|
||||||
|
...
|
||||||
|
|
||||||
|
esid: sec-error-message
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var message = "my-message";
|
||||||
|
var cause = { message: "my-cause" };
|
||||||
|
var error = new Error(message, { cause });
|
||||||
|
|
||||||
|
verifyProperty(error, "cause", {
|
||||||
|
configurable: true,
|
||||||
|
enumerable: false,
|
||||||
|
writeable: true,
|
||||||
|
value: cause,
|
||||||
|
});
|
||||||
|
|
||||||
|
verifyProperty(new Error(message), "cause", undefined);
|
||||||
|
verifyProperty(new Error(message, { cause: undefined }), "cause", { value: undefined });
|
|
@ -0,0 +1,36 @@
|
||||||
|
// Copyright (C) 2021 Chengzhong Wu. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Error constructor creates own properties in sequence
|
||||||
|
info: |
|
||||||
|
Error ( message [ , options ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
4. Perform ? InstallErrorCause(O, options).
|
||||||
|
...
|
||||||
|
|
||||||
|
esid: sec-error-message
|
||||||
|
includes: [deepEqual.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var message = "my-message";
|
||||||
|
var cause = { message: "my-cause" };
|
||||||
|
|
||||||
|
var sequence = [];
|
||||||
|
new Error(
|
||||||
|
{
|
||||||
|
toString() {
|
||||||
|
sequence.push("toString");
|
||||||
|
return message;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
get cause() {
|
||||||
|
sequence.push("cause");
|
||||||
|
return cause;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.deepEqual(sequence, [ "toString", "cause" ], "accessing own properties on sequence");
|
|
@ -0,0 +1,39 @@
|
||||||
|
// Copyright (C) 2021 Chengzhong Wu. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-aggregate-error
|
||||||
|
description: >
|
||||||
|
AggregateError constructor creates own cause property
|
||||||
|
info: |
|
||||||
|
AggregateError ( errors, message[ , options ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
4. Perform ? InstallErrorCause(O, options).
|
||||||
|
...
|
||||||
|
|
||||||
|
InstallErrorCause ( O, options )
|
||||||
|
|
||||||
|
1. If Type(options) is Object and ? HasProperty(options, "cause") is true, then
|
||||||
|
a. Let cause be ? Get(options, "cause").
|
||||||
|
b. Perform ! CreateNonEnumerableDataPropertyOrThrow(O, "cause", cause).
|
||||||
|
...
|
||||||
|
|
||||||
|
features: [AggregateError]
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var errors = [];
|
||||||
|
var message = "my-message";
|
||||||
|
var cause = { message: "my-cause" };
|
||||||
|
var error = new AggregateError(errors, message, { cause });
|
||||||
|
|
||||||
|
verifyProperty(error, "cause", {
|
||||||
|
configurable: true,
|
||||||
|
enumerable: false,
|
||||||
|
writeable: true,
|
||||||
|
value: cause,
|
||||||
|
});
|
||||||
|
|
||||||
|
verifyProperty(new AggregateError(errors, message), "cause", undefined);
|
||||||
|
verifyProperty(new AggregateError(errors, message, { cause: undefined }), "cause", { value: undefined });
|
|
@ -0,0 +1,44 @@
|
||||||
|
// Copyright (C) 2021 Chengzhong Wu. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: NativeError constructor creates own cause property
|
||||||
|
info: |
|
||||||
|
NativeError ( message[ , options ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
4. Perform ? InstallErrorCause(O, options).
|
||||||
|
...
|
||||||
|
|
||||||
|
20.5.8.1 InstallErrorCause ( O, options )
|
||||||
|
|
||||||
|
1. If Type(options) is Object and ? HasProperty(options, "cause") is true, then
|
||||||
|
a. Let cause be ? Get(options, "cause").
|
||||||
|
b. Perform ! CreateNonEnumerableDataPropertyOrThrow(O, "cause", cause).
|
||||||
|
...
|
||||||
|
|
||||||
|
esid: sec-nativeerror
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var nativeErrors = [
|
||||||
|
EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError
|
||||||
|
];
|
||||||
|
|
||||||
|
for (var i = 0; i < nativeErrors.length; ++i) {
|
||||||
|
var nativeError = nativeErrors[i];
|
||||||
|
|
||||||
|
var message = "my-message";
|
||||||
|
var cause = { message: "my-cause" };
|
||||||
|
var error = new nativeError(message, { cause });
|
||||||
|
|
||||||
|
verifyProperty(error, "cause", {
|
||||||
|
configurable: true,
|
||||||
|
enumerable: false,
|
||||||
|
writeable: true,
|
||||||
|
value: cause,
|
||||||
|
});
|
||||||
|
|
||||||
|
verifyProperty(new nativeError(message), "cause", undefined);
|
||||||
|
verifyProperty(new nativeError(message, { cause: undefined }), "cause", { value: undefined });
|
||||||
|
}
|
Loading…
Reference in New Issue