dart-sdk/tests/dartdevc/hot_restart_expando_test.dart
Sigmund Cherem 3a0c27b74c [ddc] Add a regression test for issue #45874
Expandos collide after a hot restart. This currently fails because
the DDC implementation uses a static field (_keyCounter) to compute a
unique name for each expando. After a hot-restart the counter gets reset
and keys get reused accidentally.

A hacky fix would be to ensure this field is not reset after restarts,
but a more robust fix would be to use a weak map implementation like
dart2js does.

Change-Id: I991874aabf836be66cbd44de07dd38e681415ae7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/199221
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2021-05-11 22:14:28 +00:00

31 lines
627 B
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:_runtime' as dart;
import 'package:expect/expect.dart';
import 'package:js/js.dart';
final e = Expando<int>();
@JS()
external void eval(String s);
@JS()
external Object get singleton;
void main() {
eval('''
if (!self.singleton) {
self.singleton = {};
}
''');
var o = singleton;
Expect.equals(null, e[o]);
e[o] = 1;
dart.hotRestart();
Expect.equals(null, e[o]);
}