built-ins/Promise/*: make all indentation consistent (depth & character) (#1433)

This commit is contained in:
Rick Waldron 2018-02-15 15:11:21 -05:00 committed by Leo Balter
parent 8d54ea55ad
commit 133dfa8793
223 changed files with 1780 additions and 1525 deletions

View File

@ -12,5 +12,5 @@ description: Promise === global.Promise
var global = this; var global = this;
if (Promise !== global.Promise) { if (Promise !== global.Promise) {
$ERROR("Expected Promise === global.Promise."); $ERROR("Expected Promise === global.Promise.");
} }

View File

@ -10,5 +10,5 @@ description: Promise.call("non-object") throws TypeError
---*/ ---*/
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
Promise.call("non-object", function () {}); Promise.call("non-object", function() {});
}); });

View File

@ -11,6 +11,6 @@ description: Promise.call(new Promise()) throws TypeError
var p = new Promise(function() {}); var p = new Promise(function() {});
assert.throws(TypeError, function () { assert.throws(TypeError, function() {
Promise.call(p, function () {}); Promise.call(p, function() {});
}); });

View File

@ -10,14 +10,16 @@ description: Promise.call(resolved Promise) throws TypeError
flags: [async] flags: [async]
---*/ ---*/
var p = new Promise(function(resolve) { resolve(1); }); var p = new Promise(function(resolve) {
resolve(1);
});
p.then(function () { p.then(function() {
Promise.call(p, function () {}); Promise.call(p, function() {});
}).then(function () { }).then(function() {
$ERROR("Unexpected resolution - expected TypeError"); $ERROR("Unexpected resolution - expected TypeError");
}, function (err) { }, function(err) {
if (!(err instanceof TypeError)) { if (!(err instanceof TypeError)) {
$ERROR("Expected TypeError, got " + err); $ERROR("Expected TypeError, got " + err);
} }
}).then($DONE, $DONE); }).then($DONE, $DONE);

View File

@ -10,14 +10,16 @@ description: Promise.call(rejected Promise) throws TypeError
flags: [async] flags: [async]
---*/ ---*/
var p = new Promise(function(resolve, reject) { reject(1) }); var p = new Promise(function(resolve, reject) {
reject(1)
});
p.catch(function () { p.catch(function() {
Promise.call(p, function () {}); Promise.call(p, function() {});
}).then(function () { }).then(function() {
$ERROR("Unexpected resolution - expected TypeError"); $ERROR("Unexpected resolution - expected TypeError");
}, function (err) { }, function(err) {
if (!(err instanceof TypeError)) { if (!(err instanceof TypeError)) {
$ERROR("Expected TypeError, got " + err); $ERROR("Expected TypeError, got " + err);
} }
}).then($DONE, $DONE); }).then($DONE, $DONE);

View File

@ -12,15 +12,14 @@ flags: [async]
---*/ ---*/
var errorObject = {}, var errorObject = {},
p = new Promise(function () { p = new Promise(function() {
throw errorObject; throw errorObject;
}); });
p.then(function() { p.then(function() {
$ERROR("Unexpected fulfill -- promise should reject."); $ERROR("Unexpected fulfill -- promise should reject.");
}, function (err) { }, function(err) {
if (err !== errorObject) { if (err !== errorObject) {
$ERROR("Expected promise rejection reason to be thrown errorObject, actually " + err); $ERROR("Expected promise rejection reason to be thrown errorObject, actually " + err);
} }
}).then($DONE, $DONE); }).then($DONE, $DONE);

View File

@ -14,10 +14,10 @@ flags: [async, noStrict]
var expectedThis = this; var expectedThis = this;
var p = new Promise(function (resolve) { var p = new Promise(function(resolve) {
if (this !== expectedThis) { if (this !== expectedThis) {
$ERROR("'this' must be global object, got " + this); $ERROR("'this' must be global object, got " + this);
} }
resolve(); resolve();
}).then($DONE, $DONE); }).then($DONE, $DONE);

View File

@ -14,10 +14,10 @@ flags: [async, onlyStrict]
var expectedThis = undefined; var expectedThis = undefined;
var p = new Promise(function (resolve) { var p = new Promise(function(resolve) {
if (this !== expectedThis) { if (this !== expectedThis) {
$ERROR("'this' must be undefined, got " + this); $ERROR("'this' must be undefined, got " + this);
} }
resolve(); resolve();
}).then($DONE, $DONE); }).then($DONE, $DONE);

View File

@ -9,5 +9,5 @@ description: Promise.all is callable
---*/ ---*/
if ((typeof Promise.all) !== "function") { if ((typeof Promise.all) !== "function") {
$ERROR('Expected Promise.all to be a function'); $ERROR('Expected Promise.all to be a function');
} }

View File

@ -10,5 +10,5 @@ description: Promise.all returns a Promise
var p = Promise.all([]); var p = Promise.all([]);
if (!(p instanceof Promise)) { if (!(p instanceof Promise)) {
$ERROR('Expected p to be a Promise'); $ERROR('Expected p to be a Promise');
} }

View File

@ -12,15 +12,15 @@ flags: [async]
var sequence = []; var sequence = [];
Promise.all([]).then(function () { Promise.all([]).then(function() {
sequence.push(2); sequence.push(2);
}).catch($DONE); }).catch($DONE);
Promise.resolve().then(function() { Promise.resolve().then(function() {
sequence.push(3); sequence.push(3);
}).then(function () { }).then(function() {
sequence.push(4); sequence.push(4);
checkSequence(sequence, "Promises resolved in unexpected sequence"); checkSequence(sequence, "Promises resolved in unexpected sequence");
}).then($DONE, $DONE); }).then($DONE, $DONE);
sequence.push(1); sequence.push(1);

View File

@ -11,8 +11,8 @@ flags: [async]
var arg = []; var arg = [];
Promise.all(arg).then(function (result) { Promise.all(arg).then(function(result) {
if(!(result instanceof Array)) { if (!(result instanceof Array)) {
$ERROR("expected an array from Promise.all, got " + result); $ERROR("expected an array from Promise.all, got " + result);
} }
}).then($DONE, $DONE); }).then($DONE, $DONE);

View File

@ -11,8 +11,8 @@ flags: [async]
var arg = []; var arg = [];
Promise.all(arg).then(function (result) { Promise.all(arg).then(function(result) {
if(result.length !== 0) { if (result.length !== 0) {
$ERROR("expected an empty array from Promise.all([]), got " + result); $ERROR("expected an empty array from Promise.all([]), got " + result);
} }
}).then($DONE, $DONE); }).then($DONE, $DONE);

View File

@ -11,8 +11,8 @@ flags: [async]
var arg = []; var arg = [];
Promise.all(arg).then(function (result) { Promise.all(arg).then(function(result) {
if(result === arg) { if (result === arg) {
$ERROR("expected a new array from Promise.all but argument was re-used"); $ERROR("expected a new array from Promise.all but argument was re-used");
} }
}).then($DONE, $DONE); }).then($DONE, $DONE);

View File

@ -14,10 +14,10 @@ flags: [async]
var nonIterable = 3; var nonIterable = 3;
Promise.all(nonIterable).then(function () { Promise.all(nonIterable).then(function() {
$ERROR('Promise unexpectedly resolved: Promise.all(nonIterable) should throw TypeError'); $ERROR('Promise unexpectedly resolved: Promise.all(nonIterable) should throw TypeError');
},function (err) { }, function(err) {
if (!(err instanceof TypeError)) { if (!(err instanceof TypeError)) {
$ERROR('Expected TypeError, got ' + err); $ERROR('Expected TypeError, got ' + err);
} }
}).then($DONE, $DONE); }).then($DONE, $DONE);

View File

@ -13,10 +13,10 @@ description: Promise.all(new Error()) returns Promise rejected with TypeError
flags: [async] flags: [async]
---*/ ---*/
Promise.all(new Error("abrupt")).then(function () { Promise.all(new Error("abrupt")).then(function() {
$ERROR('Promise unexpectedly resolved: Promise.all(abruptCompletion) should throw TypeError'); $ERROR('Promise unexpectedly resolved: Promise.all(abruptCompletion) should throw TypeError');
},function (err) { }, function(err) {
if (!(err instanceof TypeError)) { if (!(err instanceof TypeError)) {
$ERROR('Expected TypeError, got ' + err); $ERROR('Expected TypeError, got ' + err);
} }
}).then($DONE,$DONE); }).then($DONE, $DONE);

