Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(438)

Unified Diff: tests/html/mirrors_js_typed_interop_test.dart

Issue 1318043005: Support user generated custom native JS classes. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: about to land Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/html/json_helper.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..20bb91df0ec4c9d950f3c3e407c16c92d605c615
--- /dev/null
+++ b/tests/html/mirrors_js_typed_interop_test.dart
@@ -0,0 +1,48 @@
+// 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 'package:js/js.dart';
+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; },
+ };
+""");
+}
+
+@Js()
+external Foo get foo;
+
+@Js()
+class Foo {
+ external int get x;
+ external int set x(v);
+ external num multiplyBy2(num y);
+}
+
+main() {
+ _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);
+ });
+}
« no previous file with comments | « tests/html/json_helper.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698