forked from tc39/test262
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for AggregateError (tc39#2406)
This covers part of the Promise.any proposal
- Loading branch information
Showing
50 changed files
with
2,124 additions
and
0 deletions.
There are no files selected for viewing
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
183 changes: 183 additions & 0 deletions
183
test/built-ins/AggregateError/errors-iterabletolist-failures.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,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'); |
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) 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]); |
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,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 | ||
}); |
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) 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, | ||
}); |
Oops, something went wrong.