Commit 2d48e06e authored by rossberg@chromium.org's avatar rossberg@chromium.org

Import Blink layout tests for Promises.

Import Blink layout tests for Promises.
We omitted some tests (for example workers tests).
We fixed some wrong test expectations.

BUG=347095
LOG=N
R=rossberg@chromium.org

Review URL: https://codereview.chromium.org/182713002

Patch from Yutaka Hirano <yhirano@chromium.org>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19757 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 11808039
Resolve or reject do not take effect on a rejected Promise.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS result is "foo"
PASS successfullyParsed is true
TEST COMPLETE
// Copyright 2014 the V8 project authors. All rights reserved.
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony
'use strict';
description('Resolve or reject do not take effect on a rejected Promise.');
var result;
new Promise(function(resolve, reject) {
reject('foo');
resolve('resolve');
reject('reject');
}).then(function() {
testFailed('fulfilled');
finishJSTest();
}, function(localResult) {
result = localResult;
shouldBeEqualToString('result', 'foo');
finishJSTest();
});
Resolve or reject do not take effect on a resolved Promise.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS result is "foo"
PASS successfullyParsed is true
TEST COMPLETE
// Copyright 2014 the V8 project authors. All rights reserved.
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony
'use strict';
description('Resolve or reject do not take effect on a resolved Promise.');
var result;
new Promise(function(resolve, reject) {
var anotherResolve;
resolve(new Promise(function(r) { anotherResolve = r; }));
resolve('resolve');
reject('reject');
anotherResolve('foo');
}).then(function(localResult) {
result = localResult;
shouldBeEqualToString('result', 'foo');
finishJSTest();
}, function() {
testFailed('rejected');
finishJSTest();
});
Test Promise.prototype.catch.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS thisInInit is undefined
PASS firstPromise instanceof Promise is true
PASS secondPromise instanceof Promise is true
PASS thisInOnFulfilled is undefined
PASS result is "hello"
PASS result is "bye"
PASS fulfilled
PASS successfullyParsed is true
TEST COMPLETE
// Copyright 2014 the V8 project authors. All rights reserved.
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony
'use strict';
description('Test Promise.prototype.catch.');
var reject;
var result;
var thisInInit;
var thisInOnFulfilled;
var firstPromise = new Promise(function(_, newReject) {
thisInInit = this;
reject = newReject;
});
var secondPromise = firstPromise.catch(function(localResult) {
thisInOnFulfilled = this;
shouldBe('thisInOnFulfilled', 'undefined');
result = localResult;
shouldBeEqualToString('result', 'hello');
return 'bye';
});
secondPromise.then(function(localResult) {
result = localResult;
shouldBeEqualToString('result', 'bye');
testPassed('fulfilled');
finishJSTest();
}, function() {
testFailed('rejected');
finishJSTest();
});
shouldBe('thisInInit', 'undefined');
shouldBeTrue('firstPromise instanceof Promise');
shouldBeTrue('secondPromise instanceof Promise');
try {
firstPromise.catch(null);
} catch (e) {
testFailed('catch(null) should not throw an exception');
}
try {
firstPromise.catch(37);
} catch (e) {
testFailed('catch(37) should not throw an exception');
}
reject('hello');
Test chained Promise.prototype.then.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
This should be the first debug output.
PASS fulfilled
PASS result is "hello"
PASS fulfilled
PASS result is "hello2"
PASS rejected
PASS result is "error"
PASS rejected
PASS result is "error2"
PASS fulfilled
PASS result is "recovered"
PASS successfullyParsed is true
TEST COMPLETE
// Copyright 2014 the V8 project authors. All rights reserved.
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony
'use strict';
description('Test chained Promise.prototype.then.');
var resolve;
var promise = new Promise(function (r) {resolve = r;});
var result;
promise.then(function(localResult) { // fulfilled - continue
testPassed('fulfilled');
result = localResult;
shouldBeEqualToString('result', 'hello');
return 'hello2';
}, function() {
testFailed('rrejected');
}).then() // pass through
.then(function(localResult) { // fulfilled - throw an exception
testPassed('fulfilled');
result = localResult;
shouldBeEqualToString('result', 'hello2');
throw 'error';
}, function() {
testFailed('rejected');
}).then(function() { // rejected - throw an exception
testFailed('fulfilled');
}, function(localResult) {
testPassed('rejected');
result = localResult;
shouldBeEqualToString('result', 'error');
throw 'error2';
}).then() // pass through
.then(function() { // rejected - recover
testFailed('fulfilled');
}, function(localResult) {
testPassed('rejected');
result = localResult;
shouldBeEqualToString('result', 'error2');
return 'recovered';
}).then(function(localResult) { // fulfilled - the last
testPassed('fulfilled');
result = localResult;
shouldBeEqualToString('result', 'recovered');
finishJSTest();
}, function() {
testFailed('rejected');
finishJSTest();
});
resolve('hello');
debug('This should be the first debug output.');
An exception thrown from an onFulfilled callback should reject the Promise.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS thisInThenCallback is undefined
PASS result is "foobar"
PASS successfullyParsed is true
TEST COMPLETE
// Copyright 2014 the V8 project authors. All rights reserved.
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony
'use strict';
description('An exception thrown from an onFulfilled callback should reject the Promise.');
var thisInThenCallback;
var result;
new Promise(function(resolve) {
resolve('hello');
}).then(function(result) {
throw 'foobar';
}).then(function(localResult) {
testFailed('Unexpected invocation of onFulfilled');
}, function(localResult) {
thisInThenCallback = this;
shouldBe('thisInThenCallback', 'undefined');
result = localResult;
shouldBeEqualToString('result', 'foobar');
finishJSTest();
});
|this| in Promise constructor should be undefined.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS receiverInStrict is undefined
PASS successfullyParsed is true
TEST COMPLETE
// Copyright 2014 the V8 project authors. All rights reserved.
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony
'use strict';
description('|this| in Promise constructor should be undefined.');
var receiverInStrict;
new Promise(function () {
receiverInStrict = this;
shouldBe('receiverInStrict', 'undefined');
});
Test Promise construction.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS promise instanceof Promise is true
PASS promise.constructor is Promise
PASS thisInInit is undefined
PASS resolve instanceof Function is true
PASS reject instanceof Function is true
PASS new Promise() threw exception TypeError: Promise resolver undefined is not a function.
PASS new Promise(37) threw exception TypeError: Promise resolver 37 is not a function.
PASS promise = new Promise(function() { throw Error("foo"); }) did not throw exception.
PASS result.message is "foo"
PASS fulfilled
PASS result is "hello"
PASS successfullyParsed is true
TEST COMPLETE
// Copyright 2014 the V8 project authors. All rights reserved.
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony
'use strict';
description('Test Promise construction.');
var thisInInit;
var resolve, reject;
var result;
var promise = new Promise(function(newResolve, newReject) {
thisInInit = this;
resolve = newResolve;
reject = newReject;
});
shouldBeTrue('promise instanceof Promise');
shouldBe('promise.constructor', 'Promise');
shouldBe('thisInInit', 'undefined');
shouldBeTrue('resolve instanceof Function');
shouldBeTrue('reject instanceof Function');
shouldThrow('new Promise()', '"TypeError: Promise resolver undefined is not a function"');
shouldThrow('new Promise(37)', '"TypeError: Promise resolver 37 is not a function"');
try {
promise = new Promise(function() { throw Error('foo'); });
testPassed('promise = new Promise(function() { throw Error("foo"); }) did not throw exception.');
} catch (e) {
testFailed('new Promise(function() { throw Error(\'foo\'); }) should not throw an exception.');
}
promise.then(undefined, function(localResult) {
result = localResult;
shouldBeEqualToString('result.message', 'foo');
});
new Promise(function(resolve) {
resolve("hello");
throw Error("foo");
}).then(function(localResult) {
result = localResult;
testPassed('fulfilled');
shouldBeEqualToString('result', 'hello');
finishJSTest();
}, function(localResult) {
result = localResult;
testFailed('rejected');
finishJSTest();
});
Test whether deeply chained then-s work.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS result is undefined
PASS result is 5042
PASS successfullyParsed is true
TEST COMPLETE
// Copyright 2014 the V8 project authors. All rights reserved.
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony
'use strict';
description('Test whether deeply chained then-s work.');
var result;
var resolve;
var promise = new Promise(function (r) { resolve = r; });
for (var i = 0; i < 5000; ++i) {
promise = promise.then(function (value) { return value + 1; }, function () { testFailed('rejected'); });
}
promise.then(function (value) {
result = value;
shouldBe('result', '5042');
}).then(finishJSTest, finishJSTest);
shouldBe('result', 'undefined');
resolve(42);
Test whether deeply chained then-s work.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS result is undefined
PASS result is 5042
PASS successfullyParsed is true
TEST COMPLETE
// Copyright 2014 the V8 project authors. All rights reserved.
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony
'use strict';
description('Test whether deeply chained then-s work.');
var result;
var reject;
var promise = new Promise(function (_, r) { reject = r; });
for (var i = 0; i < 5000; ++i) {
promise = promise.then(function (value) { testFailed('fulfilled'); throw value + 1; }, function (value) { throw value + 1; });
}
promise.catch(function (value) {
result = value;
shouldBe('result', '5042');
}).then(finishJSTest, finishJSTest);
shouldBe('result', 'undefined');
reject(42);
Test Promise rejection.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS promiseState is "pending"
PASS promiseState is "pending"
PASS promiseState is "rejected"
PASS promiseResult is "hello"
PASS successfullyParsed is true
TEST COMPLETE
// Copyright 2014 the V8 project authors. All rights reserved.
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony
'use strict';
description('Test Promise rejection.');
var reject;
var promise = new Promise(function(_, r) { reject = r; });
var promiseState = 'pending';
var promiseResult = undefined;
promise.then(function(result) {
promiseState = 'fulfilled';
promiseResult = result;
}, function(result) {
promiseState = 'rejected';
promiseResult = result;
});
shouldBeEqualToString('promiseState', 'pending');
reject('hello');
shouldBeEqualToString('promiseState', 'pending');
promise.then(function() {
testFailed('fulfilled.');
finishJSTest();
}, function() {
shouldBeEqualToString('promiseState', 'rejected');
shouldBeEqualToString('promiseResult', 'hello');
finishJSTest();
});
Test chained Promise resolutions.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS result is "hello"
PASS result is "bye"
PASS successfullyParsed is true
TEST COMPLETE
// Copyright 2014 the V8 project authors. All rights reserved.
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony
'use strict';
description('Test chained Promise resolutions.');
var resolve1, resolve2, resolve3;
var reject4, resolve5, resolve6;
var result;
var promise1 = new Promise(function(r) { resolve1 = r; });
var promise2 = new Promise(function(r) { resolve2 = r; });
var promise3 = new Promise(function(r) { resolve3 = r; });
var promise4 = new Promise(function(_, r) { reject4 = r; });
var promise5 = new Promise(function(r) { resolve5 = r; });
var promise6 = new Promise(function(r) { resolve6 = r; });
resolve3(promise2);
resolve2(promise1);
resolve6(promise5);
resolve5(promise4);
promise3.then(function(localResult) {
result = localResult;
shouldBeEqualToString('result', 'hello');
}, function() {
testFailed('rejected');
});
promise6.then(function() {
testFailed('fulfilled');
finishJSTest();
}, function(localResult) {
result = localResult;
shouldBeEqualToString('result', 'bye');
finishJSTest();
});
resolve1('hello');
reject4('bye');
Test Promise resolution.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS thisInOnFulfilled is undefined
PASS result is "hello"
PASS successfullyParsed is true
TEST COMPLETE
Test whether Promise processes microtasks in the correct order.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS promiseState is "pending"
PASS promiseState is "pending"
PASS promiseState is "fulfilled"
PASS promiseResult is "hello"
PASS successfullyParsed is true
TEST COMPLETE
// Copyright 2014 the V8 project authors. All rights reserved.
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony
'use strict';
description('Test whether Promise processes microtasks in the correct order.');
var resolve;
var promise = new Promise(function(r) { resolve = r; });
var promiseState = 'pending';
var promiseResult = undefined;
promise.then(function(result) {
promiseState = 'fulfilled';
promiseResult = result;
}, function(result) {
promiseState = 'rejected';
promiseResult = result;
});
shouldBeEqualToString('promiseState', 'pending');
resolve('hello');
shouldBeEqualToString('promiseState', 'pending');
promise.then(function() {
shouldBeEqualToString('promiseState', 'fulfilled');
shouldBeEqualToString('promiseResult', 'hello');
finishJSTest();
}, function() {
testFailed('promise is rejected.');
finishJSTest();
});
Test whether Promise will be rejected if it is resolved with itself.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS rejected
PASS result is "TypeError: Chaining cycle detected for promise #<Promise>"
PASS successfullyParsed is true
TEST COMPLETE
// Copyright 2014 the V8 project authors. All rights reserved.
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony
'use strict';
description('Test whether Promise will be rejected if it is resolved with itself.');
var resolve;
var result;
var promise = new Promise(function(r) { resolve = r; });
promise.then(function () {
testFailed('fulfilled');
}, function (error) {
testPassed('rejected');
result = error.toString();
shouldBeEqualToString('result', 'TypeError: Chaining cycle detected for promise #<Promise>');
}).then(finishJSTest, finishJSTest);
resolve(promise);
Test whether Promise treats thenable correctly.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
The promise is already rejected now.
PASS rejected
PASS result is "hello"
PASS successfullyParsed is true
TEST COMPLETE
// Copyright 2014 the V8 project authors. All rights reserved.
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony
'use strict';
description('Test whether Promise treats thenable correctly.');
var callback;
var result;
new Promise(function(resolve) {
resolve({then: function() { throw 'hello'; }});
}).then(function() {
testFailed('fulfilled');
finishJSTest();
}, function(localResult) {
testPassed('rejected');
result = localResult
shouldBeEqualToString('result', 'hello');
finishJSTest();
});
debug('The promise is already rejected now.');
Test whether Promise treats thenable correctly.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
The promise is not fulfilled now.
PASS value.then is called.
PASS thisValue is value
PASS fulfilled
PASS result is "hello"
PASS successfullyParsed is true
TEST COMPLETE
// Copyright 2014 the V8 project authors. All rights reserved.
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony
'use strict';
description('Test whether Promise treats thenable correctly.');
var thisValue;
var result;
var value = {
then: function(onFulfilled) {
testPassed('value.then is called.');
thisValue = this;
shouldBe('thisValue', 'value');
onFulfilled('hello');
}
};
new Promise(function(resolve) {
resolve(value);
}).then(function(localResult) {
testPassed('fulfilled');
result = localResult;
shouldBeEqualToString('result', 'hello');
finishJSTest();
}, function() {
testFailed('rejected');
finishJSTest();
});
debug('The promise is not fulfilled now.');
Test whether Promise treats thenable correctly.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
The promise is not rejected now.
PASS value.then is called.
PASS thisValue is value
PASS rejected
PASS result is "hello"
PASS successfullyParsed is true
TEST COMPLETE
// Copyright 2014 the V8 project authors. All rights reserved.
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony
'use strict';
description('Test whether Promise treats thenable correctly.');
var thisValue;
var result;
var value = {
then: function(onFulfilled, onRejected) {
testPassed('value.then is called.');
thisValue = this;
shouldBe('thisValue', 'value');
onRejected('hello');
}
};
new Promise(function(resolve) {
resolve(value);
}).then(function() {
testFailed('fulfilled');
finishJSTest();
}, function(localResult) {
testPassed('rejected');
result = localResult;
shouldBeEqualToString('result', 'hello');
finishJSTest();
});
debug('The promise is not rejected now.');
// Copyright 2014 the V8 project authors. All rights reserved.
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony
'use strict';
description('Test Promise resolution.');
var thisInOnFulfilled;
var result;
new Promise(function(resolve) {
resolve('hello');
}).then(function(localResult) {
thisInOnFulfilled = this;
shouldBe('thisInOnFulfilled', 'undefined');
result = localResult;
shouldBeEqualToString('result', 'hello');
finishJSTest();
}, function() {
fail('rejected');
finishJSTest();
});
Test Promise.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS thisInInit is undefined
PASS thisInOnFulfilled is undefined
PASS result is "hello"
PASS successfullyParsed is true
TEST COMPLETE
// Copyright 2014 the V8 project authors. All rights reserved.
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony
'use strict';
description('Test Promise.');
var resolve;
var thisInInit;
var thisInOnFulfilled;
var result;
new Promise(function(newResolve) {
thisInInit = this;
resolve = newResolve;
}).then(function(localResult) {
thisInOnFulfilled = this;
shouldBe('thisInOnFulfilled', 'undefined');
result = localResult;
shouldBeEqualToString('result', 'hello');
finishJSTest();
});
shouldBe('thisInInit', 'undefined');
resolve('hello');
Test Promise.all
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS result is undefined
PASS Promise.all() is rejected.
PASS Promise.all([]) is fulfilled.
PASS result.length is 0
PASS Promise.all([p1, p2, p3]) is fulfilled.
PASS result.length is 3
PASS result[0] is "p1"
PASS result[1] is "p2"
PASS result[2] is "p3"
PASS Promise.all([p1, p6, p5]) is rejected.
PASS result is "p6"
PASS Promise.all([p9]) is fulfilled.
PASS result.length is 1
PASS result[0] is "p2"
PASS Promise.all([p9,,,]) is fulfilled.
PASS result.length is 3
PASS result[0] is "p2"
PASS result[1] is undefined
PASS result[2] is undefined
PASS Promise.all([p9,42]) is fulfilled.
PASS result.length is 2
PASS result[0] is "p2"
PASS result[1] is 42
PASS Promise.all({}) is rejected.
PASS successfullyParsed is true
TEST COMPLETE
// Copyright 2014 the V8 project authors. All rights reserved.
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony
'use strict';
description('Test Promise.all');
var result = undefined;
var p1 = new Promise(function(resolve) { resolve('p1'); });
var p2 = new Promise(function(resolve) { resolve('p2'); });
var p3 = new Promise(function(resolve) { resolve('p3'); });
var p4 = new Promise(function() {});
var p5 = new Promise(function() {});
var p6 = new Promise(function(_, reject) { reject('p6'); });
var p7 = new Promise(function(_, reject) { reject('p7'); });
var p8 = new Promise(function(_, reject) { reject('p8'); });
var p9 = new Promise(function(resolve) { resolve(p2); });
Promise.all([p1, p2, p5]).then(function(result) {
testFailed('Promise.all([p1, p2, p5]) is fulfilled.');
}, function() {
testFailed('Promise.all([p1, p2, p5]) is rejected.');
});
Promise.all().then(function() {
testFailed('Promise.all() is fulfilled.');
}, function() {
testPassed('Promise.all() is rejected.');
return Promise.all([]).then(function(localResult) {
testPassed('Promise.all([]) is fulfilled.');
result = localResult;
shouldBe('result.length', '0');
}, function() {
testFailed('Promise.all([]) is rejected.');
});
}).then(function() {
return Promise.all([p1, p2, p3]).then(function(localResult) {
testPassed('Promise.all([p1, p2, p3]) is fulfilled.');
result = localResult;
shouldBe('result.length', '3');
shouldBeEqualToString('result[0]', 'p1');
shouldBeEqualToString('result[1]', 'p2');
shouldBeEqualToString('result[2]', 'p3');
}, function() {
testFailed('Promise.all([p1, p2, p3]) is rejected.');
});
}).then(function() {
return Promise.all([p1, p6, p5]).then(function(localResult) {
testFailed('Promise.all([p1, p6, p5]) is fulfilled.');
}, function(localResult) {
testPassed('Promise.all([p1, p6, p5]) is rejected.');
result = localResult;
shouldBeEqualToString('result', 'p6');
});
}).then(function() {
return Promise.all([p9]).then(function(localResult) {
testPassed('Promise.all([p9]) is fulfilled.');
result = localResult;
shouldBe('result.length', '1');
shouldBeEqualToString('result[0]', 'p2');
}, function(result) {
testFailed('Promise.all([p9]) is rejected.');
});
}).then(function() {
// Array hole should not be skipped.
return Promise.all([p9,,,]).then(function(localResult) {
testPassed('Promise.all([p9,,,]) is fulfilled.');
result = localResult;
shouldBe('result.length', '3');
shouldBeEqualToString('result[0]', 'p2');
shouldBe('result[1]', 'undefined');
shouldBe('result[2]', 'undefined');
}, function(localResult) {
testFailed('Promise.all([p9,,,]) is rejected.');
});
}).then(function() {
// Immediate value should be converted to a promise object by the
// ToPromise operation.
return Promise.all([p9,42]).then(function(localResult) {
testPassed('Promise.all([p9,42]) is fulfilled.');
result = localResult;
shouldBe('result.length', '2');
shouldBeEqualToString('result[0]', 'p2');
shouldBe('result[1]', '42');
}, function(localResult) {
testFailed('Promise.all([p9,42]) is rejected.');
});
}).then(function() {
return Promise.all({}).then(function(localResult) {
testFailed('Promise.all({}) is fulfilled.');
}, function(localResult) {
testPassed('Promise.all({}) is rejected.');
});
}).then(finishJSTest, finishJSTest);
shouldBe('result', 'undefined');
Test Promise.cast
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS promise is value
PASS result is undefined
PASS result2 is undefined
PASS result is "hello"
PASS result2 is 42
PASS fulfilled
PASS successfullyParsed is true
TEST COMPLETE
// Copyright 2014 the V8 project authors. All rights reserved.
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony
'use strict';
description('Test Promise.cast');
var result = undefined;
var result2 = undefined;
var resolve;
var value = new Promise(function (r) { resolve = r;} );
var promise = Promise.cast(value);
// If [[IsPromise]] is true, Promise.cast simply returns argument.
shouldBe('promise', 'value');
promise.then(function(res) {
result = res;
shouldBeEqualToString('result', 'hello');
return Promise.cast(42).then(function (res) {
result2 = res;
shouldBe('result2', '42');
});
}).then(function () {
testPassed('fulfilled');
finishJSTest();
}, function() {
testFailed('rejected');
finishJSTest();
});
resolve('hello');
shouldBe('result', 'undefined');
shouldBe('result2', 'undefined');
Test Promise.race
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS result is undefined
PASS Promise.race() is rejected.
PASS Promise.race({}) is rejected.
PASS Promise.race([p4, p1, p6]) is fulfilled.
PASS result is "p1"
PASS Promise.race([p4, p6, p1]) is rejected.
PASS result is "p6"
PASS Promise.race([p9]) is fulfilled.
PASS result is "p2"
PASS Promise.race([p4,,]) is fulfilled.
PASS result is undefined
PASS Promise.race([p4,42]) is fulfilled.
PASS result is 42
PASS successfullyParsed is true
TEST COMPLETE
// Copyright 2014 the V8 project authors. All rights reserved.
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony
'use strict';
description('Test Promise.race');
var result;
var p1 = new Promise(function(resolve) { resolve('p1'); });
var p2 = new Promise(function(resolve) { resolve('p2'); });
var p3 = new Promise(function(resolve) { resolve('p3'); });
var p4 = new Promise(function() {});
var p5 = new Promise(function() {});
var p6 = new Promise(function(_, reject) { reject('p6'); });
var p7 = new Promise(function(_, reject) { reject('p7'); });
var p8 = new Promise(function(_, reject) { reject('p8'); });
var p9 = new Promise(function(resolve) { resolve(p2); });
Promise.race([p4, p5]).then(function(localResult) {
testFailed('Promise.race([p4, p5]) is fulfilled.');
}, function() {
testFailed('Promise.race([p4, p5]) is rejected.');
});
// If the argument is an empty array, the result promise won't be fulfilled.
Promise.race([]).then(function(localResult) {
testFailed('Promise.race([]) is fulfilled.');
}, function() {
testFailed('Promise.race([]) is rejected.');
});
Promise.race().then(function(localResult) {
testFailed('Promise.race() is fulfilled.');
}, function() {
testPassed('Promise.race() is rejected.');
}).then(function() {
return Promise.race({}).then(function(localResult) {
testFailed('Promise.race({}) is fulfilled.');
}, function() {
testPassed('Promise.race({}) is rejected.');
});
}).then(function() {
return Promise.race([p4, p1, p6]).then(function(localResult) {
testPassed('Promise.race([p4, p1, p6]) is fulfilled.');
result = localResult;
shouldBeEqualToString('result', 'p1');
}, function() {
testFailed('Promise.race([p4, p1, p6]) is rejected.');
});
}).then(function() {
return Promise.race([p4, p6, p1]).then(function(localResult) {
testFailed('Promise.race([p4, p6, p1]) is fulfilled.');
}, function(localResult) {
testPassed('Promise.race([p4, p6, p1]) is rejected.');
result = localResult;
shouldBeEqualToString('result', 'p6');
});
}).then(function() {
return Promise.race([p9]).then(function(localResult) {
testPassed('Promise.race([p9]) is fulfilled.');
result = localResult;
shouldBeEqualToString('result', 'p2');
}, function() {
testFailed('Promise.race([p9]) is rejected.');
});
}).then(function() {
// Array hole should not be skipped.
return Promise.race([p4,,]).then(function(localResult) {
testPassed('Promise.race([p4,,]) is fulfilled.');
result = localResult;
shouldBe('result', 'undefined');
}, function() {
testFailed('Promise.race([p4,,]) is rejected.');
});
}).then(function() {
// Immediate value should be converted to a promise object by the
// ToPromise operation.
return Promise.race([p4,42]).then(function(localResult) {
testPassed('Promise.race([p4,42]) is fulfilled.');
result = localResult;
shouldBe('result', '42');
}, function() {
testFailed('Promise.race([p4,42]) is rejected.');
});
}).then(finishJSTest, finishJSTest);
shouldBe('result', 'undefined');
Test Promise.reject
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS result is undefined
PASS result is "hello"
PASS successfullyParsed is true
TEST COMPLETE
// Copyright 2014 the V8 project authors. All rights reserved.
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony
'use strict';
description('Test Promise.reject');
var result = undefined;
Promise.reject('hello').then(function(result) {
testFailed('fulfilled');
finishJSTest();
}, function(localResult) {
result = localResult;
shouldBeEqualToString('result', 'hello');
finishJSTest();
});
shouldBe('result', 'undefined');
Test Promise.resolve
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS result is undefined
PASS result is "hello"
PASS successfullyParsed is true
TEST COMPLETE
// Copyright 2014 the V8 project authors. All rights reserved.
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony
'use strict';
description('Test Promise.resolve');
var result = undefined;
var resolve;
var promise = Promise.resolve(new Promise(function (r) { resolve = r;} ));
promise.then(function(localResult) {
result = localResult;
shouldBeEqualToString('result', 'hello');
finishJSTest();
}, function() {
testFailed('rejected');
finishJSTest();
});
resolve('hello');
shouldBe('result', 'undefined');
Test whether then callback receivers are correctly set.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS fulfilled
PASS thisInOnFulfilled is undefined
PASS rejected
PASS thisInOnRejected is undefined
PASS successfullyParsed is true
TEST COMPLETE
// Copyright 2014 the V8 project authors. All rights reserved.
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony
'use strict';
description('Test whether then callback receivers are correctly set.');
var thisInOnFulfilled;
var thisInOnRejected;
Promise.resolve().then(function () {
return Promise.resolve(42).then(function () {
testPassed('fulfilled');
thisInOnFulfilled = this;
shouldBe('thisInOnFulfilled', 'undefined');
}, function () {
testFailed('rejected');
});
}).then(function () {
return Promise.reject(42).then(function () {
testFailed('fulfilled');
}, function () {
testPassed('rejected');
thisInOnRejected = this;
shouldBe('thisInOnRejected', 'undefined');
});
}).then(finishJSTest, finishJSTest);
Test Promise.prototype.then
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS thisInInit is undefined
PASS firstPromise instanceof Promise is true
PASS secondPromise instanceof Promise is true
PASS thisInOnFulfilled is undefined
PASS result is "hello"
PASS result is "world"
PASS rejected
PASS result is "exception"
PASS resolved
PASS successfullyParsed is true
TEST COMPLETE
Promise.prototype.then should work without callbacks.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS result is "hello"
PASS successfullyParsed is true
TEST COMPLETE
// Copyright 2014 the V8 project authors. All rights reserved.
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony
'use strict';
description('Promise.prototype.then should work without callbacks.');
var result;
new Promise(function(resolve) { resolve('hello'); }).then(
// then without callbacks
).then(function(localResult) {
result = localResult;
shouldBeEqualToString('result', 'hello');
finishJSTest();
});
// Copyright 2014 the V8 project authors. All rights reserved.
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony
'use strict';
description('Test Promise.prototype.then');
var resolve;
var result;
var thisInOnFulfilled;
var thisInInit;
var firstPromise = new Promise(function(newResolve) {
thisInInit = this;
resolve = newResolve;
});
var secondPromise = firstPromise.then(function(localResult) {
thisInOnFulfilled = this;
shouldBe('thisInOnFulfilled', 'undefined');
result = localResult;
shouldBeEqualToString('result', 'hello');
return 'world';
});
shouldBe('thisInInit', 'undefined');
shouldBeTrue('firstPromise instanceof Promise');
shouldBeTrue('secondPromise instanceof Promise');
secondPromise.then(undefined, 37).then(function(localResult) {
result = localResult;
shouldBeEqualToString('result', 'world');
throw 'exception'
}).then(1, 2).then(function() {
testFailed('resolved');
}, function(localResult) {
testPassed('rejected');
result = localResult;
shouldBeEqualToString('result', 'exception');
}).then(function() {
testPassed('resolved');
finishJSTest();
}, function() {
testFailed('rejected');
finishJSTest();
});
resolve('hello');
......@@ -30,6 +30,9 @@
# BUG(237872). TODO(bmeurer): Investigate.
'string-replacement-outofmemory': [FAIL],
# TODO(rossberg): Awaiting spec resolution (https://bugs.ecmascript.org/show_bug.cgi?id=2566)
'fast/js/Promise-then': [FAIL],
##############################################################################
# Flaky tests.
# BUG(v8:2989).
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment