Index: test/webkit/fast/js/Promise-catch.js |
diff --git a/test/webkit/throw-from-finally.js b/test/webkit/fast/js/Promise-catch.js |
similarity index 57% |
copy from test/webkit/throw-from-finally.js |
copy to test/webkit/fast/js/Promise-catch.js |
index 183245d8d1ade776fcfbbc822236a3a8009537cd..88b053a538888ffea20b0ba302a76728fe3eef72 100644 |
--- a/test/webkit/throw-from-finally.js |
+++ b/test/webkit/fast/js/Promise-catch.js |
@@ -1,4 +1,4 @@ |
-// Copyright 2013 the V8 project authors. All rights reserved. |
+// 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 |
@@ -21,60 +21,51 @@ |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
-description( |
-"This tests that throwing from a finally block has the expected effect." |
-); |
+// Flags: --harmony |
+'use strict'; |
+description('Test Promise.prototype.catch.'); |
-var events = []; |
+var reject; |
+var result; |
+var thisInInit; |
+var thisInOnFulfilled; |
-try { |
- events.push("1:try"); |
-} finally { |
- events.push("1:finally"); |
-} |
+var firstPromise = new Promise(function(_, newReject) { |
+ thisInInit = this; |
+ reject = newReject; |
+}); |
-try { |
- try { |
- throw "2:thingy"; |
- } finally { |
- events.push("2:finally"); |
- } |
-} catch (e) { |
- events.push(e); |
-} |
+var secondPromise = firstPromise.catch(function(localResult) { |
+ thisInOnFulfilled = this; |
+ shouldBe('thisInOnFulfilled', 'undefined'); |
+ result = localResult; |
+ shouldBeEqualToString('result', 'hello'); |
+ return 'bye'; |
+}); |
-try { |
- throw "3:thingy"; |
-} catch (e) { |
- events.push(e); |
-} finally { |
- events.push("3:finally"); |
-} |
+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 { |
- try { |
- throw "4:thingy"; |
- } catch (e) { |
- events.push(e); |
- } finally { |
- events.push("4:finally"); |
- throw "4:another thingy"; |
- } |
+ firstPromise.catch(null); |
} catch (e) { |
- events.push(e); |
+ testFailed('catch(null) should not throw an exception'); |
} |
- |
try { |
- for (;;) { |
- try { |
- continue; |
- } finally { |
- events.push("5:hi"); |
- throw "5:wat"; |
- } |
- } |
+ firstPromise.catch(37); |
} catch (e) { |
- events.push(e); |
+ testFailed('catch(37) should not throw an exception'); |
} |
-shouldBe("\"\" + events", "\"1:try,1:finally,2:finally,2:thingy,3:thingy,3:finally,4:thingy,4:finally,4:another thingy,5:hi,5:wat\""); |
+reject('hello'); |