From 3a0c27b74cd77b3af1bf4606e1ba45f8589e6563 Mon Sep 17 00:00:00 2001 From: Sigmund Cherem Date: Tue, 11 May 2021 22:14:28 +0000 Subject: [PATCH] [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 --- tests/dartdevc/hot_restart_expando_test.dart | 30 +++++++++++++++++++ .../dartdevc_2/hot_restart_expando_test.dart | 30 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 tests/dartdevc/hot_restart_expando_test.dart create mode 100644 tests/dartdevc_2/hot_restart_expando_test.dart diff --git a/tests/dartdevc/hot_restart_expando_test.dart b/tests/dartdevc/hot_restart_expando_test.dart new file mode 100644 index 00000000000..4802a52423f --- /dev/null +++ b/tests/dartdevc/hot_restart_expando_test.dart @@ -0,0 +1,30 @@ +// 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(); + +@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]); +} diff --git a/tests/dartdevc_2/hot_restart_expando_test.dart b/tests/dartdevc_2/hot_restart_expando_test.dart new file mode 100644 index 00000000000..4802a52423f --- /dev/null +++ b/tests/dartdevc_2/hot_restart_expando_test.dart @@ -0,0 +1,30 @@ +// 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(); + +@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]); +}