<commit_before>/**
 * Copyright (c) 2018 The xterm.js authors. All rights reserved.
 * @license MIT
 */

import { EventEmitter } from 'common/EventEmitter';
import { disposeArray } from 'common/Lifecycle';
import { IDisposable, IMarker } from 'common/Types';

export class Marker implements IMarker {
  private static _nextId = 1;

  public isDisposed: boolean = false;
  private _disposables: IDisposable[] = [];

  private _id: number = Marker._nextId++;
  public get id(): number { return this._id; }


  private readonly _onDispose = new EventEmitter<void>();
  public readonly onDispose = this._onDispose.event;

  constructor(
    public line: number
  ) {
  }

  public dispose(): void {
    if (this.isDisposed) {
      return;
    }
    this.isDisposed = true;
    this.line = -1;
    // Emit before super.dispose such that dispose listeners get a change to react
    this._onDispose.fire();
    disposeArray(this._disposables);
  }

  public register(disposable: IDisposable): void {
    this._disposables.push(disposable);
    this._disposables.length = 0;<commit_msg>Fix Marker.dispose<commit_after>/**
 * Copyright (c) 2018 The xterm.js authors. All rights reserved.
 * @license MIT
 */

import { EventEmitter } from 'common/EventEmitter';
import { disposeArray } from 'common/Lifecycle';
import { IDisposable, IMarker } from 'common/Types';

export class Marker implements IMarker {
  private static _nextId = 1;

  public isDisposed: boolean = false;
  private _disposables: IDisposable[] = [];

  private _id: number = Marker._nextId++;
  public get id(): number { return this._id; }

  private readonly _onDispose = this.register(new EventEmitter<void>());
  public readonly onDispose = this._onDispose.event;

  constructor(
    public line: number
  ) {
  }

  public dispose(): void {
    if (this.isDisposed) {
      return;
    }
    this.isDisposed = true;
    this.line = -1;
    // Emit before super.dispose such that dispose listeners get a change to react
    this._onDispose.fire();
    disposeArray(this._disposables);
    this._disposables.length = 0;
  }

  public register<T extends IDisposable>(disposable: T): T {
    this._disposables.push(disposable);
    return disposable;
{'fraction_non_alphanumeric': 0.11176470588235295, 'fraction_numerical': 0.006334841628959276, 'mean_word_length': 3.5966735966735968, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3487768', 'n_tokens_mistral': 712, 'n_tokens_neox': 674, 'n_words': 194}