View File

@ -14,15 +14,15 @@ flags: [async]
var iterThrows = {}; var iterThrows = {};
Object.defineProperty(iterThrows, Symbol.iterator, { Object.defineProperty(iterThrows, Symbol.iterator, {
get: function () { get: function() {
throw new Error("abrupt completion"); throw new Error("abrupt completion");
} }
}); });
Promise.all(iterThrows).then(function () { Promise.all(iterThrows).then(function() {
$ERROR('Promise unexpectedly fulfilled: Promise.all(iterThrows) should throw TypeError'); $ERROR('Promise unexpectedly fulfilled: Promise.all(iterThrows) should throw TypeError');
},function (err) { }, function(err) {
if (!(err instanceof Error)) { if (!(err instanceof Error)) {
$ERROR('Expected promise to be rejected with error, got ' + err); $ERROR('Expected promise to be rejected with error, got ' + err);
} }
}).then($DONE,$DONE); }).then($DONE, $DONE);

View File

@ -9,8 +9,7 @@ description: this must conform to Promise constructor in Promise.all
author: Sam Mikes author: Sam Mikes
---*/ ---*/
function ZeroArgConstructor() { function ZeroArgConstructor() {}
}
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
Promise.all.call(ZeroArgConstructor, []); Promise.all.call(ZeroArgConstructor, []);

View File

@ -15,15 +15,15 @@ flags: [async]
var iterThrows = {}; var iterThrows = {};
var error = new Test262Error(); var error = new Test262Error();
iterThrows[Symbol.iterator] = function() { iterThrows[Symbol.iterator] = function() {
return { return {
next: function () { next: function() {
throw error; 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 (reason) { }, function(reason) {
assert.sameValue(reason, error); assert.sameValue(reason, error);
}).then($DONE,$DONE); }).then($DONE, $DONE);

View File

@ -12,5 +12,5 @@ description: Promise.all([]) produces a promise
var p = Promise.all([]); var p = Promise.all([]);
if (!(p instanceof Promise)) { if (!(p instanceof Promise)) {
$ERROR('Expected Promise.all([]) to be instanceof Promise' + err); $ERROR('Expected Promise.all([]) to be instanceof Promise' + err);
} }

View File

@ -13,11 +13,11 @@ flags: [async]
var p = Promise.all([]); var p = Promise.all([]);
p.then(function (result) { p.then(function(result) {
if (!(result instanceof Array)) { if (!(result instanceof Array)) {
$ERROR("Expected Promise.all([]) to be Array, actually " + result); $ERROR("Expected Promise.all([]) to be Array, actually " + result);
} }
if (result.length !== 0) { if (result.length !== 0) {
$ERROR("Expected Promise.all([]) to be empty Array, actually " + result); $ERROR("Expected Promise.all([]) to be empty Array, actually " + result);
} }
}).then($DONE, $DONE); }).then($DONE, $DONE);

View File

@ -15,17 +15,17 @@ var p1 = Promise.resolve(3);
var pAll = Promise.all([p1]); var pAll = Promise.all([p1]);
pAll.then(function (result) { pAll.then(function(result) {
if (!(pAll instanceof Promise)) { if (!(pAll instanceof Promise)) {
$ERROR("Expected Promise.all() to be promise, actually " + pAll); $ERROR("Expected Promise.all() to be promise, actually " + pAll);
} }
if (!(result instanceof Array)) { if (!(result instanceof Array)) {
$ERROR("Expected Promise.all() to be promise for an Array, actually " + result); $ERROR("Expected Promise.all() to be promise for an Array, actually " + result);
} }
if (result.length !== 1) { if (result.length !== 1) {
$ERROR("Expected Promise.all([p1]) to be a promise for one-element Array, actually " + result); $ERROR("Expected Promise.all([p1]) to be a promise for one-element Array, actually " + result);
} }
if (result[0] !== 3) { if (result[0] !== 3) {
$ERROR("Expected result[0] to be 3, actually " + result[0]); $ERROR("Expected result[0] to be 3, actually " + result[0]);
} }
}).then($DONE, $DONE); }).then($DONE, $DONE);

View File

@ -14,21 +14,23 @@ flags: [async]
var sequence = []; var sequence = [];
var p1 = new Promise(function (resolve) { resolve({}); } ); var p1 = new Promise(function(resolve) {
resolve({});
});
sequence.push(1); sequence.push(1);
Promise.all([p1]).then(function (resolved) { Promise.all([p1]).then(function(resolved) {
sequence.push(4); sequence.push(4);
checkSequence(sequence, "Expected Promise.all().then to queue second"); checkSequence(sequence, "Expected Promise.all().then to queue second");
}).catch($DONE); }).catch($DONE);
p1.then(function () { p1.then(function() {
sequence.push(3); sequence.push(3);
checkSequence(sequence, "Expected p1.then to queue first"); checkSequence(sequence, "Expected p1.then to queue first");
}).then(function () { }).then(function() {
sequence.push(5); sequence.push(5);
checkSequence(sequence, "Expected final then to queue last"); checkSequence(sequence, "Expected final then to queue last");
}).then($DONE, $DONE); }).then($DONE, $DONE);
sequence.push(2); sequence.push(2);

View File

@ -11,24 +11,28 @@ flags: [async]
var sequence = []; var sequence = [];
var p1 = new Promise(function (resolve) { resolve(1); } ); var p1 = new Promise(function(resolve) {
var p2 = new Promise(function (resolve) { resolve(2); } ); resolve(1);
});
var p2 = new Promise(function(resolve) {
resolve(2);
});
sequence.push(1); sequence.push(1);
p1.then(function () { p1.then(function() {
sequence.push(3); sequence.push(3);
checkSequence(sequence, "Expected to be called first."); checkSequence(sequence, "Expected to be called first.");
}).catch($DONE); }).catch($DONE);
Promise.all([p1, p2]).then(function () { Promise.all([p1, p2]).then(function() {
sequence.push(5); sequence.push(5);
checkSequence(sequence, "Expected to be called third."); checkSequence(sequence, "Expected to be called third.");
}).then($DONE, $DONE); }).then($DONE, $DONE);
p2.then(function () { p2.then(function() {
sequence.push(4); sequence.push(4);
checkSequence(sequence, "Expected to be called second."); checkSequence(sequence, "Expected to be called second.");
}).catch($DONE); }).catch($DONE);
sequence.push(2); sequence.push(2);

View File

@ -11,17 +11,17 @@ flags: [async]
---*/ ---*/
var rejectP1, var rejectP1,
p1 = new Promise(function (resolve, reject) { p1 = new Promise(function(resolve, reject) {
rejectP1 = reject; rejectP1 = reject;
}), }),
p2 = Promise.resolve(2); p2 = Promise.resolve(2);
Promise.all([p1, p2]).then(function (resolve) { Promise.all([p1, p2]).then(function(resolve) {
$ERROR("Did not expect promise to be fulfilled."); $ERROR("Did not expect promise to be fulfilled.");
}, function (rejected) { }, function(rejected) {
if (rejected !== 1) { if (rejected !== 1) {
$ERROR("Expected promise to be rejected with 1, actually " + rejected); $ERROR("Expected promise to be rejected with 1, actually " + rejected);
} }
}).then($DONE, $DONE); }).then($DONE, $DONE);
rejectP1(1); rejectP1(1);

View File

@ -11,17 +11,17 @@ flags: [async]
---*/ ---*/
var rejectP2, var rejectP2,
p1 = Promise.resolve(1), p1 = Promise.resolve(1),
p2 = new Promise(function (resolve, reject) { p2 = new Promise(function(resolve, reject) {
rejectP2 = reject; rejectP2 = reject;
}); });
Promise.all([p1, p2]).then(function () { Promise.all([p1, p2]).then(function() {
$ERROR("Did not expect promise to be fulfilled."); $ERROR("Did not expect promise to be fulfilled.");
}, function (rejected) { }, function(rejected) {
if (rejected !== 2) { if (rejected !== 2) {
$ERROR("Expected promise to be rejected with 2, actually " + rejected); $ERROR("Expected promise to be rejected with 2, actually " + rejected);
} }
}).then($DONE, $DONE); }).then($DONE, $DONE);
rejectP2(2); rejectP2(2);

View File

@ -27,7 +27,9 @@ function Constructor(executor) {
} }
executor(resolve, $ERROR); executor(resolve, $ERROR);
} }
Constructor.resolve = function(v) { return v; }; Constructor.resolve = function(v) {
return v;
};
var p1OnFulfilled; var p1OnFulfilled;

