| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 // Accessing static native methods names: | 5 // Accessing static native methods names: |
| 6 // plain declaration -> use @Native tag as 'scope' for declared name. | 6 // plain declaration -> use @Native tag as 'scope' for declared name. |
| 7 // identifier @JSName -> use @Native tag as 'scope' for @JSName. | 7 // identifier @JSName -> use @Native tag as 'scope' for @JSName. |
| 8 // other @JSName -> use @JSName as an expression. | 8 // other @JSName -> use @JSName as an expression. |
| 9 | 9 |
| 10 import 'native_testing.dart'; | 10 import 'native_testing.dart'; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 static int lepton(Callback c) native; | 30 static int lepton(Callback c) native; |
| 31 static int electron(c) => lepton(c); | 31 static int electron(c) => lepton(c); |
| 32 | 32 |
| 33 // Compiler should automatically use the tag and JSName, i.e. call | 33 // Compiler should automatically use the tag and JSName, i.e. call |
| 34 // `CC.baryon`. | 34 // `CC.baryon`. |
| 35 @JSName('baryon') | 35 @JSName('baryon') |
| 36 static int _baryon(Callback c) native; | 36 static int _baryon(Callback c) native; |
| 37 static int proton(c) => _baryon(c); | 37 static int proton(c) => _baryon(c); |
| 38 } | 38 } |
| 39 | 39 |
| 40 void setup() native r""" | 40 void setup() { |
| 41 // This code is all inside 'setup' and so not accessible from the global scope. | 41 JS('', r""" |
| 42 (function(){ |
| 43 // This code is inside 'setup' and so not accessible from the global scope. |
| 42 | 44 |
| 43 function CC(){} | 45 function CC(){} |
| 44 | 46 |
| 45 CC.foo = function(s) { return s.length; } | 47 CC.foo = function(s) { return s.length; }; |
| 46 CC.bar = function(f) { return f("Bye"); } | 48 CC.bar = function(f) { return f("Bye"); }; |
| 47 CC.lepton = function(f) { return f("Lepton"); } | 49 CC.lepton = function(f) { return f("Lepton"); }; |
| 48 CC.baryon = function(f) { return f("three quarks"); } | 50 CC.baryon = function(f) { return f("three quarks"); }; |
| 49 | 51 |
| 50 self.CC = CC; | 52 self.CC = CC; |
| 51 """; | 53 })()"""); |
| 54 } |
| 52 | 55 |
| 53 main() { | 56 main() { |
| 54 nativeTesting(); | 57 nativeTesting(); |
| 55 setup(); | 58 setup(); |
| 56 | 59 |
| 57 // TODO(sra): Investigate why this line is necessary to get a correctly | 60 // TODO(sra): Investigate why this line is necessary to get a correctly |
| 58 // compiled convertDartClosureToJS. Without this line, the compiler crashes. | 61 // compiled convertDartClosureToJS. Without this line, the compiler crashes. |
| 59 convertDartClosureToJS(main, 1); | 62 convertDartClosureToJS(main, 1); |
| 60 | 63 |
| 61 Expect.equals(5, AA.foo("Hello")); | 64 Expect.equals(5, AA.foo("Hello")); |
| 62 | 65 |
| 63 Expect.equals(3, AA.bar((s) => s.length)); | 66 Expect.equals(3, AA.bar((s) => s.length)); |
| 64 Expect.equals(3, AA.baz((s) => s.length)); | 67 Expect.equals(3, AA.baz((s) => s.length)); |
| 65 | 68 |
| 66 Expect.equals(6, AA.lepton((s) => s.length)); | 69 Expect.equals(6, AA.lepton((s) => s.length)); |
| 67 Expect.equals(6, AA.electron((s) => s.length)); | 70 Expect.equals(6, AA.electron((s) => s.length)); |
| 68 | 71 |
| 69 Expect.equals(12, AA._baryon((s) => s.length)); | 72 Expect.equals(12, AA._baryon((s) => s.length)); |
| 70 Expect.equals(12, AA.proton((s) => s.length)); | 73 Expect.equals(12, AA.proton((s) => s.length)); |
| 71 Expect.throws(() => AA.baryon((s) => s.length)); // Not defined on AA. | 74 Expect.throws(() => AA.baryon((s) => s.length)); // Not defined on AA. |
| 72 } | 75 } |
| OLD | NEW |