| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library isolate_unhandled_exception_uri_helper; | 5 library isolate_unhandled_exception_uri_helper; |
| 6 | 6 |
| 7 import 'dart:isolate'; | 7 import 'dart:isolate'; |
| 8 import 'dart:io'; | |
| 9 | 8 |
| 10 // Tests that isolate code in another script keeps message handling working | 9 // Tests that isolate code in another script keeps message handling working |
| 11 // after throwing an unhandled exception, if it has a function called | 10 // after throwing an unhandled exception, if it has a function called |
| 12 // unhandledExceptionCallback that returns true (continue handling). | 11 // unhandledExceptionCallback that returns true (continue handling). |
| 13 | 12 |
| 14 // Note: this test will hang if an uncaught exception isn't handled, | 13 // Note: this test will hang if an uncaught exception isn't handled, |
| 15 // either by an error in the callback or it returning false. | 14 // either by an error in the callback or it returning false. |
| 16 | 15 |
| 17 void main() { | 16 void main() { |
| 18 var isolate_port = spawnUri('isolate_unhandled_exception_uri_helper.dart'); | 17 var isolate_port = spawnUri('isolate_unhandled_exception_uri_helper.dart'); |
| 19 | 18 |
| 20 // Send a message that will cause an ignorable exception to be thrown. | 19 // Send a message that will cause an ignorable exception to be thrown. |
| 21 Future f = isolate_port.call('throw exception'); | 20 Future f = isolate_port.call('throw exception'); |
| 22 f.onComplete((future) { | 21 f.onComplete((future) { |
| 23 if (future.exception != null) { | 22 Expect.equals(null, future.exception); |
| 24 // Exception wasn't ignored as it was supposed to be. | |
| 25 print('failed handling exception'); | |
| 26 exit(1); | |
| 27 } | |
| 28 }); | 23 }); |
| 29 | 24 |
| 30 // Verify that isolate can still handle messages. | 25 // Verify that isolate can still handle messages. |
| 31 isolate_port.call('hi').onComplete((future) { | 26 isolate_port.call('hi').onComplete((future) { |
| 32 if (future.exception != null) { | 27 Expect.equals(null, future.exception); |
| 33 print('unhandled exception: ${future.exception}'); | 28 Expect.equals('hello', future.value); |
| 34 exit(1); | |
| 35 } | |
| 36 if (future.value != 'hello') { | |
| 37 print('unexpected response: ${future.value}'); | |
| 38 exit(1); | |
| 39 } | |
| 40 exit(0); | |
| 41 }); | 29 }); |
| 30 |
| 42 } | 31 } |
| OLD | NEW |