View File

@ -26,7 +26,9 @@ function Constructor(executor) {
} }
executor(resolve, $ERROR); executor(resolve, $ERROR);
} }
Constructor.resolve = function(v) { return v; }; Constructor.resolve = function(v) {
return v;
};
var p1 = { var p1 = {
then: function(onFulfilled, onRejected) { then: function(onFulfilled, onRejected) {

View File

@ -25,7 +25,9 @@ function Constructor(executor) {
} }
executor(resolve, $ERROR); executor(resolve, $ERROR);
} }
Constructor.resolve = function(v) { return v; }; Constructor.resolve = function(v) {
return v;
};
var p1 = { var p1 = {
then: function(onFulfilled, onRejected) { then: function(onFulfilled, onRejected) {

View File

@ -27,7 +27,7 @@ Promise.all.call(function(executor) {
checkPoint += "a"; checkPoint += "a";
executor(); executor();
checkPoint += "b"; checkPoint += "b";
executor(function(){}, function(){}); executor(function() {}, function() {});
checkPoint += "c"; checkPoint += "c";
}, []); }, []);
assert.sameValue(checkPoint, "abc", "executor initially called with no arguments"); assert.sameValue(checkPoint, "abc", "executor initially called with no arguments");
@ -37,7 +37,7 @@ Promise.all.call(function(executor) {
checkPoint += "a"; checkPoint += "a";
executor(undefined, undefined); executor(undefined, undefined);
checkPoint += "b"; checkPoint += "b";
executor(function(){}, function(){}); executor(function() {}, function() {});
checkPoint += "c"; checkPoint += "c";
}, []); }, []);
assert.sameValue(checkPoint, "abc", "executor initially called with (undefined, undefined)"); assert.sameValue(checkPoint, "abc", "executor initially called with (undefined, undefined)");
@ -46,9 +46,9 @@ var checkPoint = "";
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
Promise.all.call(function(executor) { Promise.all.call(function(executor) {
checkPoint += "a"; checkPoint += "a";
executor(undefined, function(){}); executor(undefined, function() {});
checkPoint += "b"; checkPoint += "b";
executor(function(){}, function(){}); executor(function() {}, function() {});
checkPoint += "c"; checkPoint += "c";
}, []); }, []);
}, "executor initially called with (undefined, function)"); }, "executor initially called with (undefined, function)");
@ -58,9 +58,9 @@ var checkPoint = "";
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
Promise.all.call(function(executor) { Promise.all.call(function(executor) {
checkPoint += "a"; checkPoint += "a";
executor(function(){}, undefined); executor(function() {}, undefined);
checkPoint += "b"; checkPoint += "b";
executor(function(){}, function(){}); executor(function() {}, function() {});
checkPoint += "c"; checkPoint += "c";
}, []); }, []);
}, "executor initially called with (function, undefined)"); }, "executor initially called with (function, undefined)");
@ -72,7 +72,7 @@ assert.throws(TypeError, function() {
checkPoint += "a"; checkPoint += "a";
executor("invalid value", 123); executor("invalid value", 123);
checkPoint += "b"; checkPoint += "b";
executor(function(){}, function(){}); executor(function() {}, function() {});
checkPoint += "c"; checkPoint += "c";
}, []); }, []);
}, "executor initially called with (String, Number)"); }, "executor initially called with (String, Number)");

View File

@ -56,7 +56,7 @@ var checkPoint = "";
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
Promise.all.call(function(executor) { Promise.all.call(function(executor) {
checkPoint += "a"; checkPoint += "a";
executor(undefined, function(){}); executor(undefined, function() {});
checkPoint += "b"; checkPoint += "b";
}, []); }, []);
}, "executor called with (undefined, function)"); }, "executor called with (undefined, function)");
@ -66,7 +66,7 @@ var checkPoint = "";
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
Promise.all.call(function(executor) { Promise.all.call(function(executor) {
checkPoint += "a"; checkPoint += "a";
executor(function(){}, undefined); executor(function() {}, undefined);
checkPoint += "b"; checkPoint += "b";
}, []); }, []);
}, "executor called with (function, undefined)"); }, "executor called with (function, undefined)");

View File

