-
Notifications
You must be signed in to change notification settings - Fork 478
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
1 parent
bc5c141
commit b5c9e71
Showing
10 changed files
with
416 additions
and
0 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
test/built-ins/NativeErrors/SuppressedError/message-method-prop-cast.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,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, | ||
}); |
33 changes: 33 additions & 0 deletions
33
test/built-ins/NativeErrors/SuppressedError/message-method-prop.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,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, | ||
}); |
39 changes: 39 additions & 0 deletions
39
test/built-ins/NativeErrors/SuppressedError/message-tostring-abrupt-symbol.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,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'); |
59 changes: 59 additions & 0 deletions
59
test/built-ins/NativeErrors/SuppressedError/message-tostring-abrupt.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,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'); |
19 changes: 19 additions & 0 deletions
19
test/built-ins/NativeErrors/SuppressedError/newtarget-is-undefined.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,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); |
47 changes: 47 additions & 0 deletions
47
test/built-ins/NativeErrors/SuppressedError/newtarget-proto-custom.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,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); |
58 changes: 58 additions & 0 deletions
58
test/built-ins/NativeErrors/SuppressedError/newtarget-proto-fallback.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,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); | ||
} |
35 changes: 35 additions & 0 deletions
35
test/built-ins/NativeErrors/SuppressedError/newtarget-proto.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,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); |
Oops, something went wrong.