Index: tests/html/mirrors_js_typed_interop_test.dart |
diff --git a/tests/html/mirrors_js_typed_interop_test.dart b/tests/html/mirrors_js_typed_interop_test.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..fb39dad12bebf9d8bba2a3e52604e322f015a4e8 |
--- /dev/null |
+++ b/tests/html/mirrors_js_typed_interop_test.dart |
@@ -0,0 +1,57 @@ |
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+ |
+library tests.html.mirrors_js_typed_interop_test; |
+ |
+import 'dart:mirrors'; |
+import 'dart:html'; |
+import 'dart:js'; |
+ |
+import 'package:unittest/unittest.dart'; |
+import 'package:unittest/html_config.dart'; |
+ |
+_injectJs() { |
+ document.body.append(new ScriptElement() |
+ ..type = 'text/javascript' |
+ ..innerHtml = r""" |
+ window.foo = { |
+ x: 3, |
+ z: 100, |
+ multiplyBy2: function(arg) { return arg * 2; }, |
+ }; |
+"""); |
+} |
+ |
+// TODO(jacobr): depend on package:js instead of defining this annotation here. |
+class JsName { |
+ const JsName(); |
+} |
+ |
+@JsName() |
+external Foo get foo; |
+ |
+@JsName() |
+class Foo extends JavaScriptObject { |
+ external int get x; |
+ external int set x(v); |
+ external num multiplyBy2(num y); |
+} |
+ |
+main() { |
+ // Call experimental API to register Dart interfaces implemented by |
+ // JavaScript classes. |
+ registerJsInterfaces([Foo]); |
+ |
+ _injectJs(); |
+ |
+ useHtmlConfiguration(); |
+ |
+ test('dynamic dispatch', () { |
+ var f = foo; |
+ expect(f.x, 3); |
+ // JsInterop methods are not accessible using reflection. |
+ expect(() => reflect(f).setField(#x, 123), throws); |
+ expect(f.x, 3); |
+ }); |
+} |