[tests, dart2js] Fix test using minified type names

1. Add `Object` and `Map` to the very short list of names that are
unminified in the app.

2. Tweak test to avoid testing minified name.

Change-Id: Ide0cedc2950b5392eb6963403a48c0f89cd1b50a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332368
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
This commit is contained in:
Stephen Adams 2023-10-27 01:36:28 +00:00 committed by Commit Queue
parent 8ee403e86c
commit cb52932c72
8 changed files with 20 additions and 21 deletions

View file

@ -1799,25 +1799,27 @@ class FragmentEmitter {
/// This global maps minified names for selected classes (some important
/// core classes, and some native classes) to their unminified names.
js.Property emitMangledGlobalNames() {
List<js.Property> names = [];
CommonElements commonElements = _closedWorld.commonElements;
// We want to keep the original names for the most common core classes when
// calling toString on them.
List<ClassEntity> nativeClassesNeedingUnmangledName = [
List<ClassEntity> commonClassesNeedingUnmangledName = [
commonElements.intClass,
commonElements.doubleClass,
commonElements.numClass,
commonElements.stringClass,
commonElements.boolClass,
commonElements.nullClass,
commonElements.listClass
commonElements.listClass,
commonElements.objectClass,
commonElements.mapClass,
];
// TODO(floitsch): this should probably be on a per-fragment basis.
nativeClassesNeedingUnmangledName.forEach((element) {
names.add(js.Property(
js.quoteName(_namer.className(element)), js.string(element.name)));
});
List<js.Property> names = [
for (final element in commonClassesNeedingUnmangledName)
js.Property(
js.quoteName(_namer.className(element)), js.string(element.name))
];
return js.Property(
js.string(MANGLED_GLOBAL_NAMES), js.ObjectInitializer(names));

View file

@ -16,9 +16,10 @@ main() {
check(fn('int', ''), () => 1); // closure.
var s = new Xyzzy().runtimeType.toString();
if (s.length <= 3) return; // dart2js --minify has minified names.
Expect.equals('Xyzzy', s, 'runtime type of plain class prints as class name');
if (!s.startsWith('minified')) {
Expect.equals(
'Xyzzy', s, 'runtime type of plain class prints as class name');
}
check(fn('void', 'String, dynamic'), check);

View file

@ -17,8 +17,7 @@ main() {
var typeLiteralToString = "${b}";
Expect.equals(runtimeTypeToString, typeLiteralToString);
if ('$Object' == 'Object') {
// `true` if non-minified.
if (!runtimeTypeToString.contains('minified:')) {
Expect.equals("Foo<num>", runtimeTypeToString);
Expect.equals("Foo<num>", typeLiteralToString);
}

View file

@ -16,8 +16,7 @@ main() {
local2(int i) => i;
var toString = '${local1.runtimeType}';
if ('$Object' == 'Object') {
// `true` if non-minified.
if (!toString.contains('minified:')) {
Expect.equals("Closure0Args", toString);
}
print(toString);

View file

@ -16,8 +16,7 @@ main() {
local2<T>(t) => t;
var toString = '${local1.runtimeType}';
if ('$Object' == 'Object') {
// `true` if non-minified.
if (!toString.contains('minified:')) {
Expect.equals("Closure", toString);
}
print(toString);

View file

@ -17,7 +17,7 @@ test<Q>() {
local2(int i) => i;
var toString = '${local1.runtimeType}';
if ('$Object' == 'Object') {
if (!toString.contains('minified:')) {
// `true` if non-minified.
Expect.equals("Closure", toString);
}

View file

@ -10,8 +10,7 @@ main() {
T id<T>(T t) => t;
int Function(int) x = id;
var toString = "${x.runtimeType}";
if ('$Object' == 'Object') {
// `true` if non-minified.
if (!toString.contains('minified:')) {
// The signature of `id` is not otherwise needed so the instantiation
// wrapper doesn't have a function type.
// The type parameter is present since it is required because `==`

View file

@ -37,7 +37,7 @@ foo<Y>(int x) {
void main() {
var name = '${Wrap}';
if ('$Object' != 'Object') return; // minified
if (name.contains('minified:')) return; // minified
Expect.equals(
'Wrap<(int) => ((int) => void) => (int) => void>',