mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 09:01:42 +00:00
62f84880ef
Closes #40520 Closes #40948 Closes #40425 Change-Id: I0aa3cfa51b410c90dd0bea963846eeb6b2e73efb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/140540 Commit-Queue: Johnni Winther <johnniwinther@google.com> Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
58 lines
1.8 KiB
Dart
58 lines
1.8 KiB
Dart
// Copyright (c) 2019, 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.
|
|
|
|
import 'dart:collection';
|
|
import 'package:expect/expect.dart';
|
|
|
|
main() {
|
|
// Regression test for https://github.com/dart-lang/sdk/issues/36052.
|
|
// JS compilers shouldn't produce `undefined` when a Map/Set key is not found.
|
|
testMap({});
|
|
testMap(Map.identity());
|
|
testMap(LinkedHashMap(
|
|
equals: (x, y) => x == y,
|
|
hashCode: (x) => x.hashCode,
|
|
isValidKey: (_) => true));
|
|
|
|
testSet(Set());
|
|
testSet(Set.identity());
|
|
testSet(LinkedHashSet(
|
|
equals: (x, y) => x == y,
|
|
hashCode: (x) => x.hashCode,
|
|
isValidKey: (_) => true));
|
|
}
|
|
|
|
testMap(Map<Object, Object?> map) {
|
|
var t = map.runtimeType.toString();
|
|
var s = ' (length ${map.length})';
|
|
checkUndefined('$t.[]$s', map['hi']);
|
|
checkUndefined('$t.putIfAbsent$s', map.putIfAbsent('hi', () {}));
|
|
checkUndefined('$t.remove$s', map.remove('hi'));
|
|
if (map.isEmpty) {
|
|
map['hello'] = 'there';
|
|
testMap(map);
|
|
}
|
|
}
|
|
|
|
testSet(Set<Object> set) {
|
|
var t = set.runtimeType.toString();
|
|
var s = ' (length ${set.length})';
|
|
checkUndefined('$t.lookup$s', set.lookup('hi'));
|
|
if (set.isEmpty) {
|
|
set.add('hello');
|
|
testSet(set);
|
|
}
|
|
}
|
|
|
|
/// Fails if [x] incorrectly uses the default argument instead of being `null`
|
|
/// (i.e. because `x` is undefined).
|
|
checkUndefined(String method, [Object? x = 'error']) {
|
|
// TODO(jmesserly): this check is specific to implementation details of DDC's
|
|
// current calling conventions. These conventions may change.
|
|
// Ideally we'd have an `undefined` constant in "package:js" and use that
|
|
// here instead.
|
|
Expect.isNull(x,
|
|
'error in $method: result treated as missing argument (JS undefined?)');
|
|
}
|