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

Unified Diff: tests/html/js_function_getter_trust_types_test.dart

Issue 1431523002: Fix behavior when typed JS interop getters are called as functions. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: PTAL 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/js_function_getter_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/html/js_function_getter_trust_types_test.dart
diff --git a/tests/html/js_function_getter_trust_types_test.dart b/tests/html/js_function_getter_trust_types_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..3e94b503a46fc3092ef481f3d707ac0856098ea0
--- /dev/null
+++ b/tests/html/js_function_getter_trust_types_test.dart
@@ -0,0 +1,72 @@
+// 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.
+
+// SharedOptions=--trust-type-annotations
+@JS()
+library js_function_getter_trust_types_test;
+
+import 'dart:html';
+
+import 'package:js/js.dart';
+import 'package:unittest/unittest.dart';
+import 'package:unittest/html_config.dart';
+import 'package:unittest/html_individual_config.dart';
+
+_injectJs() {
+ document.body.append(new ScriptElement()
+ ..type = 'text/javascript'
+ ..innerHtml = r"""
+ var bar = { };
+
+ bar.nonFunctionStatic = function() {
+ return arguments.length * 2;
+ };
+
+ bar.add = function(a, b) {
+ return a + b;
+ };
+
+ var foo = { 'bar' : bar };
+""");
+}
+
+typedef int AddFn(int x, int y);
+
+@JS()
+class NotAFn { }
+
+@JS()
+abstract class Bar {
+ external AddFn get add;
+ external NotAFn get nonFunctionStatic;
+}
+
+@JS()
+abstract class Foo {
+ external Bar get bar;
+}
+
+@JS()
+external Foo get foo;
+
+main() {
+ _injectJs();
+
+ useHtmlIndividualConfiguration();
+
+ group('trust types', () {
+ test('static nonFunctionStatic', () {
+ expect(() => foo.bar.nonFunctionStatic(), throws);
+ expect(() => foo.bar.nonFunctionStatic(0), throws);
+ expect(() => foo.bar.nonFunctionStatic(0,0), throws);
+ expect(() => foo.bar.nonFunctionStatic(0,0,0,0,0,0), throws);
+ });
+
+ test('typedef function', () {
+ expect(() => foo.bar.add(4), throws);
+ expect(() => foo.bar.add(4,5,10), throws);
+ expect(foo.bar.add(4,5), equals(9));
+ });
+ });
+}
« no previous file with comments | « tests/html/js_function_getter_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698