From c546f7cc8ac440a08240246ac2f55771c220a497 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Fri, 31 Mar 2023 12:11:50 -0700 Subject: [PATCH] Ensure Decoration.isDisposed can be true Fixes #4410 --- src/common/services/DecorationService.test.ts | 30 +++++++++++++++++++ src/common/services/DecorationService.ts | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/common/services/DecorationService.test.ts diff --git a/src/common/services/DecorationService.test.ts b/src/common/services/DecorationService.test.ts new file mode 100644 index 0000000000..a2cb56d266 --- /dev/null +++ b/src/common/services/DecorationService.test.ts @@ -0,0 +1,30 @@ +/** + * Copyright (c) 2019 The xterm.js authors. All rights reserved. + * @license MIT + */ + +import { assert } from 'chai'; +import { DecorationService } from './DecorationService'; +import { EventEmitter } from 'common/EventEmitter'; +import { IMarker } from 'common/Types'; +import { Disposable } from 'common/Lifecycle'; + +const fakeMarker: IMarker = Object.freeze(new class extends Disposable { + public readonly id = 1; + public readonly line = 1; + public readonly isDisposed = false; + public readonly onDispose = new EventEmitter().event; +}()); + +describe('DecorationService', () => { + it('should set isDisposed to true after dispose', () => { + const service = new DecorationService(); + const decoration = service.registerDecoration({ + marker: fakeMarker + }); + assert.ok(decoration); + assert.isFalse(decoration!.isDisposed); + decoration!.dispose(); + assert.isTrue(decoration!.isDisposed); + }); +}); diff --git a/src/common/services/DecorationService.ts b/src/common/services/DecorationService.ts index 881b3d0784..1ccc712c41 100644 --- a/src/common/services/DecorationService.ts +++ b/src/common/services/DecorationService.ts @@ -104,7 +104,7 @@ export class DecorationService extends Disposable implements IDecorationService class Decoration extends Disposable implements IInternalDecoration { public readonly marker: IMarker; public element: HTMLElement | undefined; - public isDisposed: boolean = false; + public get isDisposed(): boolean { return this._isDisposed; } public readonly onRenderEmitter = this.register(new EventEmitter()); public readonly onRender = this.onRenderEmitter.event;