@ -50,7 +50,9 @@ var iter = {};
iter[Symbol.iterator] = function() { iter[Symbol.iterator] = function() {
return { return {
next: function() { next: function() {
return { done: true }; return {
done: true
};
}, },
return: function() { return: function() {
returnCount += 1; returnCount += 1;
@ -60,7 +62,9 @@ iter[Symbol.iterator] = function() {
}; };
var P = function(executor) { var P = function(executor) {
return new Promise(function(_, reject) { return new Promise(function(_, reject) {
executor(function() { throw new Test262Error(); }, reject); executor(function() {
throw new Test262Error();
}, reject);
}); });
}; };

View File

@ -48,7 +48,9 @@ flags: [async]
var thrown = new Test262Error(); var thrown = new Test262Error();
var P = function(executor) { var P = function(executor) {
return new Promise(function(_, reject) { return new Promise(function(_, reject) {
executor(function() { throw thrown; }, reject); executor(function() {
throw thrown;
}, reject);
}); });
}; };

View File

@ -33,4 +33,6 @@ Object.defineProperty(Array.prototype, 0, {
} }
}); });
Promise.all([42]).then(function(){ $DONE(); }, $DONE); Promise.all([42]).then(function() {
$DONE();
}, $DONE);

View File

@ -30,7 +30,10 @@ var callCount = 0;
iterDoneSpy[Symbol.iterator] = function() { iterDoneSpy[Symbol.iterator] = function() {
return { return {
next: function() { next: function() {
return { value: null, done: false }; return {
value: null,
done: false
};
}, },
return: function() { return: function() {
callCount += 1; callCount += 1;

View File

@ -30,7 +30,9 @@ var returnCount = 0;
iter[Symbol.iterator] = function() { iter[Symbol.iterator] = function() {
return { return {
next: function() { next: function() {
return { done: false }; return {
done: false
};
}, },
return: function() { return: function() {
returnCount += 1; returnCount += 1;

View File

@ -31,7 +31,10 @@ var iter = {};
iter[Symbol.iterator] = function() { iter[Symbol.iterator] = function() {
return { return {
next: function() { next: function() {
return { done: false, value: promise }; return {
done: false,
value: promise
};
}, },
return: function() { return: function() {
returnCount += 1; returnCount += 1;

View File

@ -31,7 +31,10 @@ var iter = {};
iter[Symbol.iterator] = function() { iter[Symbol.iterator] = function() {
return { return {
next: function() { next: function() {
return { done: false, value: promise }; return {
done: false,
value: promise
};
}, },
return: function() { return: function() {
returnCount += 1; returnCount += 1;

View File

@ -15,14 +15,17 @@ info: |
... ...
---*/ ---*/
function resolveFunction() { } function resolveFunction() {}
function Constructor(executor) { function Constructor(executor) {
executor(resolveFunction, $ERROR); executor(resolveFunction, $ERROR);
} }
Constructor.resolve = function(v) { return v; }; Constructor.resolve = function(v) {
return v;
};
var callCount1 = 0, callCount2 = 0; var callCount1 = 0,
callCount2 = 0;
var p1OnFulfilled; var p1OnFulfilled;
var p1 = { var p1 = {

View File

@ -25,7 +25,9 @@ flags: [async]
var thenable = { var thenable = {
then: function(_, reject) { then: function(_, reject) {
new Promise(function(resolve) { resolve(); }) new Promise(function(resolve) {
resolve();
})
.then(function() { .then(function() {
reject(); reject();
}); });

View File

@ -30,7 +30,9 @@ flags: [async]
var fulfiller = { var fulfiller = {
then: function(resolve) { then: function(resolve) {
new Promise(function(resolve) { resolve(); }) new Promise(function(resolve) {
resolve();
})
.then(function() { .then(function() {
resolve(); resolve();
}); });
@ -38,7 +40,9 @@ var fulfiller = {
}; };
var rejector = { var rejector = {
then: function(resolve, reject) { then: function(resolve, reject) {
new Promise(function(resolve) { resolve(); }) new Promise(function(resolve) {
resolve();
})
.then(function() { .then(function() {
resolve(); resolve();
reject(); reject();

View File

@ -39,7 +39,9 @@ function Constructor(executor) {
} }
executor(resolve, $ERROR); executor(resolve, $ERROR);
} }
Constructor.resolve = function(v) { return v; }; Constructor.resolve = function(v) {
return v;
};
var p1OnFulfilled; var p1OnFulfilled;

View File

@ -39,7 +39,9 @@ function Constructor(executor) {
} }
executor(resolve, $ERROR); executor(resolve, $ERROR);
} }
Constructor.resolve = function(v) { return v; }; Constructor.resolve = function(v) {
return v;
};
var p1OnFulfilled; var p1OnFulfilled;

View File

@ -16,10 +16,13 @@ var thenable = {
resolveElementFunction = fulfill; resolveElementFunction = fulfill;
} }
}; };
function NotPromise(executor) { function NotPromise(executor) {
executor(function(){}, function(){}); executor(function() {}, function() {});
} }
NotPromise.resolve = function(v) { return v; }; NotPromise.resolve = function(v) {
return v;
};
Promise.all.call(NotPromise, [thenable]); Promise.all.call(NotPromise, [thenable]);
assert(Object.isExtensible(resolveElementFunction)); assert(Object.isExtensible(resolveElementFunction));

View File

@ -20,10 +20,13 @@ var thenable = {
resolveElementFunction = fulfill; resolveElementFunction = fulfill;
} }
}; };
function NotPromise(executor) { function NotPromise(executor) {
executor(function(){}, function(){}); executor(function() {}, function() {});
} }
NotPromise.resolve = function(v) { return v; }; NotPromise.resolve = function(v) {
return v;
};
Promise.all.call(NotPromise, [thenable]); Promise.all.call(NotPromise, [thenable]);
assert.sameValue(resolveElementFunction.length, 1); assert.sameValue(resolveElementFunction.length, 1);

View File

@ -19,10 +19,13 @@ var thenable = {
resolveElementFunction = fulfill; resolveElementFunction = fulfill;
} }
}; };
function NotPromise(executor) { function NotPromise(executor) {
executor(function(){}, function(){}); executor(function() {}, function() {});
} }
NotPromise.resolve = function(v) { return v; }; NotPromise.resolve = function(v) {
return v;
};
Promise.all.call(NotPromise, [thenable]); Promise.all.call(NotPromise, [thenable]);
assert.sameValue(Object.prototype.hasOwnProperty.call(resolveElementFunction, "name"), false); assert.sameValue(Object.prototype.hasOwnProperty.call(resolveElementFunction, "name"), false);

View File

@ -17,11 +17,16 @@ var thenable = {
resolveElementFunction = fulfill; resolveElementFunction = fulfill;
} }
}; };
function NotPromise(executor) { function NotPromise(executor) {
executor(function(){}, function(){}); executor(function() {}, function() {});
} }
NotPromise.resolve = function(v) { return v; }; NotPromise.resolve = function(v) {
return v;
};
Promise.all.call(NotPromise, [thenable]); Promise.all.call(NotPromise, [thenable]);
assert.sameValue(Object.prototype.hasOwnProperty.call(resolveElementFunction, "prototype"), false); assert.sameValue(Object.prototype.hasOwnProperty.call(resolveElementFunction, "prototype"), false);
assert.throws(TypeError, function() { new resolveElementFunction(); }); assert.throws(TypeError, function() {
new resolveElementFunction();
});

View File

@ -18,10 +18,13 @@ var thenable = {
resolveElementFunction = fulfill; resolveElementFunction = fulfill;
} }
}; };
function NotPromise(executor) { function NotPromise(executor) {
executor(function(){}, function(){}); executor(function() {}, function() {});
} }
NotPromise.resolve = function(v) { return v; }; NotPromise.resolve = function(v) {
return v;
};
Promise.all.call(NotPromise, [thenable]); Promise.all.call(NotPromise, [thenable]);
assert.sameValue(Object.getPrototypeOf(resolveElementFunction), Function.prototype); assert.sameValue(Object.getPrototypeOf(resolveElementFunction), Function.prototype);

View File

@ -39,7 +39,9 @@ function Constructor(executor) {
} }
executor(resolve, $ERROR); executor(resolve, $ERROR);
} }
Constructor.resolve = function(v) { return v; }; Constructor.resolve = function(v) {
return v;
};
var p1OnFulfilled, p2OnFulfilled, p3OnFulfilled; var p1OnFulfilled, p2OnFulfilled, p3OnFulfilled;

View File

@ -60,12 +60,12 @@ try {
} }
promise.then(function() { promise.then(function() {
$DONE('The promise should not be fulfilled.'); $DONE('The promise should not be fulfilled.');
}, function(val) { }, function(val) {
if (val !== value) { if (val !== value) {
$DONE('The promise should be rejected with the expected value.'); $DONE('The promise should be rejected with the expected value.');
return; return;
} }
$DONE(); $DONE();
}); });

View File

@ -62,12 +62,12 @@ try {
} }
promise.then(function(val) { promise.then(function(val) {
if (val !== value) { if (val !== value) {
$DONE('The promise should be resolved with the expected value.'); $DONE('The promise should be resolved with the expected value.');
return; return;
} }
$DONE(); $DONE();
}, function() { }, function() {
$DONE('The promise should not be rejected.'); $DONE('The promise should not be rejected.');
}); });

View File

@ -13,14 +13,17 @@ info: |
... ...
---*/ ---*/
function rejectFunction() { } function rejectFunction() {}
function Constructor(executor) { function Constructor(executor) {
executor($ERROR, rejectFunction); executor($ERROR, rejectFunction);
} }
Constructor.resolve = function(v) { return v; }; Constructor.resolve = function(v) {
return v;
};
var callCount1 = 0, callCount2 = 0; var callCount1 = 0,
callCount2 = 0;
var p1 = { var p1 = {
then: function(onFulfilled, onRejected) { then: function(onFulfilled, onRejected) {

View File

@ -14,7 +14,7 @@ features: [Symbol.species]
---*/ ---*/
function C(executor) { function C(executor) {
executor(function(){}, function(){}); executor(function() {}, function() {});
} }
Object.defineProperty(C, Symbol.species, { Object.defineProperty(C, Symbol.species, {
get: function() { get: function() {

View File

@ -11,9 +11,10 @@ info: |
---*/ ---*/
var executorFunction; var executorFunction;
function NotPromise(executor) { function NotPromise(executor) {
executorFunction = executor; executorFunction = executor;
executor(function(){}, function(){}); executor(function() {}, function() {});
} }
Promise.resolve.call(NotPromise); Promise.resolve.call(NotPromise);

View File

@ -15,9 +15,10 @@ includes: [propertyHelper.js]
---*/ ---*/
var executorFunction; var executorFunction;
function NotPromise(executor) { function NotPromise(executor) {
executorFunction = executor; executorFunction = executor;
executor(function(){}, function(){}); executor(function() {}, function() {});
} }
Promise.resolve.call(NotPromise); Promise.resolve.call(NotPromise);

View File

@ -14,9 +14,10 @@ info: |
---*/ ---*/
var executorFunction; var executorFunction;
function NotPromise(executor) { function NotPromise(executor) {
executorFunction = executor; executorFunction = executor;
executor(function(){}, function(){}); executor(function() {}, function() {});
} }
Promise.resolve.call(NotPromise); Promise.resolve.call(NotPromise);

View File

@ -12,11 +12,14 @@ info: |
---*/ ---*/
var executorFunction; var executorFunction;
function NotPromise(executor) { function NotPromise(executor) {
executorFunction = executor; executorFunction = executor;
executor(function(){}, function(){}); executor(function() {}, function() {});
} }
Promise.resolve.call(NotPromise); Promise.resolve.call(NotPromise);
assert.sameValue(Object.prototype.hasOwnProperty.call(executorFunction, "prototype"), false); assert.sameValue(Object.prototype.hasOwnProperty.call(executorFunction, "prototype"), false);
assert.throws(TypeError, function() { new executorFunction(); }); assert.throws(TypeError, function() {
new executorFunction();
});

View File

@ -13,9 +13,10 @@ info: |
---*/ ---*/
var executorFunction; var executorFunction;
function NotPromise(executor) { function NotPromise(executor) {
executorFunction = executor; executorFunction = executor;
executor(function(){}, function(){}); executor(function() {}, function() {});
} }
Promise.resolve.call(NotPromise); Promise.resolve.call(NotPromise);

View File

@ -11,5 +11,5 @@ description: Promise prototype exists
---*/ ---*/
if (Promise.prototype === undefined) { if (Promise.prototype === undefined) {
$ERROR("Expected Promise.prototype to be defined."); $ERROR("Expected Promise.prototype to be defined.");
} }

View File

@ -10,6 +10,5 @@ description: Promise.prototype.constructor is the Promise constructor
---*/ ---*/
if (Promise.prototype.constructor !== Promise) { if (Promise.prototype.constructor !== Promise) {
$ERROR("Expected Promise.prototype.constructor to be Promise"); $ERROR("Expected Promise.prototype.constructor to be Promise");
} }

View File

@ -10,5 +10,5 @@ description: Promise.prototype.catch is a function
---*/ ---*/
if (!(Promise.prototype.catch instanceof Function)) { if (!(Promise.prototype.catch instanceof Function)) {
$ERROR("Expected Promise.prototype.catch to be a function"); $ERROR("Expected Promise.prototype.catch to be a function");
} }

View File

@ -12,5 +12,5 @@ description: catch is a method on a Promise
var p = Promise.resolve(3); var p = Promise.resolve(3);
if (!(p.catch instanceof Function)) { if (!(p.catch instanceof Function)) {
$ERROR("Expected p.catch to be a function"); $ERROR("Expected p.catch to be a function");
} }

View File

@ -14,11 +14,10 @@ var obj = {};
var p = Promise.resolve(obj); var p = Promise.resolve(obj);
p.catch(function () { p.catch(function() {
$ERROR("Should not be called - promise is fulfilled"); $ERROR("Should not be called - promise is fulfilled");
}).then(function (arg) { }).then(function(arg) {
if (arg !== obj) { if (arg !== obj) {
$ERROR("Expected promise to be fulfilled with obj, got " + arg); $ERROR("Expected promise to be fulfilled with obj, got " + arg);
} }
}).then($DONE, $DONE); }).then($DONE, $DONE);

View File

@ -14,11 +14,10 @@ var obj = {};
var p = Promise.reject(obj); var p = Promise.reject(obj);
p.then(function () { p.then(function() {
$ERROR("Should not be called: did not expect promise to be fulfilled"); $ERROR("Should not be called: did not expect promise to be fulfilled");
}).catch(function (arg) { }).catch(function(arg) {
if (arg !== obj) { if (arg !== obj) {
$ERROR("Should have been rejected with reason obj, got " + arg); $ERROR("Should have been rejected with reason obj, got " + arg);
} }
}).then($DONE, $DONE); }).then($DONE, $DONE);

View File

@ -24,21 +24,29 @@ features: [Symbol]
---*/ ---*/
var booleanCount = 0; var booleanCount = 0;
Boolean.prototype.then = function() { booleanCount += 1; }; Boolean.prototype.then = function() {
booleanCount += 1;
};
Promise.prototype.catch.call(true); Promise.prototype.catch.call(true);
assert.sameValue(booleanCount, 1, 'boolean'); assert.sameValue(booleanCount, 1, 'boolean');
var numberCount = 0; var numberCount = 0;
Number.prototype.then = function() { numberCount += 1; }; Number.prototype.then = function() {
numberCount += 1;
};
Promise.prototype.catch.call(34); Promise.prototype.catch.call(34);
assert.sameValue(numberCount, 1, 'number'); assert.sameValue(numberCount, 1, 'number');
var stringCount = 0; var stringCount = 0;
String.prototype.then = function() { stringCount += 1; }; String.prototype.then = function() {
stringCount += 1;
};
Promise.prototype.catch.call(''); Promise.prototype.catch.call('');
assert.sameValue(stringCount, 1, 'string'); assert.sameValue(stringCount, 1, 'string');
var symbolCount = 0; var symbolCount = 0;
Symbol.prototype.then = function() { symbolCount += 1; }; Symbol.prototype.then = function() {
symbolCount += 1;
};
Promise.prototype.catch.call(Symbol()); Promise.prototype.catch.call(Symbol());
assert.sameValue(symbolCount, 1, 'symbol'); assert.sameValue(symbolCount, 1, 'symbol');

View File

@ -38,25 +38,37 @@ assert.throws(TypeError, function() {
}, 'undefined'); }, 'undefined');
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
Promise.prototype.catch.call({ then: null }); Promise.prototype.catch.call({
then: null
});
}, 'null'); }, 'null');
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
Promise.prototype.catch.call({ then: 1 }); Promise.prototype.catch.call({
then: 1
});
}, 'number'); }, 'number');
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
Promise.prototype.catch.call({ then: '' }); Promise.prototype.catch.call({
then: ''
});
}, 'string'); }, 'string');
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
Promise.prototype.catch.call({ then: true }); Promise.prototype.catch.call({
then: true
});
}, 'boolean'); }, 'boolean');
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
Promise.prototype.catch.call({ then: symbol }); Promise.prototype.catch.call({
then: symbol
});
}, 'symbol'); }, 'symbol');
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
Promise.prototype.catch.call({ then: {} }); Promise.prototype.catch.call({
then: {}
});
}, 'ordinary object'); }, 'ordinary object');

