mirror of https://github.com/tc39/test262.git
Fix tests for new resolve lookup
This commit is contained in:
parent
b646cf6365
commit
24d1b6d59c
|
@ -2,7 +2,7 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es6id: 25.4.4.1
|
||||
esid: sec-promise.all
|
||||
description: >
|
||||
Throws a TypeError if capabilities executor already called with non-undefined values.
|
||||
info: |
|
||||
|
@ -13,67 +13,90 @@ info: |
|
|||
7. ReturnIfAbrupt(promiseCapability).
|
||||
...
|
||||
|
||||
25.4.1.5.1 GetCapabilitiesExecutor Functions
|
||||
GetCapabilitiesExecutor Functions
|
||||
...
|
||||
3. If promiseCapability.[[Resolve]] is not undefined, throw a TypeError exception.
|
||||
4. If promiseCapability.[[Reject]] is not undefined, throw a TypeError exception.
|
||||
5. Set promiseCapability.[[Resolve]] to resolve.
|
||||
6. Set promiseCapability.[[Reject]] to reject.
|
||||
...
|
||||
|
||||
PerformPromiseAll ( iteratorRecord, constructor, resultCapability )
|
||||
|
||||
...
|
||||
1. Let promiseResolve be ? Get(constructor, `"resolve"`).
|
||||
1. If IsCallable(promiseResolve) is *false*, throw a *TypeError* exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
var checkPoint = "";
|
||||
Promise.all.call(function(executor) {
|
||||
function fn1(executor) {
|
||||
checkPoint += "a";
|
||||
executor();
|
||||
checkPoint += "b";
|
||||
executor(function() {}, function() {});
|
||||
checkPoint += "c";
|
||||
}, []);
|
||||
}
|
||||
fn1.resolve = function() {};
|
||||
Promise.all.call(fn1, []);
|
||||
assert.sameValue(checkPoint, "abc", "executor initially called with no arguments");
|
||||
|
||||
var checkPoint = "";
|
||||
Promise.all.call(function(executor) {
|
||||
checkPoint = "";
|
||||
function fn2(executor) {
|
||||
checkPoint += "a";
|
||||
executor(undefined, undefined);
|
||||
checkPoint += "b";
|
||||
executor(function() {}, function() {});
|
||||
checkPoint += "c";
|
||||
}, []);
|
||||
}
|
||||
fn2.resolve = function() {};
|
||||
Promise.all.call(fn2, []);
|
||||
assert.sameValue(checkPoint, "abc", "executor initially called with (undefined, undefined)");
|
||||
|
||||
var checkPoint = "";
|
||||
checkPoint = "";
|
||||
function fn3(executor) {
|
||||
checkPoint += "a";
|
||||
executor(undefined, function() {});
|
||||
checkPoint += "b";
|
||||
executor(function() {}, function() {});
|
||||
checkPoint += "c";
|
||||
}
|
||||
Object.defineProperty(fn3, 'resolve', {
|
||||
get() { throw new Test262Error; }
|
||||
});
|
||||
assert.throws(TypeError, function() {
|
||||
Promise.all.call(function(executor) {
|
||||
checkPoint += "a";
|
||||
executor(undefined, function() {});
|
||||
checkPoint += "b";
|
||||
executor(function() {}, function() {});
|
||||
checkPoint += "c";
|
||||
}, []);
|
||||
Promise.all.call(fn3, []);
|
||||
}, "executor initially called with (undefined, function)");
|
||||
assert.sameValue(checkPoint, "ab", "executor initially called with (undefined, function)");
|
||||
|
||||
var checkPoint = "";
|
||||
checkPoint = "";
|
||||
function fn4(executor) {
|
||||
checkPoint += "a";
|
||||
executor(function() {}, undefined);
|
||||
checkPoint += "b";
|
||||
executor(function() {}, function() {});
|
||||
checkPoint += "c";
|
||||
}
|
||||
Object.defineProperty(fn4, 'resolve', {
|
||||
get() { throw new Test262Error; }
|
||||
});
|
||||
assert.throws(TypeError, function() {
|
||||
Promise.all.call(function(executor) {
|
||||
checkPoint += "a";
|
||||
executor(function() {}, undefined);
|
||||
checkPoint += "b";
|
||||
executor(function() {}, function() {});
|
||||
checkPoint += "c";
|
||||
}, []);
|
||||
Promise.all.call(fn4, []);
|
||||
}, "executor initially called with (function, undefined)");
|
||||
assert.sameValue(checkPoint, "ab", "executor initially called with (function, undefined)");
|
||||
|
||||
var checkPoint = "";
|
||||
checkPoint = "";
|
||||
function fn5(executor) {
|
||||
checkPoint += "a";
|
||||
executor("invalid value", 123);
|
||||
checkPoint += "b";
|
||||
executor(function() {}, function() {});
|
||||
checkPoint += "c";
|
||||
}
|
||||
Object.defineProperty(fn5, 'resolve', {
|
||||
get() { throw new Test262Error; }
|
||||
});
|
||||
assert.throws(TypeError, function() {
|
||||
Promise.all.call(function(executor) {
|
||||
checkPoint += "a";
|
||||
executor("invalid value", 123);
|
||||
checkPoint += "b";
|
||||
executor(function() {}, function() {});
|
||||
checkPoint += "c";
|
||||
}, []);
|
||||
Promise.all.call(fn5, []);
|
||||
}, "executor initially called with (String, Number)");
|
||||
assert.sameValue(checkPoint, "ab", "executor initially called with (String, Number)");
|
||||
|
|
|
@ -25,59 +25,83 @@ info: |
|
|||
---*/
|
||||
|
||||
var checkPoint = "";
|
||||
function fn1(executor) {
|
||||
checkPoint += "a";
|
||||
}
|
||||
Object.defineProperty(fn1, 'resolve', {
|
||||
get() { throw new Test262Error; }
|
||||
});
|
||||
assert.throws(TypeError, function() {
|
||||
Promise.all.call(function(executor) {
|
||||
checkPoint += "a";
|
||||
}, []);
|
||||
Promise.all.call(fn1, []);
|
||||
}, "executor not called at all");
|
||||
assert.sameValue(checkPoint, "a", "executor not called at all");
|
||||
|
||||
var checkPoint = "";
|
||||
checkPoint = "";
|
||||
function fn2(executor) {
|
||||
checkPoint += "a";
|
||||
executor();
|
||||
checkPoint += "b";
|
||||
}
|
||||
Object.defineProperty(fn2, 'resolve', {
|
||||
get() { throw new Test262Error; }
|
||||
});
|
||||
assert.throws(TypeError, function() {
|
||||
Promise.all.call(function(executor) {
|
||||
checkPoint += "a";
|
||||
executor();
|
||||
checkPoint += "b";
|
||||
}, []);
|
||||
Promise.all.call(fn2, []);
|
||||
}, "executor called with no arguments");
|
||||
assert.sameValue(checkPoint, "ab", "executor called with no arguments");
|
||||
|
||||
var checkPoint = "";
|
||||
checkPoint = "";
|
||||
function fn3(executor) {
|
||||
checkPoint += "a";
|
||||
executor(undefined, undefined);
|
||||
checkPoint += "b";
|
||||
}
|
||||
Object.defineProperty(fn3, 'resolve', {
|
||||
get() { throw new Test262Error; }
|
||||
});
|
||||
assert.throws(TypeError, function() {
|
||||
Promise.all.call(function(executor) {
|
||||
checkPoint += "a";
|
||||
executor(undefined, undefined);
|
||||
checkPoint += "b";
|
||||
}, []);
|
||||
Promise.all.call(fn3, []);
|
||||
}, "executor called with (undefined, undefined)");
|
||||
assert.sameValue(checkPoint, "ab", "executor called with (undefined, undefined)");
|
||||
|
||||
var checkPoint = "";
|
||||
checkPoint = "";
|
||||
function fn4(executor) {
|
||||
checkPoint += "a";
|
||||
executor(undefined, function() {});
|
||||
checkPoint += "b";
|
||||
}
|
||||
Object.defineProperty(fn4, 'resolve', {
|
||||
get() { throw new Test262Error; }
|
||||
});
|
||||
assert.throws(TypeError, function() {
|
||||
Promise.all.call(function(executor) {
|
||||
checkPoint += "a";
|
||||
executor(undefined, function() {});
|
||||
checkPoint += "b";
|
||||
}, []);
|
||||
Promise.all.call(fn4, []);
|
||||
}, "executor called with (undefined, function)");
|
||||
assert.sameValue(checkPoint, "ab", "executor called with (undefined, function)");
|
||||
|
||||
var checkPoint = "";
|
||||
checkPoint = "";
|
||||
function fn5(executor) {
|
||||
checkPoint += "a";
|
||||
executor(function() {}, undefined);
|
||||
checkPoint += "b";
|
||||
}
|
||||
Object.defineProperty(fn5, 'resolve', {
|
||||
get() { throw new Test262Error; }
|
||||
});
|
||||
assert.throws(TypeError, function() {
|
||||
Promise.all.call(function(executor) {
|
||||
checkPoint += "a";
|
||||
executor(function() {}, undefined);
|
||||
checkPoint += "b";
|
||||
}, []);
|
||||
Promise.all.call(fn5, []);
|
||||
}, "executor called with (function, undefined)");
|
||||
assert.sameValue(checkPoint, "ab", "executor called with (function, undefined)");
|
||||
|
||||
var checkPoint = "";
|
||||
checkPoint = "";
|
||||
function fn6(executor) {
|
||||
checkPoint += "a";
|
||||
executor(123, "invalid value");
|
||||
checkPoint += "b";
|
||||
}
|
||||
Object.defineProperty(fn6, 'resolve', {
|
||||
get() { throw new Test262Error; }
|
||||
});
|
||||
assert.throws(TypeError, function() {
|
||||
Promise.all.call(function(executor) {
|
||||
checkPoint += "a";
|
||||
executor(123, "invalid value");
|
||||
checkPoint += "b";
|
||||
}, []);
|
||||
Promise.all.call(fn6, []);
|
||||
}, "executor called with (Number, String)");
|
||||
assert.sameValue(checkPoint, "ab", "executor called with (Number, String)");
|
||||
|
|
|
@ -45,11 +45,13 @@ info: |
|
|||
features: [Symbol.iterator]
|
||||
---*/
|
||||
|
||||
var nextCount = 0;
|
||||
var returnCount = 0;
|
||||
var iter = {};
|
||||
iter[Symbol.iterator] = function() {
|
||||
return {
|
||||
next: function() {
|
||||
nextCount += 1;
|
||||
return {
|
||||
done: true
|
||||
};
|
||||
|
@ -68,6 +70,9 @@ var P = function(executor) {
|
|||
});
|
||||
};
|
||||
|
||||
P.resolve = Promise.resolve;
|
||||
|
||||
Promise.all.call(P, iter);
|
||||
|
||||
assert.sameValue(nextCount, 1);
|
||||
assert.sameValue(returnCount, 0);
|
||||
|
|
|
@ -54,6 +54,8 @@ var P = function(executor) {
|
|||
});
|
||||
};
|
||||
|
||||
P.resolve = Promise.resolve;
|
||||
|
||||
Promise.all.call(P, [])
|
||||
.then(function() {
|
||||
$DONE('Promise incorrectly fulfilled.');
|
||||
|
|
|
@ -42,7 +42,7 @@ iterDoneSpy[Symbol.iterator] = function() {
|
|||
};
|
||||
|
||||
Promise.resolve = function() {
|
||||
throw new Error();
|
||||
throw new Test262Error();
|
||||
};
|
||||
|
||||
Promise.all(iterDoneSpy);
|
||||
|
|
|
@ -3,9 +3,8 @@
|
|||
|
||||
/*---
|
||||
description: >
|
||||
Error retrieving the constructor's `resolve` method (closing iterator)
|
||||
Error retrieving the constructor's `resolve` method before iterator being used.
|
||||
esid: sec-performpromiseall
|
||||
es6id: 25.4.4.1
|
||||
info: |
|
||||
11. Let result be PerformPromiseAll(iteratorRecord, C, promiseCapability).
|
||||
12. If result is an abrupt completion,
|
||||
|
@ -13,23 +12,29 @@ info: |
|
|||
IteratorClose(iterator, result).
|
||||
b. IfAbruptRejectPromise(result, promiseCapability).
|
||||
|
||||
[...]
|
||||
...
|
||||
|
||||
25.4.4.1.1 Runtime Semantics: PerformPromiseAll
|
||||
Runtime Semantics: PerformPromiseAll
|
||||
|
||||
[...]
|
||||
6. Repeat
|
||||
[...]
|
||||
i. Let nextPromise be Invoke(constructor, "resolve", «nextValue»).
|
||||
j. ReturnIfAbrupt(nextPromise ).
|
||||
...
|
||||
1. Let promiseResolve be ? Get(constructor, `"resolve"`).
|
||||
...
|
||||
1. Repeat,
|
||||
1. Let next be IteratorStep(iteratorRecord).
|
||||
...
|
||||
1. Let nextPromise be ? Call(promiseResolve, constructor, < nextValue >).
|
||||
features: [Symbol.iterator]
|
||||
---*/
|
||||
|
||||
var iter = {};
|
||||
|
||||
var returnCount = 0;
|
||||
var nextCount = 0;
|
||||
|
||||
iter[Symbol.iterator] = function() {
|
||||
return {
|
||||
next: function() {
|
||||
nextCount += 1;
|
||||
return {
|
||||
done: false
|
||||
};
|
||||
|
@ -41,11 +46,12 @@ iter[Symbol.iterator] = function() {
|
|||
};
|
||||
};
|
||||
Object.defineProperty(Promise, 'resolve', {
|
||||
get: function() {
|
||||
get() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
Promise.all(iter);
|
||||
|
||||
assert.sameValue(returnCount, 1);
|
||||
assert.sameValue(nextCount, 0);
|
||||
assert.sameValue(returnCount, 0);
|
||||
|
|
|
@ -15,13 +15,15 @@ info: |
|
|||
|
||||
[...]
|
||||
|
||||
25.4.4.1.1 Runtime Semantics: PerformPromiseAll
|
||||
Runtime Semantics: PerformPromiseAll
|
||||
|
||||
[...]
|
||||
6. Repeat
|
||||
[...]
|
||||
i. Let nextPromise be Invoke(constructor, "resolve", «nextValue»).
|
||||
j. ReturnIfAbrupt(nextPromise ).
|
||||
...
|
||||
1. Let promiseResolve be ? Get(constructor, `"resolve"`).
|
||||
...
|
||||
1. Repeat,
|
||||
1. Let next be IteratorStep(iteratorRecord).
|
||||
...
|
||||
1. Let nextPromise be ? Call(promiseResolve, constructor, < nextValue >).
|
||||
flags: [async]
|
||||
---*/
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@ features: [Symbol.species]
|
|||
function C(executor) {
|
||||
executor(function() {}, function() {});
|
||||
}
|
||||
|
||||
C.resolve = function() {};
|
||||
Object.defineProperty(C, Symbol.species, {
|
||||
get: function() {
|
||||
$ERROR("Getter for Symbol.species called");
|
||||
|
|
|
@ -23,57 +23,77 @@ info: |
|
|||
---*/
|
||||
|
||||
var checkPoint = "";
|
||||
Promise.race.call(function(executor) {
|
||||
function fn1(executor) {
|
||||
checkPoint += "a";
|
||||
executor();
|
||||
checkPoint += "b";
|
||||
executor(function() {}, function() {});
|
||||
checkPoint += "c";
|
||||
}, []);
|
||||
}
|
||||
fn1.resolve = function() {
|
||||
throw new Test262Error();
|
||||
};
|
||||
Promise.race.call(fn1 , []);
|
||||
assert.sameValue(checkPoint, "abc", "executor initially called with no arguments");
|
||||
|
||||
var checkPoint = "";
|
||||
Promise.race.call(function(executor) {
|
||||
checkPoint = "";
|
||||
function fn2(executor) {
|
||||
checkPoint += "a";
|
||||
executor(undefined, undefined);
|
||||
checkPoint += "b";
|
||||
executor(function() {}, function() {});
|
||||
checkPoint += "c";
|
||||
}, []);
|
||||
}
|
||||
fn2.resolve = function() {
|
||||
throw new Test262Error();
|
||||
};
|
||||
Promise.race.call(fn2 , []);
|
||||
assert.sameValue(checkPoint, "abc", "executor initially called with (undefined, undefined)");
|
||||
|
||||
var checkPoint = "";
|
||||
checkPoint = "";
|
||||
function fn3(executor) {
|
||||
checkPoint += "a";
|
||||
executor(undefined, function() {});
|
||||
checkPoint += "b";
|
||||
executor(function() {}, function() {});
|
||||
checkPoint += "c";
|
||||
}
|
||||
Object.defineProperty(fn3, "resolve", {
|
||||
get() { throw new Test262Error(); }
|
||||
});
|
||||
assert.throws(TypeError, function() {
|
||||
Promise.race.call(function(executor) {
|
||||
checkPoint += "a";
|
||||
executor(undefined, function() {});
|
||||
checkPoint += "b";
|
||||
executor(function() {}, function() {});
|
||||
checkPoint += "c";
|
||||
}, []);
|
||||
Promise.race.call(fn3 , []);
|
||||
}, "executor initially called with (undefined, function)");
|
||||
assert.sameValue(checkPoint, "ab", "executor initially called with (undefined, function)");
|
||||
|
||||
var checkPoint = "";
|
||||
checkPoint = "";
|
||||
function fn4(executor) {
|
||||
checkPoint += "a";
|
||||
executor(function() {}, undefined);
|
||||
checkPoint += "b";
|
||||
executor(function() {}, function() {});
|
||||
checkPoint += "c";
|
||||
}
|
||||
Object.defineProperty(fn4, "resolve", {
|
||||
get() { throw new Test262Error(); }
|
||||
});
|
||||
assert.throws(TypeError, function() {
|
||||
Promise.race.call(function(executor) {
|
||||
checkPoint += "a";
|
||||
executor(function() {}, undefined);
|
||||
checkPoint += "b";
|
||||
executor(function() {}, function() {});
|
||||
checkPoint += "c";
|
||||
}, []);
|
||||
Promise.race.call(fn4 , []);
|
||||
}, "executor initially called with (function, undefined)");
|
||||
assert.sameValue(checkPoint, "ab", "executor initially called with (function, undefined)");
|
||||
|
||||
var checkPoint = "";
|
||||
checkPoint = "";
|
||||
function fn5(executor) {
|
||||
checkPoint += "a";
|
||||
executor("invalid value", 123);
|
||||
checkPoint += "b";
|
||||
executor(function() {}, function() {});
|
||||
checkPoint += "c";
|
||||
}
|
||||
Object.defineProperty(fn5, "resolve", {
|
||||
get() { throw new Test262Error(); }
|
||||
});
|
||||
assert.throws(TypeError, function() {
|
||||
Promise.race.call(function(executor) {
|
||||
checkPoint += "a";
|
||||
executor("invalid value", 123);
|
||||
checkPoint += "b";
|
||||
executor(function() {}, function() {});
|
||||
checkPoint += "c";
|
||||
}, []);
|
||||
Promise.race.call(fn5 , []);
|
||||
}, "executor initially called with (String, Number)");
|
||||
assert.sameValue(checkPoint, "ab", "executor initially called with (String, Number)");
|
||||
|
|
|
@ -25,10 +25,14 @@ features: [Symbol.iterator]
|
|||
---*/
|
||||
|
||||
var iter = {};
|
||||
|
||||
var returnCount = 0;
|
||||
var nextCount = 0;
|
||||
|
||||
iter[Symbol.iterator] = function() {
|
||||
return {
|
||||
next: function() {
|
||||
nextCount += 1;
|
||||
return {
|
||||
done: false
|
||||
};
|
||||
|
@ -40,11 +44,12 @@ iter[Symbol.iterator] = function() {
|
|||
};
|
||||
};
|
||||
Object.defineProperty(Promise, 'resolve', {
|
||||
get: function() {
|
||||
get() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
Promise.race(iter);
|
||||
|
||||
assert.sameValue(returnCount, 1);
|
||||
assert.sameValue(nextCount, 0);
|
||||
assert.sameValue(returnCount, 0);
|
||||
|
|
|
@ -17,9 +17,12 @@ function C(executor) {
|
|||
executor(function() {}, function() {});
|
||||
}
|
||||
Object.defineProperty(C, Symbol.species, {
|
||||
get: function() {
|
||||
$ERROR("Getter for Symbol.species called");
|
||||
get() {
|
||||
throw new Test262Error("Getter for Symbol.species called");
|
||||
}
|
||||
});
|
||||
C.resolve = function() {
|
||||
throw new Test262Error();
|
||||
};
|
||||
|
||||
Promise.race.call(C, []);
|
||||
|
|
Loading…
Reference in New Issue