Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
});
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,
});
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');
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');
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);
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);
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 test/built-ins/NativeErrors/SuppressedError/newtarget-proto.js
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);
Loading