blob: c0ed55bce3d0ff2bc7edf261ac9133222293db16 [file] [log] [blame] [edit]
// Copyright (c) 2025, 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.
/// @assertion An annotation on a JavaScript interop declaration.
///
/// This annotation defines a given library, top-level external declaration, or
/// extension type as a JavaScript interop declaration.
///
/// @description Check that JS interop extension type may have not-external
/// members.
/// @author sgrekhov22@gmail.com
import 'dart:js_interop';
import 'dart:js_interop_unsafe';
import '../../../Utils/expect.dart';
import '../js_utils.dart';
@JS()
extension type ET1(JSObject _) implements JSObject {
external int f1();
String f2(int v) => "f2($v)";
static String f3() => "f3";
external static String f4();
}
extension type ET2(JSObject _) implements JSObject {
external int g1();
String g2(int v) => "g2($v)";
static String g3() => "g3";
external static String g4();
}
main() {
eval(r'''
class ET1 {
f1() {
return 1;
}
static f4() {
return "f4";
}
}
class ET2 {
g1() {
return 2;
}
static g4() {
return "g4";
}
}
globalThis.ET1 = ET1;
globalThis.ET2 = ET2;
globalThis.et1 = new ET1();
globalThis.et2 = new ET2();
''');
ET1 et1 = ET1(globalContext["et1"] as JSObject);
ET2 et2 = ET2(globalContext["et2"] as JSObject);
Expect.equals(1, et1.f1());
Expect.equals("f2(2)", et1.f2(2));
Expect.equals("f3", ET1.f3());
Expect.equals("f4", ET1.f4());
Expect.equals(2, et2.g1());
Expect.equals("g2(2)", et2.g2(2));
Expect.equals("g3", ET2.g3());
Expect.equals("g4", ET2.g4());
}