View File

@ -7,7 +7,7 @@ esid: sec-promise.prototype.finally
features: [Promise.prototype.finally] features: [Promise.prototype.finally]
---*/ ---*/
var target = new Promise(function () {}); var target = new Promise(function() {});
var returnValue = {}; var returnValue = {};
var callCount = 0; var callCount = 0;
var thisValue = null; var thisValue = null;
@ -26,8 +26,8 @@ target.then = function(a, b) {
return returnValue; return returnValue;
}; };
var originalFinallyHandler = function () {}; var originalFinallyHandler = function() {};
var anonName = Object(function () {}).name; var anonName = Object(function() {}).name;
var result = Promise.prototype.finally.call(target, originalFinallyHandler, 2, 3); var result = Promise.prototype.finally.call(target, originalFinallyHandler, 2, 3);

View File

@ -7,7 +7,7 @@ esid: sec-promise.prototype.finally
features: [Promise.prototype.finally] features: [Promise.prototype.finally]
---*/ ---*/
var target = new Promise(function () {}); var target = new Promise(function() {});
var returnValue = {}; var returnValue = {};
var callCount = 0; var callCount = 0;
var thisValue = null; var thisValue = null;

View File

@ -11,29 +11,29 @@ includes: [promiseHelper.js]
var sequence = []; var sequence = [];
var noReason = {}; var noReason = {};
var no = Promise.reject(noReason); var no = Promise.reject(noReason);
no.then = function () { no.then = function() {
sequence.push(1); sequence.push(1);
return Promise.prototype.then.apply(this, arguments); return Promise.prototype.then.apply(this, arguments);
}; };
var yesValue = {}; var yesValue = {};
var yes = Promise.resolve(yesValue); var yes = Promise.resolve(yesValue);
yes.then = function () { yes.then = function() {
sequence.push(4); sequence.push(4);
return Promise.prototype.then.apply(this, arguments); return Promise.prototype.then.apply(this, arguments);
}; };
no.catch(function (e) { no.catch(function(e) {
sequence.push(2); sequence.push(2);
assert.sameValue(e, noReason); assert.sameValue(e, noReason);
throw e; throw e;
}).finally(function () { }).finally(function() {
sequence.push(3); sequence.push(3);
return yes; return yes;
}).catch(function (e) { }).catch(function(e) {
sequence.push(5); sequence.push(5);
assert.sameValue(e, noReason); assert.sameValue(e, noReason);
}).then(function () { }).then(function() {
checkSequence(sequence, "All expected callbacks called in correct order"); checkSequence(sequence, "All expected callbacks called in correct order");
$DONE(); $DONE();
}).catch($ERROR); }).catch($ERROR);

