2020-04-03 00:36:56 +00:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
@JS()
|
|
|
|
library js_typed_interop_test;
|
|
|
|
|
|
|
|
import 'dart:html';
|
|
|
|
|
|
|
|
import 'package:js/js.dart';
|
|
|
|
import 'package:expect/minitest.dart';
|
|
|
|
|
|
|
|
_injectJs() {
|
2020-04-03 17:43:57 +00:00
|
|
|
document.body!.append(new ScriptElement()
|
2020-04-03 00:36:56 +00:00
|
|
|
..type = 'text/javascript'
|
|
|
|
..innerHtml = r"""
|
|
|
|
var Foo = {
|
2020-04-08 20:05:36 +00:00
|
|
|
get42: function(b) { return arguments.length >= 1 ? b : 42; }
|
2020-04-03 00:36:56 +00:00
|
|
|
};
|
|
|
|
""");
|
|
|
|
}
|
|
|
|
|
|
|
|
@JS()
|
|
|
|
class Foo {
|
2020-04-08 20:05:36 +00:00
|
|
|
external static num get42([num? b]);
|
2020-04-03 00:36:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
main() {
|
|
|
|
_injectJs();
|
|
|
|
|
|
|
|
test('call directly from dart', () {
|
|
|
|
expect(Foo.get42(2), 2);
|
|
|
|
expect(Foo.get42(), 42);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('call tearoff from dart with arg', () {
|
|
|
|
var f = Foo.get42;
|
2020-04-08 20:05:36 +00:00
|
|
|
expect(f(2), 2);
|
2020-04-03 00:36:56 +00:00
|
|
|
});
|
|
|
|
|
2020-04-08 20:05:36 +00:00
|
|
|
test('call tearoff from dart with no arg', () {
|
2020-04-03 00:36:56 +00:00
|
|
|
var f = Foo.get42;
|
2020-04-08 20:05:36 +00:00
|
|
|
expect(f(), 42);
|
2020-04-03 00:36:56 +00:00
|
|
|
});
|
|
|
|
}
|