blob: 905558410b42240d37c285a0d197d98680c19221 [file] [log] [blame]
// Copyright (c) 2022, 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 The finalizer can be attached multiple times to the same object
/// with different, or the same, finalization token.
/// @description Checks that finalizer can be attached to the same object with
/// the same finalization token several times.
/// @author
import '../../gc_utils_lib.dart';
import '../../../../Utils/expect.dart';
class Nonce {
final int value;
final finalizerTokens = <String>{};
final Finalizer finalizer = Finalizer((token) {
void attachToFinalizer(Nonce token1, Nonce token2, Nonce token3) {
Object value = Object();
finalizer.attach(value, "Finalization token", detach: token1);
finalizer.attach(value, "Finalization token", detach: token2);
finalizer.attach(value, "Finalization token", detach: token3);
main() async {
attachToFinalizer(Nonce(1), Nonce(2), Nonce(3));
await triggerGcWithDelay();
Expect.setEquals({"Finalization token"}, finalizerTokens);