mirror of https://github.com/tc39/test262.git
Merge pull request #465 from jugglinmike/improve-promise-coverage-all-race
Improve Promise coverage: PerformPromiseAll & PeformPromiseRace
This commit is contained in:
commit
4a862fba95
|
@ -0,0 +1,47 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
description: Use of the value returned by the constructor's `resolve` method.
|
||||
es6id: 25.4.4.1
|
||||
info: >
|
||||
[...]
|
||||
6. Let promiseCapability be NewPromiseCapability(C).
|
||||
[...]
|
||||
11. Let result be PerformPromiseAll(iteratorRecord, promiseCapability, C).
|
||||
[...]
|
||||
|
||||
25.4.4.1.1 Runtime Semantics: PerformPromiseAll
|
||||
[...]
|
||||
6. Repeat
|
||||
[...]
|
||||
i. Let nextPromise be Invoke(constructor, "resolve", «nextValue»).
|
||||
[...]
|
||||
r. Let result be Invoke(nextPromise, "then", resolveElement,
|
||||
promiseCapability.[[Reject]]»).
|
||||
[...]
|
||||
---*/
|
||||
|
||||
var originalCallCount = 0;
|
||||
var newCallCount = 0;
|
||||
var P = function(executor) {
|
||||
executor(function() {}, function() {});
|
||||
};
|
||||
P.resolve = function() {
|
||||
return newThenable;
|
||||
};
|
||||
|
||||
var originalThenable = {
|
||||
then: function() {
|
||||
originalCallCount += 1;
|
||||
}
|
||||
};
|
||||
var newThenable = {
|
||||
then: function() {
|
||||
newCallCount += 1;
|
||||
}
|
||||
};
|
||||
|
||||
Promise.all.call(P, [originalThenable]);
|
||||
|
||||
assert.sameValue(originalCallCount, 0, 'original `then` method not invoked');
|
||||
assert.sameValue(newCallCount, 1, 'new `then` method invoked exactly once');
|
|
@ -0,0 +1,54 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
Error when advancing the provided iterable
|
||||
es6id: 25.4.4.1
|
||||
info: >
|
||||
11. Let result be PerformPromiseAll(iteratorRecord, C, promiseCapability).
|
||||
12. If result is an abrupt completion,
|
||||
a. If iteratorRecord.[[done]] is false, let result be
|
||||
IteratorClose(iterator, result).
|
||||
b. IfAbruptRejectPromise(result, promiseCapability).
|
||||
|
||||
[...]
|
||||
|
||||
25.4.4.1.1 Runtime Semantics: PerformPromiseAll
|
||||
|
||||
[...]
|
||||
6. Repeat
|
||||
a. Let next be IteratorStep(iteratorRecord.[[iterator]]).
|
||||
b. If next is an abrupt completion, set iteratorRecord.[[done]] to
|
||||
true.
|
||||
c. ReturnIfAbrupt(next).
|
||||
features: [Symbol.iterator]
|
||||
---*/
|
||||
|
||||
var iterStepThrows = {};
|
||||
var poisonedDone = {};
|
||||
var error = new Test262Error();
|
||||
Object.defineProperty(poisonedDone, 'done', {
|
||||
get: function() {
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(poisonedDone, 'value', {
|
||||
get: function() {
|
||||
$ERROR('The `value` property should not be accessed.');
|
||||
}
|
||||
});
|
||||
|
||||
iterStepThrows[Symbol.iterator] = function() {
|
||||
return {
|
||||
next: function() {
|
||||
return poisonedDone;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Promise.all(iterStepThrows).then(function() {
|
||||
$ERROR('The promise should be rejected.');
|
||||
}, function(reason) {
|
||||
assert.sameValue(reason, error);
|
||||
}).then($DONE, $DONE);
|
|
@ -0,0 +1,47 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
description: Use of the value returned by the constructor's `resolve` method.
|
||||
es6id: 25.4.4.1
|
||||
info: >
|
||||
[...]
|
||||
6. Let promiseCapability be NewPromiseCapability(C).
|
||||
[...]
|
||||
11. Let result be PerformPromiseRace(iteratorRecord, promiseCapability, C).
|
||||
[...]
|
||||
|
||||
25.4.4.3.1 Runtime Semantics: PerformPromiseRace
|
||||
|
||||
1. Repeat
|
||||
[...]
|
||||
h. Let nextPromise be Invoke(C, "resolve", «nextValue»).
|
||||
[...]
|
||||
j. Let result be Invoke(nextPromise, "then",
|
||||
«promiseCapability.[[Resolve]], promiseCapability.[[Reject]]»).
|
||||
[...]
|
||||
---*/
|
||||
|
||||
var originalCallCount = 0;
|
||||
var newCallCount = 0;
|
||||
var P = function(executor) {
|
||||
executor(function() {}, function() {});
|
||||
};
|
||||
P.resolve = function() {
|
||||
return newThenable;
|
||||
};
|
||||
|
||||
var originalThenable = {
|
||||
then: function() {
|
||||
originalCallCount += 1;
|
||||
}
|
||||
};
|
||||
var newThenable = {
|
||||
then: function() {
|
||||
newCallCount += 1;
|
||||
}
|
||||
};
|
||||
|
||||
Promise.race.call(P, [originalThenable]);
|
||||
|
||||
assert.sameValue(originalCallCount, 0, 'original `then` method not invoked');
|
||||
assert.sameValue(newCallCount, 1, 'new `then` method invoked exactly once');
|
|
@ -0,0 +1,54 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
Explicit iterator closing in response to error
|
||||
es6id: 25.4.4.3
|
||||
info: >
|
||||
11. Let result be PerformPromiseRace(iteratorRecord, promiseCapability, C).
|
||||
12. If result is an abrupt completion, then
|
||||
a. If iteratorRecord.[[done]] is false, let result be
|
||||
IteratorClose(iterator,result).
|
||||
b. IfAbruptRejectPromise(result, promiseCapability).
|
||||
|
||||
|
||||
25.4.4.3.1 Runtime Semantics: PerformPromiseRace
|
||||
|
||||
1. Repeat
|
||||
[...]
|
||||
h. Let nextPromise be Invoke(C, "resolve", «nextValue»).
|
||||
i. ReturnIfAbrupt(nextPromise).
|
||||
features: [Symbol.iterator]
|
||||
---*/
|
||||
|
||||
var err = new Test262Error();
|
||||
var iterDoneSpy = {};
|
||||
var callCount = 0;
|
||||
var CustomPromise = function(executor) {
|
||||
return new Promise(executor);
|
||||
};
|
||||
iterDoneSpy[Symbol.iterator] = function() {
|
||||
return {
|
||||
next: function() {
|
||||
return { value: null, done: false };
|
||||
},
|
||||
return: function() {
|
||||
callCount += 1;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
CustomPromise.resolve = function() {
|
||||
throw err;
|
||||
};
|
||||
|
||||
Promise.race.call(CustomPromise, iterDoneSpy)
|
||||
.then(function() {
|
||||
$ERROR('The promise should be rejected.');
|
||||
}, function(reason) {
|
||||
assert.sameValue(reason, err);
|
||||
$DONE();
|
||||
});
|
||||
|
||||
assert.sameValue(callCount, 1);
|
|
@ -0,0 +1,50 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
Error when advancing the provided iterable
|
||||
es6id: 25.4.4.3
|
||||
info: >
|
||||
[...]
|
||||
11. Let result be PerformPromiseRace(iteratorRecord, promiseCapability, C).
|
||||
12. If result is an abrupt completion, then
|
||||
a. If iteratorRecord.[[done]] is false, let result be
|
||||
IteratorClose(iterator,result).
|
||||
b. IfAbruptRejectPromise(result, promiseCapability).
|
||||
|
||||
25.4.4.3.1 Runtime Semantics: PerformPromiseRace
|
||||
1. Repeat
|
||||
a. Let next be IteratorStep(iteratorRecord.[[iterator]]).
|
||||
b. If next is an abrupt completion, set iteratorRecord.[[done]] to true.
|
||||
c. ReturnIfAbrupt(next).
|
||||
features: [Symbol.iterator]
|
||||
---*/
|
||||
|
||||
var iterStepThrows = {};
|
||||
var poisonedDone = {};
|
||||
var error = new Test262Error();
|
||||
Object.defineProperty(poisonedDone, 'done', {
|
||||
get: function() {
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(poisonedDone, 'value', {
|
||||
get: function() {
|
||||
$ERROR('The `value` property should not be accessed.');
|
||||
}
|
||||
});
|
||||
|
||||
iterStepThrows[Symbol.iterator] = function() {
|
||||
return {
|
||||
next: function() {
|
||||
return poisonedDone;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Promise.race(iterStepThrows).then(function() {
|
||||
$ERROR('The promise should be rejected.');
|
||||
}, function(reason) {
|
||||
assert.sameValue(reason, error);
|
||||
}).then($DONE, $DONE);
|
Loading…
Reference in New Issue