View File

@ -14,13 +14,13 @@ var thrown = {};
var p = Promise.reject(original); var p = Promise.reject(original);
p.finally(function () { p.finally(function() {
sequence.push(1); sequence.push(1);
assert.sameValue(arguments.length, 0, 'onFinally receives zero args'); assert.sameValue(arguments.length, 0, 'onFinally receives zero args');
throw thrown; throw thrown;
}).then(function () { }).then(function() {
$ERROR('promise is rejected; onFulfill should not be called'); $ERROR('promise is rejected; onFulfill should not be called');
}).catch(function (reason) { }).catch(function(reason) {
sequence.push(2); sequence.push(2);
assert.sameValue(reason, thrown, 'onFinally can override the rejection reason by throwing'); assert.sameValue(reason, thrown, 'onFinally can override the rejection reason by throwing');
}).then(function() { }).then(function() {

View File

@ -12,11 +12,11 @@ var sequence = [];
var obj = {}; var obj = {};
var p = Promise.resolve(obj); var p = Promise.resolve(obj);
p.finally(function () { p.finally(function() {
sequence.push(1); sequence.push(1);
assert.sameValue(arguments.length, 0, 'onFinally receives zero args'); assert.sameValue(arguments.length, 0, 'onFinally receives zero args');
return {}; return {};
}).then(function (x) { }).then(function(x) {
sequence.push(2); sequence.push(2);
assert.sameValue(x, obj, 'onFinally can not override the resolution value'); assert.sameValue(x, obj, 'onFinally can not override the resolution value');
}).then(function() { }).then(function() {

View File

@ -11,30 +11,29 @@ includes: [promiseHelper.js]
var sequence = []; var sequence = [];
var yesValue = {}; var yesValue = {};
var yes = Promise.resolve(yesValue); var yes = Promise.resolve(yesValue);
yes.then = function () { yes.then = function() {
sequence.push(1); sequence.push(1);
return Promise.prototype.then.apply(this, arguments); return Promise.prototype.then.apply(this, arguments);
}; };
var noReason = {}; var noReason = {};
var no = Promise.reject(noReason); var no = Promise.reject(noReason);
no.then = function () { no.then = function() {
sequence.push(4); sequence.push(4);
return Promise.prototype.then.apply(this, arguments); return Promise.prototype.then.apply(this, arguments);
}; };
yes.then(function (x) { yes.then(function(x) {
sequence.push(2); sequence.push(2);
assert.sameValue(x, yesValue); assert.sameValue(x, yesValue);
return x; return x;
}).finally(function () { }).finally(function() {
sequence.push(3); sequence.push(3);
return no; return no;
}).catch(function (e) { }).catch(function(e) {
sequence.push(5); sequence.push(5);
assert.sameValue(e, noReason); assert.sameValue(e, noReason);
}).then(function () { }).then(function() {
checkSequence(sequence, "All expected callbacks called in correct order"); checkSequence(sequence, "All expected callbacks called in correct order");
$DONE(); $DONE();
}).catch($ERROR); }).catch($ERROR);

View File

@ -9,12 +9,14 @@ features: [Promise.prototype.finally]
class MyPromise extends Promise { class MyPromise extends Promise {
static get [Symbol.species]() { return Promise; } static get[Symbol.species]() {
return Promise;
}
} }
var p = Promise var p = Promise
.resolve() .resolve()
.finally(() => MyPromise.resolve()); .finally(() => MyPromise.resolve());
assert.sameValue(p instanceof Promise, true); assert.sameValue(p instanceof Promise, true);
assert.sameValue(p instanceof MyPromise, false); assert.sameValue(p instanceof MyPromise, false);

View File

@ -8,7 +8,9 @@ features: [Promise.prototype.finally]
---*/ ---*/
class FooPromise extends Promise { class FooPromise extends Promise {
static get [Symbol.species]() { return Promise; } static get[Symbol.species]() {
return Promise;
}
} }
var p = Promise.reject().finally(() => FooPromise.reject()); var p = Promise.reject().finally(() => FooPromise.reject());

View File

@ -8,7 +8,9 @@ features: [Promise.prototype.finally]
---*/ ---*/
class FooPromise extends Promise { class FooPromise extends Promise {
static get [Symbol.species]() { return Promise; } static get[Symbol.species]() {
return Promise;
}
} }
var p = Promise.resolve().finally(() => FooPromise.resolve()); var p = Promise.resolve().finally(() => FooPromise.resolve());

View File

@ -11,7 +11,9 @@ features: [Promise.prototype.finally]
var called = false; var called = false;
var p = new Proxy(Promise.resolve(), {}); var p = new Proxy(Promise.resolve(), {});
var oldThen = Promise.prototype.then; var oldThen = Promise.prototype.then;
Promise.prototype.then = () => { called = true; }; Promise.prototype.then = () => {
called = true;
};
Promise.prototype.finally.call(p); Promise.prototype.finally.call(p);
assert.sameValue(called, true); assert.sameValue(called, true);
Promise.prototype.then = oldThen; Promise.prototype.then = oldThen;

View File

@ -11,9 +11,11 @@ features: [Symbol, Promise.prototype.finally]
var symbol = Symbol(); var symbol = Symbol();
var thrower = function () { throw new Test262Error('this should never happen'); }; var thrower = function() {
throw new Test262Error('this should never happen');
};
var p = new Promise(function () {}); var p = new Promise(function() {});
p.then = undefined; p.then = undefined;
assert.throws(TypeError, function() { assert.throws(TypeError, function() {

View File

@ -9,7 +9,7 @@ esid: sec-promise.prototype.finally
features: [Promise.prototype.finally] features: [Promise.prototype.finally]
---*/ ---*/
var poisonedThen = Object.defineProperty(new Promise(function () {}), 'then', { var poisonedThen = Object.defineProperty(new Promise(function() {}), 'then', {
get: function() { get: function() {
throw new Test262Error(); throw new Test262Error();
} }

View File

@ -9,7 +9,7 @@ esid: sec-promise.prototype.finally
features: [Promise.prototype.finally] features: [Promise.prototype.finally]
---*/ ---*/
var thrower = new Promise(function () {}); var thrower = new Promise(function() {});
thrower.then = function() { thrower.then = function() {
throw new Test262Error(); throw new Test262Error();
}; };

View File

@ -14,27 +14,27 @@ flags: [async]
var sequence = []; var sequence = [];
var p = new Promise(function(resolve, reject){ var p = new Promise(function(resolve, reject) {
sequence.push(1); sequence.push(1);
resolve(""); resolve("");
}); });
p.then(function () { p.then(function() {
sequence.push(3); sequence.push(3);
}).then(function () { }).then(function() {
sequence.push(5); sequence.push(5);
}).then(function () { }).then(function() {
sequence.push(7); sequence.push(7);
}); });
p.then(function () { p.then(function() {
sequence.push(4); sequence.push(4);
}).then(function () { }).then(function() {
sequence.push(6); sequence.push(6);
}).then(function () { }).then(function() {
sequence.push(8); sequence.push(8);
}).then(function () { }).then(function() {
checkSequence(sequence, "Sequence should be as expected"); checkSequence(sequence, "Sequence should be as expected");
}).then($DONE, $DONE); }).then($DONE, $DONE);
sequence.push(2); sequence.push(2);

View File

@ -15,18 +15,18 @@ flags: [async]
var resolveP1, rejectP2, sequence = []; var resolveP1, rejectP2, sequence = [];
(new Promise(function (resolve, reject) { (new Promise(function(resolve, reject) {
resolveP1 = resolve; resolveP1 = resolve;
})).then(function (msg) { })).then(function(msg) {
sequence.push(msg); sequence.push(msg);
}).then(function () { }).then(function() {
checkSequence(sequence, "Expected 1,2,3"); checkSequence(sequence, "Expected 1,2,3");
}).then($DONE, $DONE); }).then($DONE, $DONE);
(new Promise(function (resolve, reject) { (new Promise(function(resolve, reject) {
rejectP2 = reject; rejectP2 = reject;
})).catch(function (msg) { })).catch(function(msg) {
sequence.push(msg); sequence.push(msg);
}); });
rejectP2(2); rejectP2(2);

View File

@ -14,26 +14,26 @@ flags: [async]
---*/ ---*/
var resolveP1, rejectP2, p1, p2, var resolveP1, rejectP2, p1, p2,
sequence = []; sequence = [];
p1 = new Promise(function (resolve, reject) { p1 = new Promise(function(resolve, reject) {
resolveP1 = resolve; resolveP1 = resolve;
}); });
p2 = new Promise(function (resolve, reject) { p2 = new Promise(function(resolve, reject) {
rejectP2 = reject; rejectP2 = reject;
}); });
rejectP2(3); rejectP2(3);
resolveP1(2); resolveP1(2);
p1.then(function (msg) { p1.then(function(msg) {
sequence.push(msg); sequence.push(msg);
}); });
p2.catch(function (msg) { p2.catch(function(msg) {
sequence.push(msg); sequence.push(msg);
}).then(function () { }).then(function() {
checkSequence(sequence, "Expected 1,2,3"); checkSequence(sequence, "Expected 1,2,3");
}).then($DONE, $DONE); }).then($DONE, $DONE);
sequence.push(1); sequence.push(1);

View File

@ -14,30 +14,28 @@ flags: [async]
---*/ ---*/
var resolveP1, rejectP2, p1, p2, var resolveP1, rejectP2, p1, p2,
sequence = []; sequence = [];
p1 = new Promise(function (resolve, reject) { p1 = new Promise(function(resolve, reject) {
resolveP1 = resolve; resolveP1 = resolve;
}); });
p2 = new Promise(function (resolve, reject) { p2 = new Promise(function(resolve, reject) {
rejectP2 = reject; rejectP2 = reject;
}); });
rejectP2(3); rejectP2(3);
resolveP1(2); resolveP1(2);
Promise.resolve().then(function () { Promise.resolve().then(function() {
p1.then(function (msg) { p1.then(function(msg) {
sequence.push(msg); sequence.push(msg);
}); });
p2.catch(function (msg) { p2.catch(function(msg) {
sequence.push(msg); sequence.push(msg);
}).then(function () { }).then(function() {
checkSequence(sequence, "Expected 1,2,3"); checkSequence(sequence, "Expected 1,2,3");
}).then($DONE, $DONE); }).then($DONE, $DONE);
}); });
sequence.push(1); sequence.push(1);

View File

@ -10,5 +10,5 @@ description: Promise.prototype.then is a function of two arguments
---*/ ---*/
if (!(Promise.prototype.then instanceof Function)) { if (!(Promise.prototype.then instanceof Function)) {
$ERROR("Expected Promise.prototype.then to be a function"); $ERROR("Expected Promise.prototype.then to be a function");
} }

View File

@ -9,14 +9,12 @@ author: Sam Mikes
description: Promise.prototype.then is a function of two arguments description: Promise.prototype.then is a function of two arguments
---*/ ---*/
var p = new Promise(function () {}); var p = new Promise(function() {});
if (!(p.then instanceof Function)) { if (!(p.then instanceof Function)) {
$ERROR("Expected p.then to be a function"); $ERROR("Expected p.then to be a function");
} }
if (p.then.length !== 2) { if (p.then.length !== 2) {
$ERROR("Expected p.then to be a function of two arguments"); $ERROR("Expected p.then to be a function of two arguments");
} }

View File

@ -9,8 +9,8 @@ author: Sam Mikes
description: Promise.prototype.then throw if 'this' is non-Object description: Promise.prototype.then throw if 'this' is non-Object
---*/ ---*/
var p = new Promise(function () {}); var p = new Promise(function() {});
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
p.then.call(3, function () {}, function () {}); p.then.call(3, function() {}, function() {});
}); });

View File

@ -9,11 +9,10 @@ author: Sam Mikes
description: Promise.prototype.then throw if 'this' is non-Promise Object description: Promise.prototype.then throw if 'this' is non-Promise Object
---*/ ---*/
function ZeroArgConstructor() { function ZeroArgConstructor() {}
}
var z = new ZeroArgConstructor(); var z = new ZeroArgConstructor();
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
Promise.then.call(z, function () {}, function () {}); Promise.then.call(z, function() {}, function() {});
}); });

View File

@ -15,8 +15,8 @@ var obj = {};
var p = Promise.resolve(obj); var p = Promise.resolve(obj);
p.then(undefined, undefined) p.then(undefined, undefined)
.then(function (arg) { .then(function(arg) {
if (arg !== obj) { if (arg !== obj) {
$ERROR("Expected resolution object to be passed through, got " + arg); $ERROR("Expected resolution object to be passed through, got " + arg);
} }
}).then($DONE, $DONE); }).then($DONE, $DONE);

View File

@ -14,10 +14,10 @@ flags: [async]
var obj = {}; var obj = {};
var p = Promise.reject(obj); var p = Promise.reject(obj);
p.then(undefined, undefined).then(function () { p.then(undefined, undefined).then(function() {
$ERROR("Should not be called -- promise was rejected."); $ERROR("Should not be called -- promise was rejected.");
}, function (arg) { }, function(arg) {
if (arg !== obj) { if (arg !== obj) {
$ERROR("Expected resolution object to be passed through, got " + arg); $ERROR("Expected resolution object to be passed through, got " + arg);
} }
}).then($DONE, $DONE); }).then($DONE, $DONE);

View File

@ -15,8 +15,8 @@ var obj = {};
var p = Promise.resolve(obj); var p = Promise.resolve(obj);
p.then(3, 5) p.then(3, 5)
.then(function (arg) { .then(function(arg) {
if (arg !== obj) { if (arg !== obj) {
$ERROR("Expected resolution object to be passed through, got " + arg); $ERROR("Expected resolution object to be passed through, got " + arg);
} }
}).then($DONE, $DONE); }).then($DONE, $DONE);

View File

@ -14,10 +14,10 @@ flags: [async]
var obj = {}; var obj = {};
var p = Promise.reject(obj); var p = Promise.reject(obj);
p.then(3, 5).then(function () { p.then(3, 5).then(function() {
$ERROR("Should not be called -- promise was rejected."); $ERROR("Should not be called -- promise was rejected.");
}, function (arg) { }, function(arg) {
if (arg !== obj) { if (arg !== obj) {
$ERROR("Expected resolution object to be passed through, got " + arg); $ERROR("Expected resolution object to be passed through, got " + arg);
} }
}).then($DONE, $DONE); }).then($DONE, $DONE);

View File

@ -13,27 +13,27 @@ flags: [async]
---*/ ---*/
var sequence = [], var sequence = [],
pResolve, pResolve,
p = new Promise(function (resolve, reject) { p = new Promise(function(resolve, reject) {
pResolve = resolve; pResolve = resolve;
}); });
sequence.push(1); sequence.push(1);
p.then(function () { p.then(function() {
sequence.push(3); sequence.push(3);
checkSequence(sequence, "Should be second"); checkSequence(sequence, "Should be second");
}).catch($DONE); }).catch($DONE);
Promise.resolve().then(function () { Promise.resolve().then(function() {
// enqueue another then-handler // enqueue another then-handler
p.then(function () { p.then(function() {
sequence.push(4); sequence.push(4);
checkSequence(sequence, "Should be third"); checkSequence(sequence, "Should be third");
}).then($DONE, $DONE); }).then($DONE, $DONE);
sequence.push(2); sequence.push(2);
checkSequence(sequence, "Should be first"); checkSequence(sequence, "Should be first");
pResolve(); pResolve();
}).catch($DONE); }).catch($DONE);

View File

@ -13,29 +13,29 @@ flags: [async]
---*/ ---*/
var sequence = [], var sequence = [],
pResolve, pResolve,
p = new Promise(function (resolve, reject) { p = new Promise(function(resolve, reject) {
pResolve = resolve; pResolve = resolve;
}); });
sequence.push(1); sequence.push(1);
pResolve(); pResolve();
p.then(function () { p.then(function() {
sequence.push(3); sequence.push(3);
checkSequence(sequence, "Should be first"); checkSequence(sequence, "Should be first");
}).catch($DONE); }).catch($DONE);
Promise.resolve().then(function () { Promise.resolve().then(function() {
// enqueue another then-handler // enqueue another then-handler
p.then(function () { p.then(function() {
sequence.push(5); sequence.push(5);
checkSequence(sequence, "Should be third"); checkSequence(sequence, "Should be third");
}).then($DONE, $DONE); }).then($DONE, $DONE);
sequence.push(4); sequence.push(4);
checkSequence(sequence, "Should be second"); checkSequence(sequence, "Should be second");
}).catch($DONE); }).catch($DONE);
sequence.push(2); sequence.push(2);

View File

@ -13,33 +13,33 @@ flags: [async]
---*/ ---*/
var sequence = [], var sequence = [],
pReject, pReject,
p = new Promise(function (resolve, reject) { p = new Promise(function(resolve, reject) {
pReject = reject; pReject = reject;
}); });
sequence.push(1); sequence.push(1);
pReject(); pReject();
p.then(function () { p.then(function() {
$ERROR("Should not be called -- Promise rejected."); $ERROR("Should not be called -- Promise rejected.");
}, function () { }, function() {
sequence.push(3); sequence.push(3);
checkSequence(sequence, "Should be first"); checkSequence(sequence, "Should be first");
}).catch($DONE); }).catch($DONE);
Promise.resolve().then(function () { Promise.resolve().then(function() {
// enqueue another then-handler // enqueue another then-handler
p.then(function () { p.then(function() {
$ERROR("Should not be called (2) -- Promise rejected."); $ERROR("Should not be called (2) -- Promise rejected.");
}, function () { }, function() {
sequence.push(5); sequence.push(5);
checkSequence(sequence, "Should be third"); checkSequence(sequence, "Should be third");
}).then($DONE, $DONE); }).then($DONE, $DONE);
sequence.push(4); sequence.push(4);
checkSequence(sequence, "Should be second"); checkSequence(sequence, "Should be second");
}).catch($DONE); }).catch($DONE);
sequence.push(2); sequence.push(2);

View File

@ -33,14 +33,14 @@ var promise = new class extends Promise {
} }
return super(executor); return super(executor);
} }
}(function(){}); }(function() {});
var checkPoint = ""; var checkPoint = "";
constructorFunction = function(executor) { constructorFunction = function(executor) {
checkPoint += "a"; checkPoint += "a";
executor(); executor();
checkPoint += "b"; checkPoint += "b";
executor(function(){}, function(){}); executor(function() {}, function() {});
checkPoint += "c"; checkPoint += "c";
}; };
promise.then(); promise.then();
@ -51,7 +51,7 @@ constructorFunction = function(executor) {
checkPoint += "a"; checkPoint += "a";
executor(undefined, undefined); executor(undefined, undefined);
checkPoint += "b"; checkPoint += "b";
executor(function(){}, function(){}); executor(function() {}, function() {});
checkPoint += "c"; checkPoint += "c";
}; };
promise.then(); promise.then();
@ -61,9 +61,9 @@ var checkPoint = "";
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
constructorFunction = function(executor) { constructorFunction = function(executor) {
checkPoint += "a"; checkPoint += "a";
executor(undefined, function(){}); executor(undefined, function() {});
checkPoint += "b"; checkPoint += "b";
executor(function(){}, function(){}); executor(function() {}, function() {});
checkPoint += "c"; checkPoint += "c";
}; };
promise.then(); promise.then();
@ -74,9 +74,9 @@ var checkPoint = "";
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
constructorFunction = function(executor) { constructorFunction = function(executor) {
checkPoint += "a"; checkPoint += "a";
executor(function(){}, undefined); executor(function() {}, undefined);
checkPoint += "b"; checkPoint += "b";
executor(function(){}, function(){}); executor(function() {}, function() {});
checkPoint += "c"; checkPoint += "c";
}; };
promise.then(); promise.then();
@ -89,7 +89,7 @@ assert.throws(TypeError, function() {
checkPoint += "a"; checkPoint += "a";
executor("invalid value", 123); executor("invalid value", 123);
checkPoint += "b"; checkPoint += "b";
executor(function(){}, function(){}); executor(function() {}, function() {});
checkPoint += "c"; checkPoint += "c";
}; };
promise.then(); promise.then();

View File

@ -35,7 +35,7 @@ var promise = new class extends Promise {
} }
return super(executor); return super(executor);
} }
}(function(){}); }(function() {});
var checkPoint = ""; var checkPoint = "";
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
@ -72,7 +72,7 @@ var checkPoint = "";
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
constructorFunction = function(executor) { constructorFunction = function(executor) {
checkPoint += "a"; checkPoint += "a";
executor(undefined, function(){}); executor(undefined, function() {});
checkPoint += "b"; checkPoint += "b";
}; };
promise.then(); promise.then();
@ -83,7 +83,7 @@ var checkPoint = "";
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
constructorFunction = function(executor) { constructorFunction = function(executor) {
checkPoint += "a"; checkPoint += "a";
executor(function(){}, undefined); executor(function() {}, undefined);
checkPoint += "b"; checkPoint += "b";
}; };
promise.then(); promise.then();

