mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 04:27:17 +00:00
5ff2459d88
These annotations have all been replaced with @pragma('dart2js:xxx') versions: @ForceInline, @NoInline, @NoThrows, @NoSideEffects, @AssumeDynamic. Change-Id: Ia4730670c6864ccbe0fa4120108c3c16ab887c23 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/208863 Reviewed-by: Sigmund Cherem <sigmund@google.com> Commit-Queue: Stephen Adams <sra@google.com>
68 lines
1.6 KiB
Dart
68 lines
1.6 KiB
Dart
// 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_callable_object_test;
|
|
|
|
import 'dart:html';
|
|
|
|
import 'package:js/js.dart';
|
|
import 'package:expect/minitest.dart';
|
|
|
|
// This is a regression test for https://github.com/dart-lang/sdk/issues/25658
|
|
|
|
@pragma('dart2js:noInline')
|
|
@pragma('dart2js: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();
|
|
|
|
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"));
|
|
});
|
|
});
|
|
}
|