OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 import "dart:_js_helper"; | 5 import "dart:_js_helper"; |
6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
7 | 7 |
8 makeCC() native; | 8 makeCC() native ; |
9 | 9 |
10 void setup() native """ | 10 void setup() native """ |
11 function CC() {} | 11 function CC() {} |
12 makeCC = function() { return new CC; } | 12 makeCC = function() { return new CC; } |
13 """; | 13 """; |
14 | 14 |
15 | |
16 @Native("CC") | 15 @Native("CC") |
17 class ClickCounter { | 16 class ClickCounter { |
18 var status; | 17 var status; |
19 | 18 |
20 var foo; | 19 var foo; |
21 | 20 |
22 init() { | 21 init() { |
23 foo = wrap(g); | 22 foo = wrap(g); |
24 } | 23 } |
25 | 24 |
26 g(val) => "### $val ###"; | 25 g(val) => "### $val ###"; |
27 } | 26 } |
28 | 27 |
29 wrap(cb) { | 28 wrap(cb) { |
30 return (val) { | 29 return (val) { |
31 return cb("!!! $val !!!"); | 30 return cb("!!! $val !!!"); |
32 }; | 31 }; |
33 } | 32 } |
34 | 33 |
35 main() { | 34 main() { |
36 setup(); | 35 setup(); |
37 var c = makeCC(); | 36 var c = makeCC(); |
38 c.init(); | 37 c.init(); |
39 // `foo` contains a closure. Make sure that invoking foo through an | 38 // `foo` contains a closure. Make sure that invoking foo through an |
40 // interceptor works. | 39 // interceptor works. |
41 Expect.equals("### !!! 499 !!! ###", c.foo(499)); | 40 Expect.equals("### !!! 499 !!! ###", c.foo(499)); |
42 } | 41 } |
OLD | NEW |