mirror of
https://github.com/tc39/test262.git
synced 2025-07-27 07:54:41 +02:00
Merge pull request #330 from bocoup/correct-promise-test
Fix bugs in Promise tests
This commit is contained in:
commit
134c484abb
@ -11,20 +11,17 @@ description: iterator.next throws, causing Promise.all to reject
|
|||||||
---*/
|
---*/
|
||||||
|
|
||||||
var iterThrows = {};
|
var iterThrows = {};
|
||||||
Object.defineProperty(iterThrows, Symbol.iterator, {
|
var error = new Test262Error();
|
||||||
get: function () {
|
iterThrows[Symbol.iterator] = function() {
|
||||||
return {
|
return {
|
||||||
next: function () {
|
next: function () {
|
||||||
throw new Error("abrupt completion");
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
});
|
|
||||||
|
|
||||||
Promise.all(iterThrows).then(function () {
|
Promise.all(iterThrows).then(function () {
|
||||||
$ERROR('Promise unexpectedly resolved: Promise.all(iterThrows) should throw TypeError');
|
$ERROR('Promise unexpectedly resolved: Promise.all(iterThrows) should throw TypeError');
|
||||||
},function (err) {
|
},function (reason) {
|
||||||
if (!(err instanceof TypeError)) {
|
assert.sameValue(reason, error);
|
||||||
$ERROR('Expected TypeError, got ' + err);
|
|
||||||
}
|
|
||||||
}).then($DONE,$DONE);
|
}).then($DONE,$DONE);
|
||||||
|
@ -14,21 +14,14 @@ var p = Promise.resolve("foo");
|
|||||||
|
|
||||||
Object.defineProperty(p, "constructor", {
|
Object.defineProperty(p, "constructor", {
|
||||||
get: function () {
|
get: function () {
|
||||||
throw new Error("abrupt completion");
|
throw new Test262Error();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
assert.throws(Test262Error, function() {
|
||||||
p.then(function () {
|
p.then(function() {
|
||||||
$ERROR("Should never be called.");
|
$ERROR("Should never be called.");
|
||||||
}, function () {
|
}, function() {
|
||||||
$ERROR("Should never be called.");
|
$ERROR("Should never be called.");
|
||||||
});
|
});
|
||||||
} catch (e) {
|
});
|
||||||
if (!(e instanceof Error)) {
|
|
||||||
$ERROR("Expected Error, got " + e);
|
|
||||||
}
|
|
||||||
if (e.message !== "abrupt completion") {
|
|
||||||
$ERROR("Expected the Error we threw, got " + e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -8,21 +8,18 @@ description: Promise.race rejects if IteratorStep throws
|
|||||||
---*/
|
---*/
|
||||||
|
|
||||||
var iterThrows = {};
|
var iterThrows = {};
|
||||||
Object.defineProperty(iterThrows, Symbol.iterator, {
|
var error = new Test262Error();
|
||||||
get: function () {
|
iterThrows[Symbol.iterator] = function () {
|
||||||
return {
|
return {
|
||||||
next: function () {
|
next: function () {
|
||||||
throw new Error("abrupt completion");
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
});
|
|
||||||
|
|
||||||
Promise.race(iterThrows).then(function () {
|
Promise.race(iterThrows).then(function () {
|
||||||
$ERROR('Promise unexpectedly fulfilled: Promise.race(iterThrows) should throw TypeError');
|
$ERROR('Promise unexpectedly fulfilled: Promise.race(iterThrows) should throw TypeError');
|
||||||
},function (err) {
|
}, function (reason) {
|
||||||
if (!(err instanceof TypeError)) {
|
assert.sameValue(reason, error);
|
||||||
$ERROR('Expected TypeError, got ' + err);
|
|
||||||
}
|
|
||||||
}).then($DONE,$DONE);
|
}).then($DONE,$DONE);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user