mirror of
https://github.com/tc39/test262.git
synced 2025-04-08 19:35:28 +02:00
Add tests for SuppressedError
This commit is contained in:
parent
ae0656d7d4
commit
b0319e488d
@ -0,0 +1,69 @@
|
||||
// Copyright (C) 2023 Ron Buckton. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-suppressederror-constructor
|
||||
description: >
|
||||
Cast ToString values of message in the created method property
|
||||
info: |
|
||||
SuppressedError ( error, suppressed, message )
|
||||
|
||||
...
|
||||
5. If message is not undefined, then
|
||||
a. Let msg be ? ToString(message).
|
||||
b. Perform ! CreateMethodProperty(O, "message", msg).
|
||||
6. Return O.
|
||||
|
||||
CreateMethodProperty ( O, P, V )
|
||||
|
||||
...
|
||||
3. Let newDesc be the PropertyDescriptor { [[Value]]: V, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }.
|
||||
4. Return ? O.[[DefineOwnProperty]](P, newDesc).
|
||||
features: [explicit-resource-management]
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
var case1 = new SuppressedError(undefined, undefined, 42);
|
||||
|
||||
verifyProperty(case1, 'message', {
|
||||
value: '42',
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
var case2 = new SuppressedError(undefined, undefined, false);
|
||||
|
||||
verifyProperty(case2, 'message', {
|
||||
value: 'false',
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
var case3 = new SuppressedError(undefined, undefined, true);
|
||||
|
||||
verifyProperty(case3, 'message', {
|
||||
value: 'true',
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
var case4 = new SuppressedError(undefined, undefined, { toString() { return 'string'; }});
|
||||
|
||||
verifyProperty(case4, 'message', {
|
||||
value: 'string',
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
var case5 = new SuppressedError(undefined, undefined, null);
|
||||
|
||||
verifyProperty(case5, 'message', {
|
||||
value: 'null',
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
});
|
@ -0,0 +1,33 @@
|
||||
// Copyright (C) 2023 Ron Buckton. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-suppressederror-constructor
|
||||
description: >
|
||||
Creates a method property for message
|
||||
info: |
|
||||
SuppressedError ( error, suppressed, message )
|
||||
|
||||
...
|
||||
5. If message is not undefined, then
|
||||
a. Let msg be ? ToString(message).
|
||||
b. Perform ! CreateMethodProperty(O, "message", msg).
|
||||
6. Return O.
|
||||
|
||||
CreateMethodProperty ( O, P, V )
|
||||
|
||||
...
|
||||
3. Let newDesc be the PropertyDescriptor { [[Value]]: V, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }.
|
||||
4. Return ? O.[[DefineOwnProperty]](P, newDesc).
|
||||
features: [explicit-resource-management]
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
var obj = new SuppressedError(undefined, undefined, '42');
|
||||
|
||||
verifyProperty(obj, 'message', {
|
||||
value: '42',
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
});
|
@ -0,0 +1,39 @@
|
||||
// Copyright (C) 2023 Ron Buckton. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-suppressederror-constructor
|
||||
description: >
|
||||
Abrupt completions of ToString(Symbol message)
|
||||
info: |
|
||||
SuppressedError ( error, suppressed, message )
|
||||
|
||||
...
|
||||
5. If message is not undefined, then
|
||||
a. Let msg be ? ToString(message).
|
||||
b. Perform ! CreateMethodProperty(O, "message", msg).
|
||||
6. Return O.
|
||||
features: [explicit-resource-management, Symbol, Symbol.toPrimitive]
|
||||
---*/
|
||||
|
||||
var case1 = Symbol();
|
||||
|
||||
assert.throws(TypeError, () => {
|
||||
new SuppressedError(undefined, undefined, case1);
|
||||
}, 'toPrimitive');
|
||||
|
||||
var case2 = {
|
||||
[Symbol.toPrimitive]() {
|
||||
return Symbol();
|
||||
},
|
||||
toString() {
|
||||
throw new Test262Error();
|
||||
},
|
||||
valueOf() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
|
||||
assert.throws(TypeError, () => {
|
||||
new SuppressedError(undefined, undefined, case2);
|
||||
}, 'from ToPrimitive');
|
@ -0,0 +1,59 @@
|
||||
// Copyright (C) 2023 Ron Buckton. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-suppressederror-constructor
|
||||
description: >
|
||||
Abrupt completions of ToString(message)
|
||||
info: |
|
||||
SuppressedError ( error, suppressed, message )
|
||||
|
||||
...
|
||||
5. If message is not undefined, then
|
||||
a. Let msg be ? ToString(message).
|
||||
b. Perform ! CreateMethodProperty(O, "message", msg).
|
||||
6. Return O.
|
||||
features: [explicit-resource-management, Symbol.toPrimitive]
|
||||
---*/
|
||||
|
||||
var case1 = {
|
||||
[Symbol.toPrimitive]() {
|
||||
throw new Test262Error();
|
||||
},
|
||||
toString() {
|
||||
throw 'toString called';
|
||||
},
|
||||
valueOf() {
|
||||
throw 'valueOf called';
|
||||
}
|
||||
};
|
||||
|
||||
assert.throws(Test262Error, () => {
|
||||
new SuppressedError(undefined, undefined, case1);
|
||||
}, 'toPrimitive');
|
||||
|
||||
var case2 = {
|
||||
[Symbol.toPrimitive]: undefined,
|
||||
toString() {
|
||||
throw new Test262Error();
|
||||
},
|
||||
valueOf() {
|
||||
throw 'valueOf called';
|
||||
}
|
||||
};
|
||||
|
||||
assert.throws(Test262Error, () => {
|
||||
new SuppressedError(undefined, undefined, case2);
|
||||
}, 'toString');
|
||||
|
||||
var case3 = {
|
||||
[Symbol.toPrimitive]: undefined,
|
||||
toString: undefined,
|
||||
valueOf() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
|
||||
assert.throws(Test262Error, () => {
|
||||
new SuppressedError(undefined, undefined, case3);
|
||||
}, 'valueOf');
|
@ -0,0 +1,19 @@
|
||||
// Copyright (C) 2023 Ron Buckton. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-suppressederror-constructor
|
||||
description: >
|
||||
NewTarget is undefined
|
||||
info: |
|
||||
SuppressedError ( error, suppressed, message )
|
||||
|
||||
1. If NewTarget is undefined, let newTarget be the active function object, else let newTarget be NewTarget.
|
||||
|
||||
features: [explicit-resource-management]
|
||||
---*/
|
||||
|
||||
var obj = SuppressedError();
|
||||
|
||||
assert.sameValue(Object.getPrototypeOf(obj), SuppressedError.prototype);
|
||||
assert(obj instanceof SuppressedError);
|
@ -0,0 +1,47 @@
|
||||
// Copyright (C) 2023 Ron Buckton. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-suppressederror-constructor
|
||||
description: >
|
||||
Use a custom NewTarget prototype
|
||||
info: |
|
||||
SuppressedError ( error, suppressed, message )
|
||||
|
||||
1. If NewTarget is undefined, let newTarget be the active function object, else let newTarget be NewTarget.
|
||||
2. Let O be ? OrdinaryCreateFromConstructor(newTarget, "%SuppressedError.prototype%", « [[ErrorData]], [[AggregateErrors]] »).
|
||||
...
|
||||
6. Return O.
|
||||
|
||||
OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
|
||||
|
||||
...
|
||||
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
|
||||
3. Return ObjectCreate(proto, internalSlotsList).
|
||||
|
||||
GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
|
||||
|
||||
...
|
||||
3. Let proto be ? Get(constructor, "prototype").
|
||||
4. If Type(proto) is not Object, then
|
||||
a. Let realm be ? GetFunctionRealm(constructor).
|
||||
b. Set proto to realm's intrinsic object named intrinsicDefaultProto.
|
||||
Return proto.
|
||||
features: [explicit-resource-management, Reflect.construct]
|
||||
---*/
|
||||
|
||||
var custom = { x: 42 };
|
||||
var newt = new Proxy(function() {}, {
|
||||
get(t, p) {
|
||||
if (p === 'prototype') {
|
||||
return custom;
|
||||
}
|
||||
|
||||
return t[p];
|
||||
}
|
||||
});
|
||||
|
||||
var obj = Reflect.construct(SuppressedError, [], newt);
|
||||
|
||||
assert.sameValue(Object.getPrototypeOf(obj), custom);
|
||||
assert.sameValue(obj.x, 42);
|
@ -0,0 +1,58 @@
|
||||
// Copyright (C) 2023 Ron Buckton. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-suppressederror-constructor
|
||||
description: >
|
||||
Fallback to the NewTarget's [[Prototype]] if the prototype property is not an object
|
||||
info: |
|
||||
SuppressedError ( error, suppressed, message )
|
||||
|
||||
1. If NewTarget is undefined, let newTarget be the active function object, else let newTarget be NewTarget.
|
||||
2. Let O be ? OrdinaryCreateFromConstructor(newTarget, "%SuppressedError.prototype%", « [[ErrorData]], [[AggregateErrors]] »).
|
||||
...
|
||||
6. Return O.
|
||||
|
||||
OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
|
||||
|
||||
...
|
||||
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
|
||||
3. Return ObjectCreate(proto, internalSlotsList).
|
||||
|
||||
GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
|
||||
|
||||
...
|
||||
3. Let proto be ? Get(constructor, "prototype").
|
||||
4. If Type(proto) is not Object, then
|
||||
a. Let realm be ? GetFunctionRealm(constructor).
|
||||
b. Set proto to realm's intrinsic object named intrinsicDefaultProto.
|
||||
Return proto.
|
||||
features: [explicit-resource-management, Symbol]
|
||||
---*/
|
||||
|
||||
const values = [
|
||||
undefined,
|
||||
null,
|
||||
42,
|
||||
false,
|
||||
true,
|
||||
Symbol(),
|
||||
'string',
|
||||
SuppressedError.prototype,
|
||||
];
|
||||
|
||||
const NewTarget = new Function();
|
||||
|
||||
for (const value of values) {
|
||||
const NewTargetProxy = new Proxy(NewTarget, {
|
||||
get(t, p) {
|
||||
if (p === 'prototype') {
|
||||
return value;
|
||||
}
|
||||
return t[p];
|
||||
}
|
||||
});
|
||||
|
||||
const error = Reflect.construct(SuppressedError, [], NewTargetProxy);
|
||||
assert.sameValue(Object.getPrototypeOf(error), SuppressedError.prototype);
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
// Copyright (C) 2023 Ron Buckton. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-suppressederror-constructor
|
||||
description: >
|
||||
Default prototype is the %SuppressedError.prototype%"
|
||||
info: |
|
||||
SuppressedError ( error, suppressed, message )
|
||||
|
||||
1. If NewTarget is undefined, let newTarget be the active function object, else let newTarget be NewTarget.
|
||||
2. Let O be ? OrdinaryCreateFromConstructor(newTarget, "%SuppressedError.prototype%", « [[ErrorData]], [[AggregateErrors]] »).
|
||||
...
|
||||
6. Return O.
|
||||
|
||||
OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
|
||||
|
||||
...
|
||||
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
|
||||
3. Return ObjectCreate(proto, internalSlotsList).
|
||||
|
||||
GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
|
||||
|
||||
...
|
||||
3. Let proto be ? Get(constructor, "prototype").
|
||||
4. If Type(proto) is not Object, then
|
||||
a. Let realm be ? GetFunctionRealm(constructor).
|
||||
b. Set proto to realm's intrinsic object named intrinsicDefaultProto.
|
||||
Return proto.
|
||||
features: [explicit-resource-management]
|
||||
---*/
|
||||
|
||||
var obj = new SuppressedError();
|
||||
|
||||
assert.sameValue(Object.getPrototypeOf(obj), SuppressedError.prototype);
|
@ -0,0 +1,37 @@
|
||||
// Copyright (C) 2023 Ron Buckton. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-suppressederror-constructor
|
||||
description: >
|
||||
Process arguments in superclass-then-subclass order
|
||||
info: |
|
||||
SuppressedError ( error, suppressed, message )
|
||||
|
||||
3. If message is not undefined, then
|
||||
a. Let messageString be ? ToString(message).
|
||||
b. Perform CreateNonEnumerableDataPropertyOrThrow(O, "message", messageString).
|
||||
4. Perform CreateNonEnumerableDataPropertyOrThrow(O, "error", error).
|
||||
5. Perform CreateNonEnumerableDataPropertyOrThrow(O, "suppressed", suppressed).
|
||||
|
||||
features: [explicit-resource-management, Symbol.iterator]
|
||||
---*/
|
||||
|
||||
let messageStringified = false;
|
||||
const message = {
|
||||
toString() {
|
||||
messageStringified = true;
|
||||
return '';
|
||||
}
|
||||
};
|
||||
const error = {};
|
||||
const suppressed = {};
|
||||
|
||||
const e = new SuppressedError(error, suppressed, message);
|
||||
|
||||
assert.sameValue(messageStringified, true);
|
||||
const keys = Object.getOwnPropertyNames(e);
|
||||
assert(keys.indexOf("message") === 0, "Expected 'message' to be defined first");
|
||||
assert(keys.indexOf("error") === 1, "Expected 'error' to be defined second");
|
||||
assert(keys.indexOf("suppressed") === 2, "Expected 'suppressed' to be defined third");
|
||||
|
20
test/built-ins/NativeErrors/SuppressedError/prototype/errors-absent-on-prototype.js
vendored
Normal file
20
test/built-ins/NativeErrors/SuppressedError/prototype/errors-absent-on-prototype.js
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
// Copyright (C) 2023 Ron Buckton. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-properties-of-the-suppressederror-prototype-objects
|
||||
description: >
|
||||
The SuppressedError prototype object isn't an SuppressedError instance.
|
||||
info: |
|
||||
Properties of the SuppressedError Prototype Object
|
||||
|
||||
The SuppressedError prototype object:
|
||||
...
|
||||
- is not an Error instance or an SuppressedError instance and does not have an
|
||||
[[ErrorData]] internal slot.
|
||||
...
|
||||
features: [explicit-resource-management]
|
||||
---*/
|
||||
|
||||
assert.sameValue(SuppressedError.prototype.hasOwnProperty("error"), false);
|
||||
assert.sameValue(SuppressedError.prototype.hasOwnProperty("suppressed"), false);
|
Loading…
x
Reference in New Issue
Block a user