Skip to content
Snippets Groups Projects
Commit 26787ab0 authored by smikes's avatar smikes
Browse files

add tests for 24.4.4.1 - Promise.all

add more tests of Promise.all

additional Promise test

add tests of Promise.prototype

add some tests for Promise.race

additional Promise tests

add Promise.reject and Promise.resolve tests

correct test description

rename badly-named files

use current license and minor style cleanup

correct understanding of undefined as thisArgument

incorporate line notes

Is this enough to make a constructor in ES6?

more accurate use of resolved,fulfilled etc.
remove some redundant tests
add new tests

remove "constant array" unclear language

better description

Update S25.4.2.1_A3.2_T1.js

address dangling ()

changes per @anba line notes
 - if GetIterator is abrupt, the Promise.race / Promise.all should reject
 - if Promise.race is called with nonconforming constructor as 'this',
   TypeError should be thrown (cannot reject if exeption is thrown from
   NewPromiseCapability; no promise exists yet...)

correct description of "this" testing in callbacks

fix whitespace, formatting

remove tab
add "next-turn" checking to sequencers
parent 61113dbf
No related branches found
No related tags found
No related merge requests found
Showing
with 276 additions and 62 deletions
// Copyright 2014 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: >
Promise reaction jobs have predictable environment
author: Sam Mikes
description: argument passes through "Identity"
---*/
var obj = {};
var p = Promise.resolve(obj).then(/*Identity, Thrower*/)
.then(function (arg) {
if (arg !== obj) {
$ERROR("Expected promise to be fulfilled with obj, actually " + arg);
}
}).then($DONE, $DONE);
// Copyright 2014 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: >
Promise reaction jobs have predictable environment
author: Sam Mikes
description: argument thrown through "Thrower"
---*/
var obj = {};
var p = Promise.reject(obj).then(/*Identity, Thrower*/)
.then(function () {
$ERROR("Unexpected fulfillment - promise should reject.");
}, function (arg) {
if (arg !== obj) {
$ERROR("Expected reject reason to be obj, actually " + arg);
}
}).then($DONE, $DONE);
// Copyright 2014 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: >
Promise reaction jobs have predictable environment
author: Sam Mikes
description: Promise.onFulfilled gets undefined as 'this'
---*/
var expectedThis,
obj = {};
(function () { expectedThis = this; }());
var p = Promise.resolve(obj).then(function(arg) {
if (this !== expectedThis) {
$ERROR("'this' must be same as for function called without explicit this got " + this);
}
if (arg !== obj) {
$ERROR("Expected promise to be fulfilled by obj, actually " + arg);
}
}).then($DONE, $DONE);
// Copyright 2014 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: >
Promise reaction jobs have predictable environment
'this' is global object in sloppy mode,
undefined in strict mode
author: Sam Mikes
description: onRejected gets default 'this'
---*/
var expectedThis,
obj = {};
(function () { expectedThis = this; }());
var p = Promise.reject(obj).then(function () {
$ERROR("Unexpected fulfillment; expected rejection.");
}, function(arg) {
if (this !== expectedThis) {
$ERROR("'this' must be same as for function called without explicit this, got " + this);
}
if (arg !== obj) {
$ERROR("Expected promise to be rejected with obj, actually " + arg);
}
}).then($DONE, $DONE);
// Copyright 2014 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: >
Promise is the Promise property of the global object
author: Sam Mikes
description: Promise === global.Promise
includes: [fnGlobalObject.js]
---*/
var global = fnGlobalObject();
if (Promise !== global.Promise) {
$ERROR("Expected Promise === global.Promise.");
}
// Copyright 2014 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: >
Promise throws TypeError when 'this' is not Object
author: Sam Mikes
description: Promise.call("non-object") throws TypeError
negative: TypeError
---*/
Promise.call("non-object", function () {});
// Copyright 2014 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: >
Promise throws TypeError when 'this' is constructed but unsettled promise
author: Sam Mikes
description: Promise.call(new Promise()) throws TypeError
negative: TypeError
---*/
var p = new Promise(function() {});
Promise.call(p, function () {});
// Copyright 2014 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: >
Promise throws TypeError when 'this' is resolved promise
author: Sam Mikes
description: Promise.call(resolved Promise) throws TypeError
---*/
var p = new Promise(function(resolve) { resolve(1); });
p.then(function () {
Promise.call(p, function () {});
}).then(function () {
$ERROR("Unexpected resolution - expected TypeError");
}, function (err) {
if (!(err instanceof TypeError)) {
$ERROR("Expected TypeError, got " + err);
}
}).then($DONE, $DONE);
// Copyright 2014 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: >
Promise throws TypeError when 'this' is rejected promise
author: Sam Mikes
description: Promise.call(rejected Promise) throws TypeError
---*/
var p = new Promise(function(resolve, reject) { reject(1) });
p.catch(function () {
Promise.call(p, function () {});
}).then(function () {
$ERROR("Unexpected resolution - expected TypeError");
}, function (err) {
if (!(err instanceof TypeError)) {
$ERROR("Expected TypeError, got " + err);
}
}).then($DONE, $DONE);
// Copyright 2014 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: >
Promise throws TypeError when executor is not callable
author: Sam Mikes
description: new Promise("not callable") throws TypeError
negative: TypeError
---*/
new Promise("not callable");
// Copyright 2014 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: >
Promise catches exceptions thrown from executor and turns
them into reject
author: Sam Mikes
description: new Promise(function () { throw }) should reject
---*/
var errorObject = {},
p = new Promise(function () {
throw errorObject;
});
p.then(function() {
$ERROR("Unexpected fulfill -- promise should reject.");
}, function (err) {
if (err !== errorObject) {
$ERROR("Expected promise rejection reason to be thrown errorObject, actually " + err);
}
}).then($DONE, $DONE);
// Copyright 2014 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: >
Promise executor has predictable environment
'this' should be global object in sloppy mode,
undefined in strict mode
author: Sam Mikes
description: Promise executor gets default handling for 'this'
---*/
var expectedThis;
(function () { expectedThis = this; }());
var p = new Promise(function (resolve) {
if (this !== expectedThis) {
$ERROR("'this' must be same as for function called without explicit this, got " + this);
}
resolve();
}).then($DONE, $DONE);
// Copyright 2014 Ecma International. All rights reserved.
// Ecma International makes this code available under the terms and conditions set
// forth on http://hg.ecmascript.org/tests/test262/raw-file/tip/LICENSE (the
// "Use Terms"). Any redistribution of this code must retain the above
// copyright and this notice and otherwise comply with the Use Terms.
// Copyright 2014 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: Promise.all is callable
es5id: 25.4.4.1_A1.1_T1
author: Sam Mikes
description: Promise.all is callable
---*/
// CHECK#1
var x = typeof Promise.all;
if (x !== "function") {
$ERROR('#1: x = typeof Promise.all; x === "function". Actual: ' + (x));
if ((typeof Promise.all) !== "function") {
$ERROR('Expected Promise.all to be a function');
}
// Copyright 2012 Ecma International. All rights reserved.
// Ecma International makes this code available under the terms and conditions set
// forth on http://hg.ecmascript.org/tests/test262/raw-file/tip/LICENSE (the
// "Use Terms"). Any redistribution of this code must retain the above
// copyright and this notice and otherwise comply with the Use Terms.
// Copyright 2014 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: Promise.all expects 1 argument
es5id: 25.4.4.1_A1.2_T1
author: Sam Mikes
description: Promise.all expects 1 argument
---*/
// CHECK#1
var x = Promise.all.length;
if (x !== 1) {
$ERROR('#1: x = Promise.all.length; x === 1. Actual: ' + (x));
if (Promise.all.length !== 1) {
$ERROR('Expected Promise.all to be a function of one argument.');
}
// Copyright 2014 Ecma International. All rights reserved.
// Ecma International makes this code available under the terms and conditions set
// forth on http://hg.ecmascript.org/tests/test262/raw-file/tip/LICENSE (the
// "Use Terms"). Any redistribution of this code must retain the above
// copyright and this notice and otherwise comply with the Use Terms.
// Copyright 2014 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: Promise.all([]) is a Promise
es5id: 25.4.4.1_A2.1_T1
author: Sam Mikes
description: Promise.all returns a Promise
---*/
// CHECK#1
var x = (Promise.all([]) instanceof Promise);
if (x !== true) {
$ERROR('#1: x (Promise.all([]) instanceof Promise); x === true. Actual: ' + (x));
var p = Promise.all([]);
if (!(p instanceof Promise)) {
$ERROR('Expected p to be a Promise');
}
// Copyright 2014 Ecma International. All rights reserved.
// Ecma International makes this code available under the terms and conditions set
// forth on http://hg.ecmascript.org/tests/test262/raw-file/tip/LICENSE (the
// "Use Terms"). Any redistribution of this code must retain the above
// copyright and this notice and otherwise comply with the Use Terms.
// Copyright 2014 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: Promise.all([]) is resolved immediately
es5id: 25.4.4.1_A2.2_T1
author: Sam Mikes
includes: [PromiseHelper.js]
description: Promise.all([]) returns immediately
---*/
var sequence = [];
Promise.all([]).then(function () {
sequence.push(1);
sequence.push(2);
}).catch($DONE);
Promise.resolve().then(function() {
sequence.push(2);
}).then(function () {
sequence.push(3);
}).then(function () {
sequence.push(4);
checkSequence(sequence, "Promises resolved in unexpected sequence");
}).then($DONE,$DONE);
}).then($DONE, $DONE);
sequence.push(1);
// Copyright 2014 Ecma International. All rights reserved.
// Ecma International makes this code available under the terms and conditions set
// forth on http://hg.ecmascript.org/tests/test262/raw-file/tip/LICENSE (the
// "Use Terms"). Any redistribution of this code must retain the above
// copyright and this notice and otherwise comply with the Use Terms.
// Copyright 2014 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: Promise.all is resolved with a new empty array
info: Promise.all([]) returns a promise for a new empty array
es5id: 25.4.4.1_A2.3_T1
author: Sam Mikes
description: Promise.all([]) returns a promise for an array
---*/
var arg = [];
Promise.all(arg).then(function (result) {
if((result instanceof Array) !== true) {
if(!(result instanceof Array)) {
$ERROR("expected an array from Promise.all, got " + result);
}
}).then($DONE,$DONE);
}).then($DONE, $DONE);
// Copyright 2014 Ecma International. All rights reserved.
// Ecma International makes this code available under the terms and conditions set
// forth on http://hg.ecmascript.org/tests/test262/raw-file/tip/LICENSE (the
// "Use Terms"). Any redistribution of this code must retain the above
// copyright and this notice and otherwise comply with the Use Terms.
// Copyright 2014 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: Promise.all is resolved with a new empty array
es5id: 25.4.4.1_A2.3_T2
author: Sam Mikes
description: Promise.all([]) returns a Promise for an empty array
---*/
var arg = [];
......@@ -16,4 +14,4 @@ Promise.all(arg).then(function (result) {
if(result.length !== 0) {
$ERROR("expected an empty array from Promise.all([]), got " + result);
}
}).then($DONE,$DONE);
}).then($DONE, $DONE);
// Copyright 2014 Ecma International. All rights reserved.
// Ecma International makes this code available under the terms and conditions set
// forth on http://hg.ecmascript.org/tests/test262/raw-file/tip/LICENSE (the
// "Use Terms"). Any redistribution of this code must retain the above
// copyright and this notice and otherwise comply with the Use Terms.
// Copyright 2014 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: Promise.all is resolved with a new empty array
info: Promise.all([]) is resolved with Promise for a new empty array
es5id: 25.4.4.1_A2.3_T3
author: Sam Mikes
description: Promise.all([]) is resolved with a Promise for a new array
---*/
var arg = [];
......@@ -16,4 +14,4 @@ Promise.all(arg).then(function (result) {
if(result === arg) {
$ERROR("expected a new array from Promise.all but argument was re-used");
}
}).then($DONE,$DONE);
}).then($DONE, $DONE);
// Copyright 2014 Ecma International. All rights reserved.
// Ecma International makes this code available under the terms and conditions set
// forth on http://hg.ecmascript.org/tests/test262/raw-file/tip/LICENSE (the
// "Use Terms"). Any redistribution of this code must retain the above
// copyright and this notice and otherwise comply with the Use Terms.
// Copyright 2014 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: >
......@@ -11,6 +8,7 @@ info: >
ref 7.4.2 GetIterator throws TypeError if CheckIterable fails
es5id: 25.4.4.1_A3.1_T1
author: Sam Mikes
description: Promise.all(3) returns Promise rejected with TypeError
---*/
var nonIterable = 3;
......@@ -21,4 +19,4 @@ Promise.all(nonIterable).then(function () {
if (!(err instanceof TypeError)) {
$ERROR('Expected TypeError, got ' + err);
}
}).then($DONE,$DONE);
}).then($DONE, $DONE);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment