Skip to content

Commit

Permalink
Add tests for AggregateError (tc39#2406)
Browse files Browse the repository at this point in the history
This covers part of the Promise.any proposal
  • Loading branch information
leobalter committed Nov 7, 2019
1 parent 91861e2 commit 1bc1935
Show file tree
Hide file tree
Showing 50 changed files with 2,124 additions and 0 deletions.
5 changes: 5 additions & 0 deletions features.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ coalesce-expression
# https://github.com/tc39-transfer/proposal-intl-displaynames
Intl.DisplayNames

# Promise.any
# https://github.com/tc39/proposal-promise-any
Promise.any
AggregateError

## Standard language features
#
# Language features that have been included in a published version of the
Expand Down
183 changes: 183 additions & 0 deletions test/built-ins/AggregateError/errors-iterabletolist-failures.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-aggregate-error
description: >
Return abrupt completion from IterableToList(errors)
info: |
AggregateError ( errors, message )
...
3. Let errorsList be ? IterableToList(errors).
4. Set O.[[AggregateErrors]] to errorsList.
...
6. Return O.
Runtime Semantics: IterableToList ( items [ , method ] )
1. If method is present, then
...
2. Else,
b. Let iteratorRecord be ? GetIterator(items, sync).
3. Let values be a new empty List.
4. Let next be true.
5. Repeat, while next is not false
a. Set next to ? IteratorStep(iteratorRecord).
b. If next is not false, then
i. Let nextValue be ? IteratorValue(next).
ii. Append nextValue to the end of the List values.
6. Return values.
GetIterator ( obj [ , hint [ , method ] ] )
...
3. If method is not present, then
a. If hint is async, then
...
b. Otherwise, set method to ? GetMethod(obj, @@iterator).
4. Let iterator be ? Call(method, obj).
5. If Type(iterator) is not Object, throw a TypeError exception.
6. Let nextMethod be ? GetV(iterator, "next").
...
8. Return iteratorRecord.
features: [AggregateError, Symbol.iterator]
---*/

var case1 = {
get [Symbol.iterator]() {
throw new Test262Error();
}
};

assert.throws(Test262Error, () => {
var obj = new AggregateError(case1);
}, 'get Symbol.iterator');

var case2 = {
get [Symbol.iterator]() {
return {};
}
};

assert.throws(TypeError, () => {
var obj = new AggregateError(case2);
}, 'GetMethod(obj, @@iterator) abrupts from non callable');

var case3 = {
[Symbol.iterator]() {
throw new Test262Error();
}
};

assert.throws(Test262Error, () => {
var obj = new AggregateError(case3);
}, 'Abrupt from @@iterator call');

var case4 = {
[Symbol.iterator]() {
return 'a string';
}
};

assert.throws(TypeError, () => {
var obj = new AggregateError(case4);
}, '@@iterator call returns a string');

var case5 = {
[Symbol.iterator]() {
return undefined;
}
};

assert.throws(TypeError, () => {
var obj = new AggregateError(case5);
}, '@@iterator call returns undefined');

var case6 = {
[Symbol.iterator]() {
return {
get next() {
throw new Test262Error();
}
}
}
};

assert.throws(Test262Error, () => {
var obj = new AggregateError(case6);
}, 'GetV(iterator, next) returns abrupt');

var case7 = {
[Symbol.iterator]() {
return {
get next() {
return {};
}
}
}
};

assert.throws(TypeError, () => {
var obj = new AggregateError(case7);
}, 'GetV(iterator, next) returns a non callable');

var case8 = {
[Symbol.iterator]() {
return {
next() {
throw new Test262Error();
}
}
}
};

assert.throws(Test262Error, () => {
var obj = new AggregateError(case8);
}, 'abrupt from iterator.next()');

var case9 = {
[Symbol.iterator]() {
return {
next() {
return undefined;
}
}
}
};

assert.throws(TypeError, () => {
var obj = new AggregateError(case9);
}, 'iterator.next() returns undefined');

var case10 = {
[Symbol.iterator]() {
return {
next() {
return 'a string';
}
}
}
};

assert.throws(TypeError, () => {
var obj = new AggregateError(case10);
}, 'iterator.next() returns a string');

var case11 = {
[Symbol.iterator]() {
return {
next() {
return {
get done() {
throw new Test262Error();
}
};
}
}
}
};

assert.throws(Test262Error, () => {
var obj = new AggregateError(case11);
}, 'IteratorCompete abrupts getting the done property');
69 changes: 69 additions & 0 deletions test/built-ins/AggregateError/errors-iterabletolist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-aggregate-error
description: >
Iteration of errors
info: |
AggregateError ( errors, message )
...
3. Let errorsList be ? IterableToList(errors).
4. Set O.[[AggregateErrors]] to errorsList.
...
6. Return O.
Runtime Semantics: IterableToList ( items [ , method ] )
1. If method is present, then
...
2. Else,
b. Let iteratorRecord be ? GetIterator(items, sync).
3. Let values be a new empty List.
4. Let next be true.
5. Repeat, while next is not false
a. Set next to ? IteratorStep(iteratorRecord).
b. If next is not false, then
i. Let nextValue be ? IteratorValue(next).
ii. Append nextValue to the end of the List values.
6. Return values.
GetIterator ( obj [ , hint [ , method ] ] )
...
3. If method is not present, then
a. If hint is async, then
...
b. Otherwise, set method to ? GetMethod(obj, @@iterator).
4. Let iterator be ? Call(method, obj).
5. If Type(iterator) is not Object, throw a TypeError exception.
6. Let nextMethod be ? GetV(iterator, "next").
...
8. Return iteratorRecord.
features: [AggregateError, Symbol.iterator]
includes: [compareArray.js]
---*/

var count = 0;
var values = [];
var case1 = {
[Symbol.iterator]() {
return {
next() {
count += 1;
return {
done: count === 3,
get value() {
values.push(count)
}
};
}
};
}
};

new AggregateError(case1);

assert.sameValue(count, 3);
assert.compareArray(values, [1, 2]);
32 changes: 32 additions & 0 deletions test/built-ins/AggregateError/length.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-aggregate-error
description: AggregateError.length property descriptor
info: |
AggregateError ( errors, message )
17 ECMAScript Standard Built-in Objects
Every built-in function object, including constructors, has a length
property whose value is an integer. Unless otherwise specified, this
value is equal to the largest number of named arguments shown in the
subclause headings for the function description. Optional parameters
(which are indicated with brackets: [ ]) or rest parameters (which
are shown using the form «...name») are not included in the default
argument count.
Unless otherwise specified, the length property of a built-in
function object has the attributes { [[Writable]]: false,
[[Enumerable]]: false, [[Configurable]]: true }.
includes: [propertyHelper.js]
features: [AggregateError]
---*/

verifyProperty(AggregateError, 'length', {
value: 2,
writable: false,
enumerable: false,
configurable: true
});
69 changes: 69 additions & 0 deletions test/built-ins/AggregateError/message-method-prop-cast.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-aggregate-error
description: >
Cast ToString values of message in the created method property
info: |
AggregateError ( errors, 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: [AggregateError]
includes: [propertyHelper.js]
---*/

var case1 = new AggregateError([], 42);

verifyProperty(case1, 'message', {
value: '42',
writable: true,
enumerable: false,
configurable: true,
});

var case2 = new AggregateError([], false);

verifyProperty(case2, 'message', {
value: 'false',
writable: true,
enumerable: false,
configurable: true,
});

var case3 = new AggregateError([], true);

verifyProperty(case3, 'message', {
value: 'true',
writable: true,
enumerable: false,
configurable: true,
});

var case4 = new AggregateError([], { toString() { return 'string'; }});

verifyProperty(case4, 'message', {
value: 'string',
writable: true,
enumerable: false,
configurable: true,
});

var case5 = new AggregateError([], null);

verifyProperty(case5, 'message', {
value: 'null',
writable: true,
enumerable: false,
configurable: true,
});

0 comments on commit 1bc1935

Please sign in to comment.