diff --git a/test/suite/es6/ch25/25.4/25.4.2/25.4.2.1/S25.4.2.1_A1.1_T1.js b/test/suite/es6/ch25/25.4/25.4.2/25.4.2.1/S25.4.2.1_A1.1_T1.js new file mode 100644 index 0000000000..064dac8c9e --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.2/25.4.2.1/S25.4.2.1_A1.1_T1.js @@ -0,0 +1,18 @@ +// 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); diff --git a/test/suite/es6/ch25/25.4/25.4.2/25.4.2.1/S25.4.2.1_A2.1_T1.js b/test/suite/es6/ch25/25.4/25.4.2/25.4.2.1/S25.4.2.1_A2.1_T1.js new file mode 100644 index 0000000000..f093629775 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.2/25.4.2.1/S25.4.2.1_A2.1_T1.js @@ -0,0 +1,20 @@ +// 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); diff --git a/test/suite/es6/ch25/25.4/25.4.2/25.4.2.1/S25.4.2.1_A3.1_T1.js b/test/suite/es6/ch25/25.4/25.4.2/25.4.2.1/S25.4.2.1_A3.1_T1.js new file mode 100644 index 0000000000..39ac61f1f1 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.2/25.4.2.1/S25.4.2.1_A3.1_T1.js @@ -0,0 +1,23 @@ +// 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); diff --git a/test/suite/es6/ch25/25.4/25.4.2/25.4.2.1/S25.4.2.1_A3.2_T1.js b/test/suite/es6/ch25/25.4/25.4.2/25.4.2.1/S25.4.2.1_A3.2_T1.js new file mode 100644 index 0000000000..2a0f5fdddc --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.2/25.4.2.1/S25.4.2.1_A3.2_T1.js @@ -0,0 +1,28 @@ +// 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); diff --git a/test/suite/es6/ch25/25.4/25.4.3/25.4.3.1/S25.4.3.1_A1.1_T1.js b/test/suite/es6/ch25/25.4/25.4.3/25.4.3.1/S25.4.3.1_A1.1_T1.js new file mode 100644 index 0000000000..e225c49034 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.3/25.4.3.1/S25.4.3.1_A1.1_T1.js @@ -0,0 +1,16 @@ +// 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."); +} diff --git a/test/suite/es6/ch25/25.4/25.4.3/25.4.3.1/S25.4.3.1_A2.1_T1.js b/test/suite/es6/ch25/25.4/25.4.3/25.4.3.1/S25.4.3.1_A2.1_T1.js new file mode 100644 index 0000000000..79637f68d7 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.3/25.4.3.1/S25.4.3.1_A2.1_T1.js @@ -0,0 +1,12 @@ +// 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 () {}); diff --git a/test/suite/es6/ch25/25.4/25.4.3/25.4.3.1/S25.4.3.1_A2.2_T1.js b/test/suite/es6/ch25/25.4/25.4.3/25.4.3.1/S25.4.3.1_A2.2_T1.js new file mode 100644 index 0000000000..93e69c395d --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.3/25.4.3.1/S25.4.3.1_A2.2_T1.js @@ -0,0 +1,14 @@ +// 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 () {}); diff --git a/test/suite/es6/ch25/25.4/25.4.3/25.4.3.1/S25.4.3.1_A2.3_T1.js b/test/suite/es6/ch25/25.4/25.4.3/25.4.3.1/S25.4.3.1_A2.3_T1.js new file mode 100644 index 0000000000..9d741cc94c --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.3/25.4.3.1/S25.4.3.1_A2.3_T1.js @@ -0,0 +1,21 @@ +// 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); diff --git a/test/suite/es6/ch25/25.4/25.4.3/25.4.3.1/S25.4.3.1_A2.4_T1.js b/test/suite/es6/ch25/25.4/25.4.3/25.4.3.1/S25.4.3.1_A2.4_T1.js new file mode 100644 index 0000000000..13d2abd36a --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.3/25.4.3.1/S25.4.3.1_A2.4_T1.js @@ -0,0 +1,21 @@ +// 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); diff --git a/test/suite/es6/ch25/25.4/25.4.3/25.4.3.1/S25.4.3.1_A3.1_T1.js b/test/suite/es6/ch25/25.4/25.4.3/25.4.3.1/S25.4.3.1_A3.1_T1.js new file mode 100644 index 0000000000..c89edcaf52 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.3/25.4.3.1/S25.4.3.1_A3.1_T1.js @@ -0,0 +1,12 @@ +// 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"); diff --git a/test/suite/es6/ch25/25.4/25.4.3/25.4.3.1/S25.4.3.1_A4.1_T1.js b/test/suite/es6/ch25/25.4/25.4.3/25.4.3.1/S25.4.3.1_A4.1_T1.js new file mode 100644 index 0000000000..4a633214b0 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.3/25.4.3.1/S25.4.3.1_A4.1_T1.js @@ -0,0 +1,24 @@ +// 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); + diff --git a/test/suite/es6/ch25/25.4/25.4.3/25.4.3.1/S25.4.3.1_A5.1_T1.js b/test/suite/es6/ch25/25.4/25.4.3/25.4.3.1/S25.4.3.1_A5.1_T1.js new file mode 100644 index 0000000000..d4d2dbb4fc --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.3/25.4.3.1/S25.4.3.1_A5.1_T1.js @@ -0,0 +1,23 @@ +// 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); diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A1.1_T1.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A1.1_T1.js index 353ff861f9..89fa820ef7 100644 --- a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A1.1_T1.js +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A1.1_T1.js @@ -1,17 +1,13 @@ -// 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'); } diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A1.2_T1.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A1.2_T1.js index b4b50d6746..83ce6f00e0 100644 --- a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A1.2_T1.js +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A1.2_T1.js @@ -1,17 +1,14 @@ -// 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.'); } diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A2.1_T1.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A2.1_T1.js index e1673e6ec3..6a02959b72 100644 --- a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A2.1_T1.js +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A2.1_T1.js @@ -1,17 +1,14 @@ -// 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'); } diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A2.2_T1.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A2.2_T1.js index a6a0030eae..6c1199e128 100644 --- a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A2.2_T1.js +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A2.2_T1.js @@ -1,25 +1,25 @@ -// 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); diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A2.3_T1.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A2.3_T1.js index b2c18dfca6..6f3b224280 100644 --- a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A2.3_T1.js +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A2.3_T1.js @@ -1,19 +1,17 @@ -// 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); diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A2.3_T2.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A2.3_T2.js index cfdbcb4fa6..26706526d8 100644 --- a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A2.3_T2.js +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A2.3_T2.js @@ -1,13 +1,11 @@ -// 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); diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A2.3_T3.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A2.3_T3.js index 78bc8ad16d..ab1caf6d85 100644 --- a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A2.3_T3.js +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A2.3_T3.js @@ -1,13 +1,11 @@ -// 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); diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A3.1_T1.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A3.1_T1.js index b11aa6d748..587c2a8de0 100644 --- a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A3.1_T1.js +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A3.1_T1.js @@ -1,8 +1,5 @@ -// 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); diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A3.1_T2.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A3.1_T2.js new file mode 100644 index 0000000000..ddab9ba4b9 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A3.1_T2.js @@ -0,0 +1,20 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + Promise.all expects an iterable argument; + fails if recieves an abrupt completion + ref 7.4.1 non-Object fails CheckIterable + ref 7.4.2 GetIterator throws TypeError if CheckIterable fails +author: Sam Mikes +description: Promise.all(new Error()) returns Promise rejected with TypeError +---*/ + +Promise.all(new Error("abrupt")).then(function () { + $ERROR('Promise unexpectedly resolved: Promise.all(abruptCompletion) should throw TypeError'); +},function (err) { + if (!(err instanceof TypeError)) { + $ERROR('Expected TypeError, got ' + err); + } +}).then($DONE,$DONE); diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A3.1_T3.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A3.1_T3.js new file mode 100644 index 0000000000..9fad16f2e7 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A3.1_T3.js @@ -0,0 +1,25 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + Promise.all expects an iterable argument; + fails if GetIterator returns an abrupt completion. +author: Sam Mikes +description: Promise.all((throw on GetIterator)) returns Promise rejected with TypeError +---*/ + +var iterThrows = {}; +Object.defineProperty(iterThrows, Symbol.iterator, { + get: function () { + throw new Error("abrupt completion"); + } +}); + +Promise.all(iterThrows).then(function () { + $ERROR('Promise unexpectedly fulfilled: Promise.all(iterThrows) should throw TypeError'); +},function (err) { + if (!(err instanceof Error)) { + $ERROR('Expected promise to be rejected with error, got ' + err); + } +}).then($DONE,$DONE); diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A4.1_T1.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A4.1_T1.js new file mode 100644 index 0000000000..d7a0f45e93 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A4.1_T1.js @@ -0,0 +1,15 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + Promise.all should throw if 'this' does not conform to Promise constructor +negative: TypeError +description: this must conform to Promise constructor in Promise.all +author: Sam Mikes +---*/ + +function ZeroArgConstructor() { +} + +Promise.all.call(ZeroArgConstructor, []); diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A5.1_T1.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A5.1_T1.js new file mode 100644 index 0000000000..4a32f6a0be --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A5.1_T1.js @@ -0,0 +1,29 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + Promise.all expects an iterable argument; + rejects if IteratorStep() throws +author: Sam Mikes +description: iterator.next throws, causing Promise.all to reject +---*/ + +var iterThrows = {}; +Object.defineProperty(iterThrows, Symbol.iterator, { + get: function () { + return { + next: function () { + throw new Error("abrupt completion"); + } + }; + } +}); + +Promise.all(iterThrows).then(function () { + $ERROR('Promise unexpectedly resolved: Promise.all(iterThrows) should throw TypeError'); +},function (err) { + if (!(err instanceof TypeError)) { + $ERROR('Expected TypeError, got ' + err); + } +}).then($DONE,$DONE); diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A6.1_T1.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A6.1_T1.js new file mode 100644 index 0000000000..2b2b96c52c --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A6.1_T1.js @@ -0,0 +1,15 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + Promise.all with 0-element array +author: Sam Mikes +description: Promise.all([]) produces a promise +---*/ + +var p = Promise.all([]); + +if (!(p instanceof Promise)) { + $ERROR('Expected Promise.all([]) to be instanceof Promise' + err); +} diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A6.1_T2.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A6.1_T2.js new file mode 100644 index 0000000000..373683e769 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A6.1_T2.js @@ -0,0 +1,21 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + Promise.all with 0-element array + should accept an empty array +author: Sam Mikes +description: Promise.all([]) returns a promise for an empty array +---*/ + +var p = Promise.all([]); + +p.then(function (result) { + if (!(result instanceof Array)) { + $ERROR("Expected Promise.all([]) to be Array, actually " + result); + } + if (result.length !== 0) { + $ERROR("Expected Promise.all([]) to be empty Array, actually " + result); + } +}).then($DONE, $DONE); diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A7.1_T1.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A7.1_T1.js new file mode 100644 index 0000000000..ff1c937666 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A7.1_T1.js @@ -0,0 +1,29 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + Promise.all with 1-element array + should accept an array with settled promise +author: Sam Mikes +description: Promise.all([p1]) is resolved with a promise for a one-element array +---*/ + +var p1 = Promise.resolve(3); + +var pAll = Promise.all([p1]); + +pAll.then(function (result) { + if (!(pAll instanceof Promise)) { + $ERROR("Expected Promise.all() to be promise, actually " + pAll); + } + if (!(result instanceof Array)) { + $ERROR("Expected Promise.all() to be promise for an Array, actually " + result); + } + if (result.length !== 1) { + $ERROR("Expected Promise.all([p1]) to be a promise for one-element Array, actually " + result); + } + if (result[0] !== 3) { + $ERROR("Expected result[0] to be 3, actually " + result[0]); + } +}).then($DONE, $DONE); diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A7.2_T1.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A7.2_T1.js new file mode 100644 index 0000000000..7c3940ec5c --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A7.2_T1.js @@ -0,0 +1,32 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + Promise.all with 1-element array + should accept an array with settled promise +author: Sam Mikes +description: Promise.all() accepts a one-element array +includes: [PromiseHelper.js] +---*/ + +var sequence = []; + +var p1 = new Promise(function (resolve) { resolve({}); } ); + +sequence.push(1); + +Promise.all([p1]).then(function (resolved) { + sequence.push(4); + checkSequence(sequence, "Expected Promise.all().then to queue second"); +}).catch($DONE); + +p1.then(function () { + sequence.push(3); + checkSequence(sequence, "Expected p1.then to queue first"); +}).then(function () { + sequence.push(5); + checkSequence(sequence, "Expected final then to queue last"); +}).then($DONE, $DONE); + +sequence.push(2); diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A8.1_T1.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A8.1_T1.js new file mode 100644 index 0000000000..c0cf75318f --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A8.1_T1.js @@ -0,0 +1,32 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +author: Sam Mikes +description: Promise.all([p1, p2]) resolution functions are called in predictable sequence +includes: [PromiseHelper.js] +---*/ + +var sequence = []; + +var p1 = new Promise(function (resolve) { resolve(1); } ); +var p2 = new Promise(function (resolve) { resolve(2); } ); + +sequence.push(1); + +p1.then(function () { + sequence.push(3); + checkSequence(sequence, "Expected to be called first."); +}).catch($DONE); + +Promise.all([p1, p2]).then(function () { + sequence.push(5); + checkSequence(sequence, "Expected to be called third."); +}).then($DONE, $DONE); + +p2.then(function () { + sequence.push(4); + checkSequence(sequence, "Expected to be called second."); +}).catch($DONE); + +sequence.push(2); diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A8.2_T1.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A8.2_T1.js new file mode 100644 index 0000000000..1fedf5ffac --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A8.2_T1.js @@ -0,0 +1,26 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + Promise.all with 2-element array +author: Sam Mikes +description: Promise.all() rejects when a promise in its array rejects +includes: [PromiseHelper.js] +---*/ + +var rejectP1, + p1 = new Promise(function (resolve, reject) { + rejectP1 = reject; + }), + p2 = Promise.resolve(2); + +Promise.all([p1, p2]).then(function (resolve) { + $ERROR("Did not expect promise to be fulfilled."); +}, function (rejected) { + if (rejected !== 1) { + $ERROR("Expected promise to be rejected with 1, actually " + rejected); + } +}).then($DONE, $DONE); + +rejectP1(1); diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A8.2_T2.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A8.2_T2.js new file mode 100644 index 0000000000..5bf25f5d91 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.1/S25.4.4.1_A8.2_T2.js @@ -0,0 +1,26 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + Promise.all with 2-element array +author: Sam Mikes +description: Promise.all() rejects when second promise in array rejects +includes: [PromiseHelper.js] +---*/ + +var rejectP2, + p1 = Promise.resolve(1), + p2 = new Promise(function (resolve, reject) { + rejectP2 = reject; + }); + +Promise.all([p1, p2]).then(function () { + $ERROR("Did not expect promise to be fulfilled."); +}, function (rejected) { + if (rejected !== 2) { + $ERROR("Expected promise to be rejected with 2, actually " + rejected); + } +}).then($DONE, $DONE); + +rejectP2(2); diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.2/S25.4.4.2_A1.1_T1.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.2/S25.4.4.2_A1.1_T1.js new file mode 100644 index 0000000000..dc61a6931e --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.2/S25.4.4.2_A1.1_T1.js @@ -0,0 +1,19 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + Promise prototype object exists, is object, not enumerable, writable, + or configurable +author: Sam Mikes +description: Promise prototype exists +---*/ + +if (Promise.prototype === undefined) { + $ERROR("Expected Promise.prototype to be defined."); +} + +if (!(Promise.prototype instanceof Object)) { + $ERROR("Expected Promise.prototype to be an object."); +} + diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A1.1_T1.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A1.1_T1.js new file mode 100644 index 0000000000..7bcd06d732 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A1.1_T1.js @@ -0,0 +1,16 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: Promise.race is callable +author: Sam Mikes +description: Promise.race is callable +---*/ + +if (typeof Promise.race !== "function") { + $ERROR("Expected Promise.race to be a function, actually " + typeof Promise.race); +} + +if (Promise.race.length !== 1) { + $ERROR("Expected Promise.race to be a function of 1 argument."); +} diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A2.1_T1.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A2.1_T1.js new file mode 100644 index 0000000000..7f54054e1d --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A2.1_T1.js @@ -0,0 +1,14 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: Promise.race returns a new promise +author: Sam Mikes +description: Promise.race returns a new promise +---*/ + +var p = Promise.race([]); + +if (!(p instanceof Promise)) { + $ERROR("Expected Promise.race([]) to return a promise."); +} diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A2.2_T1.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A2.2_T1.js new file mode 100644 index 0000000000..b8a4554f6d --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A2.2_T1.js @@ -0,0 +1,19 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: Promise.race rejects on non-iterable argument +author: Sam Mikes +description: Promise.race rejects if argument is not object or is non-iterable +---*/ + +var nonIterable = 3; + +Promise.race(nonIterable).then(function () { + $ERROR('Promise unexpectedly fulfilled: Promise.race(nonIterable) should throw TypeError'); +}, function (err) { + if (!(err instanceof TypeError)) { + $ERROR('Expected TypeError, got ' + err); + } +}).then($DONE, $DONE); + diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A2.2_T2.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A2.2_T2.js new file mode 100644 index 0000000000..29200c90af --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A2.2_T2.js @@ -0,0 +1,17 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: Promise.race rejects on non-iterable argument +author: Sam Mikes +description: Promise.race rejects if argument is not object or is non-iterable +---*/ + +Promise.race(new Error("abrupt")).then(function () { + $ERROR('Promise unexpectedly resolved: Promise.race(abruptCompletion) should throw TypeError'); +}, function (err) { + if (!(err instanceof TypeError)) { + $ERROR('Expected TypeError, got ' + err); + } +}).then($DONE, $DONE); + diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A2.2_T3.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A2.2_T3.js new file mode 100644 index 0000000000..4173503010 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A2.2_T3.js @@ -0,0 +1,28 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + Promise.race rejects when GetIterator() returns an abrupt completion + 4. Let iterator be GetIterator(iterable). + 5. IfAbruptRejectPromise(iterator, promiseCapability) + +author: Sam Mikes +description: Promise.race rejects if GetIterator throws +---*/ + +var iterThrows = {}; +Object.defineProperty(iterThrows, Symbol.iterator, { + get: function () { + throw new Error("abrupt completion"); + } +}); + +Promise.race(iterThrows).then(function () { + $ERROR('Promise unexpectedly fulfilled: Promise.race(iterThrows) should throw'); +}, function (err) { + if (!(err instanceof Error)) { + $ERROR('Expected Promise to be rejected with an error, got ' + err); + } +}).then($DONE, $DONE); + diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A3.1_T1.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A3.1_T1.js new file mode 100644 index 0000000000..824712c041 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A3.1_T1.js @@ -0,0 +1,17 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + Promise.race throws on invalid 'this' + Note: must have at least one element in array, or else Promise.race + never exercises the code that throws +author: Sam Mikes +description: Promise.race throws if 'this' does not conform to Promise constructor +negative: TypeError +---*/ + +function ZeroArgConstructor() { +} + +Promise.race.call(ZeroArgConstructor, [3]); diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A3.1_T2.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A3.1_T2.js new file mode 100644 index 0000000000..687463f057 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A3.1_T2.js @@ -0,0 +1,16 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + Promise.race must throw TypeError per + CreatePromiseCapabilityRecord step 8 when + promiseCapabliity.[[Resolve]] is not callable +author: Sam Mikes +description: Promise.race throws TypeError, even on empty array, when 'this' does not conform to Promise constructor +negative: TypeError +---*/ + +function BadPromiseConstructor(f) { f(undefined, undefined); } + +Promise.race.call(BadPromiseConstructor, []); diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A4.1_T1.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A4.1_T1.js new file mode 100644 index 0000000000..b1d979c7a4 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A4.1_T1.js @@ -0,0 +1,27 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +author: Sam Mikes +description: Promise.race rejects if IteratorStep throws +---*/ + +var iterThrows = {}; +Object.defineProperty(iterThrows, Symbol.iterator, { + get: function () { + return { + next: function () { + throw new Error("abrupt completion"); + } + }; + } +}); + +Promise.race(iterThrows).then(function () { + $ERROR('Promise unexpectedly fulfilled: Promise.race(iterThrows) should throw TypeError'); +},function (err) { + if (!(err instanceof TypeError)) { + $ERROR('Expected TypeError, got ' + err); + } +}).then($DONE,$DONE); + diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A4.1_T2.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A4.1_T2.js new file mode 100644 index 0000000000..bd7f880f4a --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A4.1_T2.js @@ -0,0 +1,33 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +author: Sam Mikes +description: Promise.race rejects if IteratorStep throws +---*/ + +var iterThrows = {}; +Object.defineProperty(iterThrows, Symbol.iterator, { + get: function () { + return { + next: function () { + var v = {}; + Object.defineProperty(v, 'value', { + get: function () { + throw new Error("abrupt completion"); + } + }); + return v; + } + }; + } +}); + +Promise.race(iterThrows).then(function () { + $ERROR('Promise unexpectedly fulfilled: Promise.race(iterThrows) should throw TypeError'); +},function (err) { + if (!(err instanceof TypeError)) { + $ERROR('Expected TypeError, got ' + err); + } +}).then($DONE,$DONE); + diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A5.1_T1.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A5.1_T1.js new file mode 100644 index 0000000000..8bcd93aa51 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A5.1_T1.js @@ -0,0 +1,19 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +author: Sam Mikes +description: Promise.race([]) never settles +---*/ + +var p = Promise.race([]); + +p.then(function () { + $ERROR("Never settles."); +}, function () { + $ERROR("Never settles."); +}).then($DONE, $DONE); + +// use three 'then's to allow above to settle +// if this is a buggy Promise.race implementation +Promise.resolve().then().then().then($DONE, $DONE); diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A6.1_T1.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A6.1_T1.js new file mode 100644 index 0000000000..d652669a0f --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A6.1_T1.js @@ -0,0 +1,29 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +author: Sam Mikes +description: Promise.race([1]) settles immediately +includes: [PromiseHelper.js] +---*/ + +var sequence = []; + +var p = Promise.race([1]); + +sequence.push(1); + +p.then(function () { + sequence.push(4); + checkSequence(sequence, "This happens second"); +}).catch($DONE); + +Promise.resolve().then(function () { + sequence.push(3); + checkSequence(sequence, "This happens first"); +}).then(function () { + sequence.push(5); + checkSequence(sequence, "This happens third"); +}).then($DONE, $DONE); + +sequence.push(2); diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A6.2_T1.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A6.2_T1.js new file mode 100644 index 0000000000..be5745565f --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A6.2_T1.js @@ -0,0 +1,32 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +author: Sam Mikes +description: Promise.race([p1]) settles immediately +includes: [PromiseHelper.js] +---*/ + +var sequence = []; + +var p1 = Promise.reject(1), + p = Promise.race([p1]); + +sequence.push(1); + +p.then(function () { + $ERROR("Should not fulfill."); +}, function () { + sequence.push(4); + checkSequence(sequence, "This happens second"); +}).catch($DONE); + +Promise.resolve().then(function () { + sequence.push(3); + checkSequence(sequence, "This happens first"); +}).then(function () { + sequence.push(5); + checkSequence(sequence, "This happens third"); +}).then($DONE, $DONE); + +sequence.push(2); diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A7.1_T1.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A7.1_T1.js new file mode 100644 index 0000000000..4109073344 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A7.1_T1.js @@ -0,0 +1,35 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +author: Sam Mikes +description: Promise.race([p1, p2]) settles when first settles +includes: [PromiseHelper.js] +---*/ + +var sequence = []; + +var p1 = Promise.resolve(1), + p2 = Promise.resolve(2), + p = Promise.race([p1, p2]); + +sequence.push(1); + +p.then(function (arg) { + if (arg !== 1) { + $ERROR("Expected promise to be fulfilled with 1, got " + arg); + } + + sequence.push(4); + checkSequence(sequence, "This happens second"); +}).catch($DONE); + +Promise.resolve().then(function () { + sequence.push(3); + checkSequence(sequence, "This happens first"); +}).then(function () { + sequence.push(5); + checkSequence(sequence, "This happens third"); +}).then($DONE, $DONE); + +sequence.push(2); diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A7.1_T2.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A7.1_T2.js new file mode 100644 index 0000000000..746c71cddc --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A7.1_T2.js @@ -0,0 +1,35 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +author: Sam Mikes +description: Promise.race([p1, p2]) settles when first settles +includes: [PromiseHelper.js] +---*/ + +var sequence = []; + +var p1 = Promise.resolve(1), + p2 = new Promise(function () {}), + p = Promise.race([p1, p2]); + +sequence.push(1); + +p.then(function (arg) { + if (arg !== 1) { + $ERROR("Expected promise to be fulfilled with 1, got " + arg); + } + + sequence.push(4); + checkSequence(sequence, "This happens second"); +}).catch($DONE); + +Promise.resolve().then(function () { + sequence.push(3); + checkSequence(sequence, "This happens first"); +}).then(function () { + sequence.push(5); + checkSequence(sequence, "This happens third"); +}).then($DONE, $DONE); + +sequence.push(2); diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A7.1_T3.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A7.1_T3.js new file mode 100644 index 0000000000..76e4be8918 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A7.1_T3.js @@ -0,0 +1,35 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +author: Sam Mikes +description: Promise.race([p1, p2]) settles when first settles +includes: [PromiseHelper.js] +---*/ + +var sequence = []; + +var p1 = new Promise(function () {}), + p2 = Promise.resolve(2), + p = Promise.race([p1, p2]); + +sequence.push(1); + +p.then(function (arg) { + if (arg !== 2) { + $ERROR("Expected promise to be fulfilled with 2, got " + arg); + } + + sequence.push(4); + checkSequence(sequence, "This happens second"); +}).catch($DONE); + +Promise.resolve().then(function () { + sequence.push(3); + checkSequence(sequence, "This happens first"); +}).then(function () { + sequence.push(5); + checkSequence(sequence, "This happens third"); +}).then($DONE, $DONE); + +sequence.push(2); diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A7.2_T1.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A7.2_T1.js new file mode 100644 index 0000000000..e3afc0f6d4 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A7.2_T1.js @@ -0,0 +1,37 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +author: Sam Mikes +description: Promise.race([p1, p2]) settles when first settles +includes: [PromiseHelper.js] +---*/ + +var sequence = []; + +var p1 = Promise.reject(1), + p2 = Promise.resolve(2), + p = Promise.race([p1, p2]); + +sequence.push(1); + +p.then(function () { + $ERROR("Should not be fulfilled - expected rejection."); +}, function (arg) { + if (arg !== 1) { + $ERROR("Expected rejection reason to be 1, got " + arg); + } + + sequence.push(4); + checkSequence(sequence, "This happens second"); +}).catch($DONE); + +Promise.resolve().then(function () { + sequence.push(3); + checkSequence(sequence, "This happens first"); +}).then(function () { + sequence.push(5); + checkSequence(sequence, "This happens third"); +}).then($DONE, $DONE); + +sequence.push(2); diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A7.3_T1.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A7.3_T1.js new file mode 100644 index 0000000000..312e25cc15 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A7.3_T1.js @@ -0,0 +1,20 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +author: Sam Mikes +description: Promise.race([p1, p2]) settles when first settles +---*/ + +var resolveP1, rejectP2, + p1 = new Promise(function (resolve) { resolveP1 = resolve; }), + p2 = new Promise(function (resolve, reject) { rejectP2 = reject; }); + +rejectP2(new Error("Promise.race should not see this if P1 already resolved")); +resolveP1(1); + +Promise.race([p1, p2]).then(function (arg) { + if (arg !== 1) { + $ERROR("Expected fulfillment with 1, got " + arg); + } +}).then($DONE, $DONE); diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A7.3_T2.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A7.3_T2.js new file mode 100644 index 0000000000..08d5b28097 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.3/S25.4.4.3_A7.3_T2.js @@ -0,0 +1,23 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +author: Sam Mikes +description: Promise.race([p1, p2]) settles when first settles +---*/ + +var resolveP1, rejectP2, + p1 = new Promise(function (resolve) { resolveP1 = resolve; }), + p2 = new Promise(function (resolve, reject) { rejectP2 = reject; }); + +Promise.race([p1, p2]).then(function () { + $ERROR("Should not be fulfilled: expected rejection."); +}, function (arg) { + if (arg !== 2) { + $ERROR("Expected rejection reason to be 2, got " + arg); + } +}).then($DONE, $DONE); + +rejectP2(2); +resolveP1(1); + diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.4/S25.4.4.4_A1.1_T1.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.4/S25.4.4.4_A1.1_T1.js new file mode 100644 index 0000000000..c906c2cde2 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.4/S25.4.4.4_A1.1_T1.js @@ -0,0 +1,17 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + Promise.reject +author: Sam Mikes +description: Promise.reject is a function +---*/ + +if ((typeof Promise.reject) !== "function") { + $ERROR("Expected Promise.reject to be a function"); +} + +if (Promise.reject.length !== 1) { + $ERROR("Expected Promise.reject to be a function of one argument"); +} diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.4/S25.4.4.4_A2.1_T1.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.4/S25.4.4.4_A2.1_T1.js new file mode 100644 index 0000000000..ba284de166 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.4/S25.4.4.4_A2.1_T1.js @@ -0,0 +1,23 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + Promise.reject +author: Sam Mikes +description: Promise.reject creates a new settled promise +---*/ + +var p = Promise.reject(3); + +if (!(p instanceof Promise)) { + $ERROR("Expected Promise.reject to return a promise."); +} + +p.then(function () { + $ERROR("Promise should not be fulfilled."); +}, function (arg) { + if (arg !== 3) { + $ERROR("Expected promise to be rejected with supplied arg, got " + arg); + } +}).then($DONE, $DONE); diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.4/S25.4.4.4_A3.1_T1.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.4/S25.4.4.4_A3.1_T1.js new file mode 100644 index 0000000000..ba6c68b5ab --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.4/S25.4.4.4_A3.1_T1.js @@ -0,0 +1,15 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + Promise.reject +author: Sam Mikes +description: Promise.reject throws TypeError for bad 'this' +negative: TypeError +---*/ + +function ZeroArgConstructor() { +} + +Promise.reject.call(ZeroArgConstructor, 4); diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.5/S25.4.4.5_A1.1_T1.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.5/S25.4.4.5_A1.1_T1.js new file mode 100644 index 0000000000..8432339487 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.5/S25.4.4.5_A1.1_T1.js @@ -0,0 +1,17 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + Promise.resolve +author: Sam Mikes +description: Promise.resolve is a function +---*/ + +if ((typeof Promise.resolve) !== "function") { + $ERROR("Expected Promise.resolve to be a function"); +} + +if (Promise.resolve.length !== 1) { + $ERROR("Expected Promise.resolve to be a function of one argument"); +} diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.5/S25.4.4.5_A2.1_T1.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.5/S25.4.4.5_A2.1_T1.js new file mode 100644 index 0000000000..c3bce23cb1 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.5/S25.4.4.5_A2.1_T1.js @@ -0,0 +1,14 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +author: Sam Mikes +description: Promise.resolve passes through a promise w/ same Constructor +---*/ + +var p1 = Promise.resolve(1), + p2 = Promise.resolve(p1); + +if (p1 !== p2) { + $ERROR("Expected p1 === Promise.resolve(p1) because they have same constructor"); +} diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.5/S25.4.4.5_A2.2_T1.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.5/S25.4.4.5_A2.2_T1.js new file mode 100644 index 0000000000..aa5c3a10f1 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.5/S25.4.4.5_A2.2_T1.js @@ -0,0 +1,24 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +author: Sam Mikes +description: Promise.resolve passes through an unsettled promise w/ same Constructor +---*/ + +var resolveP1, + p1 = new Promise(function (resolve) { resolveP1 = resolve; }), + p2 = Promise.resolve(p1), + obj = {}; + +if (p1 !== p2) { + $ERROR("Expected p1 === Promise.resolve(p1) because they have same constructor"); +} + +p2.then(function (arg) { + if (arg !== obj) { + $ERROR("Expected promise to be resolved with obj, actually " + arg); + } +}).then($DONE, $DONE); + +resolveP1(obj); diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.5/S25.4.4.5_A2.3_T1.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.5/S25.4.4.5_A2.3_T1.js new file mode 100644 index 0000000000..f7c9ade18f --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.5/S25.4.4.5_A2.3_T1.js @@ -0,0 +1,26 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +author: Sam Mikes +description: Promise.resolve passes through an unsettled promise w/ same Constructor +---*/ + +var rejectP1, + p1 = new Promise(function (resolve, reject) { rejectP1 = reject; }), + p2 = Promise.resolve(p1), + obj = {}; + +if (p1 !== p2) { + $ERROR("Expected p1 === Promise.resolve(p1) because they have same constructor"); +} + +p2.then(function () { + $ERROR("Expected p2 to be rejected, not fulfilled."); +}, function (arg) { + if (arg !== obj) { + $ERROR("Expected promise to be rejected with reason obj, actually " + arg); + } +}).then($DONE, $DONE); + +rejectP1(obj); diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.5/S25.4.4.5_A3.1_T1.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.5/S25.4.4.5_A3.1_T1.js new file mode 100644 index 0000000000..7a998b1e9d --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.5/S25.4.4.5_A3.1_T1.js @@ -0,0 +1,32 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + Promise.resolve +author: Sam Mikes +description: Promise.resolve delegates to foreign thenable +includes: [PromiseHelper.js] +---*/ + +var sequence = []; + +var thenable = { + then: function(onResolve, onReject) { + sequence.push(3); + checkSequence(sequence, "thenable.then called"); + + Promise.resolve().then(function () { + sequence.push(4); + checkSequence(sequence, "all done"); + }).then($DONE, $DONE); + } +}; + +sequence.push(1); +checkSequence(sequence, "no async calls yet"); + +var p1 = Promise.resolve(thenable); + +sequence.push(2); +checkSequence(sequence, "thenable.then queued but not yet called"); diff --git a/test/suite/es6/ch25/25.4/25.4.4/25.4.4.5/S25.4.4.5_A4.1_T1.js b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.5/S25.4.4.5_A4.1_T1.js new file mode 100644 index 0000000000..e552c3c1ac --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/25.4.4.5/S25.4.4.5_A4.1_T1.js @@ -0,0 +1,22 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + Section 25.4.1.4.2 +author: Sam Mikes +description: self-resolved Promise throws TypeError +---*/ + +var resolveP, + p = new Promise(function (resolve) { resolveP = resolve; }); + +resolveP(p); + +p.then(function () { + $ERROR("Should not fulfill: should reject with TypeError."); +}, function (err) { + if (!(err instanceof TypeError)) { + $ERROR("Expected TypeError, got " + err); + } +}).then($DONE, $DONE); diff --git a/test/suite/es6/ch25/25.4/25.4.4/S25.4.4_A1.1_T1.js b/test/suite/es6/ch25/25.4/25.4.4/S25.4.4_A1.1_T1.js new file mode 100644 index 0000000000..4497e2b2e8 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/S25.4.4_A1.1_T1.js @@ -0,0 +1,38 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + Misc sequencing tests + inspired by https://github.com/getify/native-promise-only/issues/34#issuecomment-54282002 +author: Sam Mikes +description: Promise onResolved functions are called in predictable sequence +includes: [PromiseHelper.js] +---*/ + +var sequence = []; + +var p = new Promise(function(resolve, reject){ + sequence.push(1); + resolve(""); +}); + +p.then(function () { + sequence.push(3); +}).then(function () { + sequence.push(5); +}).then(function () { + sequence.push(7); +}); + +p.then(function () { + sequence.push(4); +}).then(function () { + sequence.push(6); +}).then(function () { + sequence.push(8); +}).then(function () { + checkSequence(sequence, "Sequence should be as expected"); +}).then($DONE, $DONE); + +sequence.push(2); diff --git a/test/suite/es6/ch25/25.4/25.4.4/S25.4.4_A2.1_T1.js b/test/suite/es6/ch25/25.4/25.4.4/S25.4.4_A2.1_T1.js new file mode 100644 index 0000000000..47086b9461 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/S25.4.4_A2.1_T1.js @@ -0,0 +1,33 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + Misc sequencing tests + inspired by https://github.com/promises-aplus/promises-tests/issues/61 + Case "T1" +author: Sam Mikes +description: Promise onResolved functions are called in predictable sequence +includes: [PromiseHelper.js] +---*/ + +var resolveP1, rejectP2, sequence = []; + +(new Promise(function (resolve, reject) { + resolveP1 = resolve; +})).then(function (msg) { + sequence.push(msg); +}).then(function () { + checkSequence(sequence, "Expected 1,2,3"); +}).then($DONE, $DONE); + +(new Promise(function (resolve, reject) { + rejectP2 = reject; +})).catch(function (msg) { + sequence.push(msg); +}); + +rejectP2(2); +resolveP1(3); + +sequence.push(1); diff --git a/test/suite/es6/ch25/25.4/25.4.4/S25.4.4_A2.1_T2.js b/test/suite/es6/ch25/25.4/25.4.4/S25.4.4_A2.1_T2.js new file mode 100644 index 0000000000..991feaad7d --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/S25.4.4_A2.1_T2.js @@ -0,0 +1,37 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + Misc sequencing tests + inspired by https://github.com/promises-aplus/promises-tests/issues/61 + Case "T2a" +author: Sam Mikes +description: Promise onResolved functions are called in predictable sequence +includes: [PromiseHelper.js] +---*/ + +var resolveP1, rejectP2, p1, p2, + sequence = []; + +p1 = new Promise(function (resolve, reject) { + resolveP1 = resolve; +}); +p2 = new Promise(function (resolve, reject) { + rejectP2 = reject; +}); + +rejectP2(3); +resolveP1(2); + +p1.then(function (msg) { + sequence.push(msg); +}); + +p2.catch(function (msg) { + sequence.push(msg); +}).then(function () { + checkSequence(sequence, "Expected 1,2,3"); +}).then($DONE, $DONE); + +sequence.push(1); diff --git a/test/suite/es6/ch25/25.4/25.4.4/S25.4.4_A2.1_T3.js b/test/suite/es6/ch25/25.4/25.4.4/S25.4.4_A2.1_T3.js new file mode 100644 index 0000000000..b050f14da1 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.4/S25.4.4_A2.1_T3.js @@ -0,0 +1,41 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + Misc sequencing tests + inspired by https://github.com/promises-aplus/promises-tests/issues/61 + Case "T2b" +author: Sam Mikes +description: Promise onResolved functions are called in predictable sequence +includes: [PromiseHelper.js] +---*/ + +var resolveP1, rejectP2, p1, p2, + sequence = []; + +p1 = new Promise(function (resolve, reject) { + resolveP1 = resolve; +}); +p2 = new Promise(function (resolve, reject) { + rejectP2 = reject; +}); + +rejectP2(3); +resolveP1(2); + +Promise.resolve().then(function () { + p1.then(function (msg) { + sequence.push(msg); + }); + + p2.catch(function (msg) { + sequence.push(msg); + }).then(function () { + checkSequence(sequence, "Expected 1,2,3"); + }).then($DONE, $DONE); +}); + +sequence.push(1); + + diff --git a/test/suite/es6/ch25/25.4/25.4.5/25.4.5.1/S25.4.5.1_A1.1_T1.js b/test/suite/es6/ch25/25.4/25.4.5/25.4.5.1/S25.4.5.1_A1.1_T1.js new file mode 100644 index 0000000000..064e964b7a --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.5/25.4.5.1/S25.4.5.1_A1.1_T1.js @@ -0,0 +1,13 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + Promise prototype.catch is a function +author: Sam Mikes +description: Promise.prototype.catch is a function +---*/ + +if (!(Promise.prototype.catch instanceof Function)) { + $ERROR("Expected Promise.prototype.catch to be a function"); +} diff --git a/test/suite/es6/ch25/25.4/25.4.5/25.4.5.1/S25.4.5.1_A2.1_T1.js b/test/suite/es6/ch25/25.4/25.4.5/25.4.5.1/S25.4.5.1_A2.1_T1.js new file mode 100644 index 0000000000..99a45f5010 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.5/25.4.5.1/S25.4.5.1_A2.1_T1.js @@ -0,0 +1,21 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + catch is a method on a Promise +author: Sam Mikes +description: catch is a method on a Promise +---*/ + +var p = Promise.resolve(3); + +if (!(p.catch instanceof Function)) { + $ERROR("Expected p.catch to be a function"); +} + +if (p.catch.length !== 1) { + $ERROR("Expected p.catch to take one argument"); +} + + diff --git a/test/suite/es6/ch25/25.4/25.4.5/25.4.5.1/S25.4.5.1_A3.1_T1.js b/test/suite/es6/ch25/25.4/25.4.5/25.4.5.1/S25.4.5.1_A3.1_T1.js new file mode 100644 index 0000000000..2dd242ed0d --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.5/25.4.5.1/S25.4.5.1_A3.1_T1.js @@ -0,0 +1,22 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + catch(arg) is equivalent to then(undefined, arg) +author: Sam Mikes +description: catch is implemented in terms of then +---*/ + +var obj = {}; + +var p = Promise.resolve(obj); + +p.catch(function () { + $ERROR("Should not be called - promise is fulfilled"); +}).then(function (arg) { + if (arg !== obj) { + $ERROR("Expected promise to be fulfilled with obj, got " + arg); + } +}).then($DONE, $DONE); + diff --git a/test/suite/es6/ch25/25.4/25.4.5/25.4.5.1/S25.4.5.1_A3.1_T2.js b/test/suite/es6/ch25/25.4/25.4.5/25.4.5.1/S25.4.5.1_A3.1_T2.js new file mode 100644 index 0000000000..143d2e8045 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.5/25.4.5.1/S25.4.5.1_A3.1_T2.js @@ -0,0 +1,22 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + catch(arg) is equivalent to then(undefined, arg) +author: Sam Mikes +description: catch is implemented in terms of then +---*/ + +var obj = {}; + +var p = Promise.reject(obj); + +p.then(function () { + $ERROR("Should not be called: did not expect promise to be fulfilled"); +}).catch(function (arg) { + if (arg !== obj) { + $ERROR("Should have been rejected with reason obj, got " + arg); + } +}).then($DONE, $DONE); + diff --git a/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A1.1_T1.js b/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A1.1_T1.js new file mode 100644 index 0000000000..e8c5d3e5d9 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A1.1_T1.js @@ -0,0 +1,17 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + Promise.prototype.then is a function of two arguments +author: Sam Mikes +description: Promise.prototype.then is a function of two arguments +---*/ + +if (!(Promise.prototype.then instanceof Function)) { + $ERROR("Expected Promise.prototype.then to be a function"); +} + +if (Promise.prototype.then.length !== 2) { + $ERROR("Expected Promise.prototype.then to be a function of two arguments"); +} diff --git a/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A1.1_T2.js b/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A1.1_T2.js new file mode 100644 index 0000000000..1369eefbe9 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A1.1_T2.js @@ -0,0 +1,21 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + Promise.prototype.then is a function of two arguments +author: Sam Mikes +description: Promise.prototype.then is a function of two arguments +---*/ + +var p = new Promise(function () {}); + +if (!(p.then instanceof Function)) { + $ERROR("Expected p.then to be a function"); +} + +if (p.then.length !== 2) { + $ERROR("Expected p.then to be a function of two arguments"); +} + + diff --git a/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A2.1_T1.js b/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A2.1_T1.js new file mode 100644 index 0000000000..a56fbd6111 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A2.1_T1.js @@ -0,0 +1,15 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + Promise.prototype.then expects a constructor conforming to Promise as 'this' +author: Sam Mikes +description: Promise.prototype.then throw if 'this' is non-Object +negative: TypeError +---*/ + +var p = new Promise(function () {}); + +p.then.call(3, function () {}, function () {}); + diff --git a/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A2.1_T2.js b/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A2.1_T2.js new file mode 100644 index 0000000000..d549abaa3a --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A2.1_T2.js @@ -0,0 +1,17 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + Promise.prototype.then expects a Promise as 'this' +author: Sam Mikes +description: Promise.prototype.then throw if 'this' is non-Promise Object +negative: TypeError +---*/ + +function ZeroArgConstructor() { +} + +var z = new ZeroArgConstructor(); + +Promise.then.call(z, function () {}, function () {}); diff --git a/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A3.1_T1.js b/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A3.1_T1.js new file mode 100644 index 0000000000..db6e17dc5f --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A3.1_T1.js @@ -0,0 +1,33 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + Promise.prototype.then throws TypeError if Get(promise, "constructor") throws + Ref 25.4.5.3 step 4 ReturnIfAbrupt(C) +author: Sam Mikes +description: Promise.prototype.then throws if Get(promise, "constructor") throws +---*/ + +var p = Promise.resolve("foo"); + +Object.defineProperty(p, "constructor", { + get: function () { + throw new Error("abrupt completion"); + } +}); + +try { + p.then(function () { + $ERROR("Should never be called."); + }, function () { + $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); + } +} diff --git a/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A4.1_T1.js b/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A4.1_T1.js new file mode 100644 index 0000000000..8f5fec3a20 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A4.1_T1.js @@ -0,0 +1,20 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + PerformPromiseThen + Ref 25.4.5.3.1 +author: Sam Mikes +description: Promise.prototype.then accepts 'undefined' as arg1, arg2 +---*/ + +var obj = {}; +var p = Promise.resolve(obj); + +p.then(undefined, undefined) + .then(function (arg) { + if (arg !== obj) { + $ERROR("Expected resolution object to be passed through, got " + arg); + } + }).then($DONE, $DONE); diff --git a/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A4.1_T2.js b/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A4.1_T2.js new file mode 100644 index 0000000000..e34b6f01ca --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A4.1_T2.js @@ -0,0 +1,21 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + PerformPromiseThen + Ref 25.4.5.3.1 +author: Sam Mikes +description: Promise.prototype.then accepts 'undefined' as arg1, arg2 +---*/ + +var obj = {}; +var p = Promise.reject(obj); + +p.then(undefined, undefined).then(function () { + $ERROR("Should not be called -- promise was rejected."); +}, function (arg) { + if (arg !== obj) { + $ERROR("Expected resolution object to be passed through, got " + arg); + } + }).then($DONE, $DONE); diff --git a/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A4.2_T1.js b/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A4.2_T1.js new file mode 100644 index 0000000000..c82e0281d6 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A4.2_T1.js @@ -0,0 +1,20 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + PerformPromiseThen + Ref 25.4.5.3.1 +author: Sam Mikes +description: Promise.prototype.then treats non-callable arg1, arg2 as undefined +---*/ + +var obj = {}; +var p = Promise.resolve(obj); + +p.then(3, 5) + .then(function (arg) { + if (arg !== obj) { + $ERROR("Expected resolution object to be passed through, got " + arg); + } + }).then($DONE, $DONE); diff --git a/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A4.2_T2.js b/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A4.2_T2.js new file mode 100644 index 0000000000..08e1500ae4 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A4.2_T2.js @@ -0,0 +1,21 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + PerformPromiseThen + Ref 25.4.5.3.1 +author: Sam Mikes +description: Promise.prototype.then treats non-callable arg1, arg2 as undefined +---*/ + +var obj = {}; +var p = Promise.reject(obj); + +p.then(3, 5).then(function () { + $ERROR("Should not be called -- promise was rejected."); +}, function (arg) { + if (arg !== obj) { + $ERROR("Expected resolution object to be passed through, got " + arg); + } +}).then($DONE, $DONE); diff --git a/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A5.1_T1.js b/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A5.1_T1.js new file mode 100644 index 0000000000..69819e355b --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A5.1_T1.js @@ -0,0 +1,37 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + PerformPromiseThen + Ref 25.4.5.3.1 +author: Sam Mikes +description: Promise.prototype.then enqueues handler if pending +includes: [PromiseHelper.js] +---*/ + +var sequence = [], + pResolve, + p = new Promise(function (resolve, reject) { + pResolve = resolve; + }); + +sequence.push(1); + +p.then(function () { + sequence.push(3); + checkSequence(sequence, "Should be second"); +}).catch($DONE); + +Promise.resolve().then(function () { + // enqueue another then-handler + p.then(function () { + sequence.push(4); + checkSequence(sequence, "Should be third"); + }).then($DONE, $DONE); + + sequence.push(2); + checkSequence(sequence, "Should be first"); + + pResolve(); +}).catch($DONE); diff --git a/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A5.2_T1.js b/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A5.2_T1.js new file mode 100644 index 0000000000..444df5babd --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A5.2_T1.js @@ -0,0 +1,39 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + PerformPromiseThen + Ref 25.4.5.3.1 +author: Sam Mikes +description: Promise.prototype.then immediately queues handler if fulfilled +includes: [PromiseHelper.js] +---*/ + +var sequence = [], + pResolve, + p = new Promise(function (resolve, reject) { + pResolve = resolve; + }); + +sequence.push(1); + +pResolve(); + +p.then(function () { + sequence.push(3); + checkSequence(sequence, "Should be first"); +}).catch($DONE); + +Promise.resolve().then(function () { + // enqueue another then-handler + p.then(function () { + sequence.push(5); + checkSequence(sequence, "Should be third"); + }).then($DONE, $DONE); + + sequence.push(4); + checkSequence(sequence, "Should be second"); +}).catch($DONE); + +sequence.push(2); diff --git a/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A5.3_T1.js b/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A5.3_T1.js new file mode 100644 index 0000000000..7c9f67cc33 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.5/25.4.5.3/S25.4.5.3_A5.3_T1.js @@ -0,0 +1,43 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + PerformPromiseThen + Ref 25.4.5.3.1 +author: Sam Mikes +description: Promise.prototype.then immediately queues handler if rejected +includes: [PromiseHelper.js] +---*/ + +var sequence = [], + pReject, + p = new Promise(function (resolve, reject) { + pReject = reject; + }); + +sequence.push(1); + +pReject(); + +p.then(function () { + $ERROR("Should not be called -- Promise rejected."); +}, function () { + sequence.push(3); + checkSequence(sequence, "Should be first"); +}).catch($DONE); + +Promise.resolve().then(function () { + // enqueue another then-handler + p.then(function () { + $ERROR("Should not be called (2) -- Promise rejected."); + }, function () { + sequence.push(5); + checkSequence(sequence, "Should be third"); + }).then($DONE, $DONE); + + sequence.push(4); + checkSequence(sequence, "Should be second"); +}).catch($DONE); + +sequence.push(2); diff --git a/test/suite/es6/ch25/25.4/25.4.5/S25.4.5_A1.1_T1.js b/test/suite/es6/ch25/25.4/25.4.5/S25.4.5_A1.1_T1.js new file mode 100644 index 0000000000..ec20bf602e --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.5/S25.4.5_A1.1_T1.js @@ -0,0 +1,12 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + Promise prototype object is an ordinary object +author: Sam Mikes +description: Promise prototype does not have [[PromiseState]] internal slot +negative: TypeError +---*/ + +Promise.call(Promise.prototype, function () {}); diff --git a/test/suite/es6/ch25/25.4/25.4.5/S25.4.5_A2.1_T1.js b/test/suite/es6/ch25/25.4/25.4.5/S25.4.5_A2.1_T1.js new file mode 100644 index 0000000000..2ff5e9ae08 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.5/S25.4.5_A2.1_T1.js @@ -0,0 +1,14 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + Promise prototype object is an ordinary object +author: Sam Mikes +description: Promise prototype is a standard built-in Object +---*/ + +if (!(Promise.prototype instanceof Object)) { + $ERROR("Expected Promise.prototype to be an Object"); +} + diff --git a/test/suite/es6/ch25/25.4/25.4.5/S25.4.5_A3.1_T1.js b/test/suite/es6/ch25/25.4/25.4.5/S25.4.5_A3.1_T1.js new file mode 100644 index 0000000000..b4fa5cea41 --- /dev/null +++ b/test/suite/es6/ch25/25.4/25.4.5/S25.4.5_A3.1_T1.js @@ -0,0 +1,14 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: > + Promise.prototype.constructor is the Promise constructor +author: Sam Mikes +description: Promise.prototype.constructor is the Promise constructor +---*/ + +if (Promise.prototype.constructor !== Promise) { + $ERROR("Expected Promise.prototype.constructor to be Promise"); +} +