Skip to content

Commit bbb0c3f

Browse files
committed
Seems like this is all that is required to support callable JS objects. dartbug.com/25321
BUG= R=sra@google.com Review URL: https://codereview.chromium.org/2164483004 .
1 parent db48637 commit bbb0c3f

File tree

4 files changed

+73
-7
lines changed

4 files changed

+73
-7
lines changed

pkg/compiler/lib/src/diagnostics/messages.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3703,11 +3703,6 @@ Your app imports dart:mirrors via:"""
37033703
"""
37043704
$MIRRORS_NOT_SUPPORTED_BY_BACKEND_PADDING#{importChain}"""),
37053705

3706-
MessageKind.CALL_NOT_SUPPORTED_ON_NATIVE_CLASS: const MessageTemplate(
3707-
MessageKind.CALL_NOT_SUPPORTED_ON_NATIVE_CLASS,
3708-
"Non-supported 'call' member on a native class, or a "
3709-
"subclass of a native class."),
3710-
37113706
MessageKind.DIRECTLY_THROWING_NSM: const MessageTemplate(
37123707
MessageKind.DIRECTLY_THROWING_NSM,
37133708
"This 'noSuchMethod' implementation is guaranteed to throw an "

pkg/compiler/lib/src/js_backend/backend.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -945,8 +945,6 @@ class JavaScriptBackend extends Backend {
945945
cls.ensureResolved(resolution);
946946
cls.forEachMember((ClassElement classElement, Element member) {
947947
if (member.name == Identifiers.call) {
948-
reporter.reportErrorMessage(
949-
member, MessageKind.CALL_NOT_SUPPORTED_ON_NATIVE_CLASS);
950948
return;
951949
}
952950
if (member.isSynthesized) return;

tests/html/html.status

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ js_interop_1_test: SkipByDesign
358358
js_test: SkipByDesign
359359
js_array_test: SkipByDesign
360360
js_typed_interop_bind_this_test: SkipByDesign
361+
js_typed_interop_callable_object_test: SkipByDesign
361362
js_typed_interop_test: SkipByDesign
362363
js_typed_interop_default_arg_test: SkipByDesign
363364
js_typed_interop_type_test: SkipByDesign
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
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.
4+
5+
@JS()
6+
library js_typed_interop_callable_object_test;
7+
8+
import 'dart:html';
9+
10+
import 'package:expect/expect.dart' show NoInline, AssumeDynamic;
11+
import 'package:js/js.dart';
12+
import 'package:unittest/html_config.dart';
13+
import 'package:unittest/html_individual_config.dart';
14+
import 'package:unittest/unittest.dart';
15+
16+
// This is a regression test for https://github.com/dart-lang/sdk/issues/25658
17+
18+
@NoInline()
19+
@AssumeDynamic()
20+
confuse(x) => x;
21+
22+
_injectJs() {
23+
document.body.append(new ScriptElement()
24+
..type = 'text/javascript'
25+
..innerHtml = r"""
26+
"use strict";
27+
28+
window.callableObject = function (a, b) { return a + b; };
29+
window.callableObject.foo = function() { return "bar"; };
30+
window.callableObject.bar = 42;
31+
32+
""");
33+
}
34+
35+
@JS()
36+
@anonymous
37+
class CallableObject {
38+
/// If a @JS class implements `call`, the underlying representation must be
39+
/// a JavaScript callable (i.e. function).
40+
external num call(num a, num b);
41+
external int get bar;
42+
external String foo();
43+
}
44+
45+
@JS()
46+
external CallableObject get callableObject;
47+
48+
main() {
49+
_injectJs();
50+
51+
useHtmlIndividualConfiguration();
52+
53+
group('callable object', () {
54+
test('simple', () {
55+
var obj = callableObject;
56+
expect(obj(4, 5), equals(9));
57+
expect(obj.bar, equals(42));
58+
expect(obj.foo(), equals("bar"));
59+
60+
expect(callableObject(4, 5), equals(9));
61+
expect(callableObject.bar, equals(42));
62+
expect(callableObject.foo(), equals("bar"));
63+
});
64+
65+
test('dynamic', () {
66+
var obj = confuse(callableObject);
67+
expect(obj(4, 5), equals(9));
68+
expect(obj.bar, equals(42));
69+
expect(obj.foo(), equals("bar"));
70+
});
71+
});
72+
}

0 commit comments

Comments
 (0)