View File

@ -29,7 +29,9 @@ flags: [async]
---*/ ---*/
var callCount = 0; var callCount = 0;
var prms = new Promise(function(resolve) { resolve(); }); var prms = new Promise(function(resolve) {
resolve();
});
Object.defineProperty(prms, 'constructor', { Object.defineProperty(prms, 'constructor', {
get: function() { get: function() {
callCount += 1; callCount += 1;
@ -38,12 +40,12 @@ Object.defineProperty(prms, 'constructor', {
}); });
prms.then(function() { prms.then(function() {
if (callCount !== 1) { if (callCount !== 1) {
$DONE('Expected constructor access count: 1. Actual: ' + callCount); $DONE('Expected constructor access count: 1. Actual: ' + callCount);
return; return;
} }
$DONE(); $DONE();
}, function() { }, function() {
$DONE('The promise should not be rejected.'); $DONE('The promise should not be rejected.');
}); });

View File

@ -13,9 +13,9 @@ description: Promise.prototype.then throws if Get(promise, "constructor") throws
var p = Promise.resolve("foo"); var p = Promise.resolve("foo");
Object.defineProperty(p, "constructor", { Object.defineProperty(p, "constructor", {
get: function () { get: function() {
throw new Test262Error(); throw new Test262Error();
} }
}); });
assert.throws(Test262Error, function() { assert.throws(Test262Error, function() {

View File

@ -26,10 +26,14 @@ var BadCtor = function() {
}; };
var originalSpecies = Object.getOwnPropertyDescriptor(Promise, Symbol.species); var originalSpecies = Object.getOwnPropertyDescriptor(Promise, Symbol.species);
Object.defineProperty(Promise, Symbol.species, { value: BadCtor }); Object.defineProperty(Promise, Symbol.species, {
value: BadCtor
});
try { try {
var p = new Promise(function(resolve) { resolve(); }); var p = new Promise(function(resolve) {
resolve();
});
assert.throws(Test262Error, function() { assert.throws(Test262Error, function() {
p.then(); p.then();

View File

@ -20,14 +20,16 @@ flags: [async]
---*/ ---*/
var value = {}; var value = {};
var p = new Promise(function(resolve) { resolve(value); }); var p = new Promise(function(resolve) {
resolve(value);
});
p.then(function(x) { p.then(function(x) {
if (x !== value) { if (x !== value) {
$DONE('The `onFulfilled` handler should be invoked with the promise result.'); $DONE('The `onFulfilled` handler should be invoked with the promise result.');
return; return;
} }
$DONE(); $DONE();
}, function() { }, function() {
$DONE('The `onRejected` handler should not be invoked.'); $DONE('The `onRejected` handler should not be invoked.');
}); });

Some files were not shown because too many files have changed in this diff Show More