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