OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <script src="../../resources/js-test.js"></script> |
| 5 </head> |
| 6 <body> |
| 7 <div id="description"></div> |
| 8 <div id="console"></div> |
| 9 <script> |
| 10 description('Test whether the generated code handles exceptions correctly.'); |
| 11 |
| 12 window.jsTestIsAsync = true; |
| 13 |
| 14 var reason; |
| 15 |
| 16 function shouldBeRejected(promise, message) { |
| 17 return promise.then(function() { |
| 18 testFailed('Resolved unexpectedly: ' + message); |
| 19 }, function(e) { |
| 20 reason = e; |
| 21 testPassed('Rejected as expected: ' + message); |
| 22 shouldBeTrue('reason instanceof Error'); |
| 23 debug(e); |
| 24 }); |
| 25 } |
| 26 |
| 27 function shouldBeResolved(promise, message) { |
| 28 return promise.then(function() { |
| 29 testPassed('Resolved as expected: ' + message); |
| 30 }, function(e) { |
| 31 testFailed('Rejected unexpectedly: ' + message); |
| 32 reason = e; |
| 33 shouldBeTrue('reason instanceof Error'); |
| 34 debug(e); |
| 35 }); |
| 36 } |
| 37 |
| 38 var check = internals.promiseCheck.bind(internals); |
| 39 var check2 = internals.promiseCheckWithoutExceptionState.bind(internals); |
| 40 var check3 = internals.promiseCheckRange.bind(internals); |
| 41 |
| 42 Promise.resolve().then(function() { |
| 43 return shouldBeRejected(check(), 'no arguments'); |
| 44 }).then(function() { |
| 45 return shouldBeResolved(check(3, true, {}, ''), 'valid arguments'); |
| 46 }).then(function() { |
| 47 return shouldBeResolved(check(null, true, {}, ''), 'convert(long)'); |
| 48 }).then(function() { |
| 49 return shouldBeResolved(check(3, {}, {}, ''), 'convert(boolean)'); |
| 50 }).then(function() { |
| 51 return shouldBeRejected(check(3, true, 3, ''), 'type error(Dictionary)'); |
| 52 }).then(function() { |
| 53 return shouldBeResolved(check(3, true, {}, {}), 'convert(String)'); |
| 54 }).then(function() { |
| 55 var x = { |
| 56 toString: function() { |
| 57 throw Error('Thrown from toString'); |
| 58 } |
| 59 }; |
| 60 return shouldBeRejected(check(3, true, {}, x), 'conversion error(toString)'); |
| 61 }).then(function() { |
| 62 return shouldBeRejected(check(3, false, {}, ''), 'rejected by the impl'); |
| 63 }).then(function() { |
| 64 return shouldBeRejected(check2(), 'no arguments'); |
| 65 }).then(function() { |
| 66 return shouldBeResolved(check2({}, '', '', ''), 'valid arguments'); |
| 67 }).then(function() { |
| 68 return shouldBeResolved(check2({}, ''), 'valid arguments'); |
| 69 }).then(function() { |
| 70 return shouldBeRejected(check2(3, ''), 'type error(Dictionary)'); |
| 71 }).then(function() { |
| 72 return shouldBeResolved(check2({}, '', {}, 3), 'convert(String...)'); |
| 73 }).then(function() { |
| 74 var x = { |
| 75 toString: function() { |
| 76 throw Error('Thrown from toString'); |
| 77 } |
| 78 }; |
| 79 return shouldBeRejected(check2({}, '', '', x), 'conversion error(String...)'); |
| 80 }).then(function() { |
| 81 return shouldBeRejected(check3(-1), 'range error(octet)'); |
| 82 }).then(undefined, function(e) { |
| 83 testFailed('An exception is thrown from a method'); |
| 84 debug(e); |
| 85 }).then(finishJSTest, finishJSTest); |
| 86 |
| 87 </script> |
| 88 </body> |
| 89 </html> |
OLD | NEW |