| 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 // Test that exception unwrapping handle cases like ({foo:null}).foo(). |
| 6 |
| 7 import 'dart:_js_helper'; |
| 8 |
| 5 import "package:expect/expect.dart"; | 9 import "package:expect/expect.dart"; |
| 6 | 10 |
| 7 typedef void MyFunctionType(); | 11 typedef void MyFunctionType(); |
| 8 | 12 |
| 9 class A native "A" { | 13 class A native "A" { |
| 10 setClosure(MyFunctionType f) native; | 14 setClosure(MyFunctionType f) native; |
| 11 check(MyFunctionType f) native; | 15 check(MyFunctionType f) native; |
| 12 invoke() native; | 16 invoke() native; |
| 13 } | 17 } |
| 14 | 18 |
| 15 makeA() native { return new A(); } | 19 makeA() native { return new A(); } |
| 16 | 20 |
| 17 void setup() native """ | 21 void setup() native """ |
| 18 function A() {} | 22 function A() {} |
| 19 A.prototype.setClosure = function(f) { this.f = f; }; | 23 A.prototype.setClosure = function(f) { this.f = f; }; |
| 20 A.prototype.check = function(f) { return this.f === f; }; | 24 A.prototype.check = function(f) { return this.f === f; }; |
| 21 A.prototype.invoke = function() { return this.f(); }; | 25 A.prototype.invoke = function() { return this.f(); }; |
| 22 makeA = function(){return new A;}; | 26 makeA = function(){return new A;}; |
| 23 """; | 27 """; |
| 24 | 28 |
| 25 | |
| 26 main() { | 29 main() { |
| 27 setup(); | 30 setup(); |
| 28 A a = makeA(); | 31 A a = makeA(); |
| 29 a.setClosure(null); | 32 a.setClosure(null); |
| 30 Expect.isTrue(a.check(null)); | 33 Expect.isTrue(a.check(null)); |
| 31 bool caughtException = false; | 34 bool caughtException = false; |
| 32 try { | 35 try { |
| 33 a.invoke(); | 36 a.invoke(); |
| 34 } on Exception catch (e) { | 37 } on JsNoSuchMethodError catch (e) { |
| 38 print(e); |
| 35 caughtException = true; | 39 caughtException = true; |
| 36 } | 40 } |
| 37 Expect.isTrue(caughtException); | 41 Expect.isTrue(caughtException); |
| 38 } | 42 } |
| OLD | NEW |