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

Unified Diff: tests/html/js_typed_interop_callable_object_test.dart

Issue 2164483004: Allow callable JS objects. dartbug.com/25321 (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Seems like this is all that is required to support callable JS objects. dartbug.com/25321 Created 4 years, 5 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 | « pkg/compiler/lib/src/js_backend/backend.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_typed_interop_callable_object_test.dart
diff --git a/tests/html/js_typed_interop_callable_object_test.dart b/tests/html/js_typed_interop_callable_object_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..002ee59ef36d5dc2ae17e8956396e0daede3d16b
--- /dev/null
+++ b/tests/html/js_typed_interop_callable_object_test.dart
@@ -0,0 +1,72 @@
+// Copyright (c) 2016, 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.
+
+@JS()
+library js_typed_interop_bind_this_test;
+
+import 'dart:html';
+
+import 'package:expect/expect.dart' show NoInline, AssumeDynamic;
+import 'package:js/js.dart';
+import 'package:unittest/html_config.dart';
+import 'package:unittest/html_individual_config.dart';
+import 'package:unittest/unittest.dart';
+
+// This is a regression test for https://github.com/dart-lang/sdk/issues/25658
+
+@NoInline()
+@AssumeDynamic()
+confuse(x) => x;
+
+_injectJs() {
+ document.body.append(new ScriptElement()
+ ..type = 'text/javascript'
+ ..innerHtml = r"""
+ "use strict";
+
+ window.callableObject = function (a, b) { return a + b; };
+ window.callableObject.foo = function() { return "bar"; };
+ window.callableObject.bar = 42;
+
+""");
+}
+
+@JS()
+@anonymous
+class CallableObject {
+ /// If a @JS class implements `call`, the underlying representation must be
+ /// a JavaScript callable (i.e. function).
+ external num call(num a, num b);
+ external int get bar;
+ external String foo();
+}
+
+@JS()
+external CallableObject get callableObject;
+
+main() {
+ _injectJs();
+
+ useHtmlIndividualConfiguration();
+
+ group('callable object', () {
+ test('simple', () {
+ var obj = callableObject;
+ expect(obj(4, 5), equals(9));
+ expect(obj.bar, equals(42));
+ expect(obj.foo(), equals("bar"));
+
+ expect(callableObject(4, 5), equals(9));
+ expect(callableObject.bar, equals(42));
+ expect(callableObject.foo(), equals("bar"));
+ });
+
+ test('dynamic', () {
+ var obj = confuse(callableObject);
+ expect(obj(4, 5), equals(9));
+ expect(obj.bar, equals(42));
+ expect(obj.foo(), equals("bar"));
+ });
+ });
+}
« no previous file with comments | « pkg/compiler/lib/src/js_backend/backend.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698