Repository: mozilla/pdf.js
File: src/display/editor/draw.js (JavaScript)

Code before:
  static startDrawing(parent, uiManager, _isLTR, event) {
    // The _currentPointerType is set when the user starts an empty drawing
    // session. If, in the same drawing session, the user starts using a
    // different type of pointer (e.g. a pen and then a finger), we just return.
    //
    // The _currentPointerId  and _currentPointerIds are used to keep track of
    // the pointers with a same type (e.g. two fingers). If the user starts to
    // draw with a finger and then uses a second finger, we just stop the
    // current drawing and let the user zoom the document.

    const { target, offsetX: x, offsetY: y, pointerId, pointerType } = event;
    if (this._currentPointerType && this._currentPointerType !== pointerType) {
      return;
    }

    const {
      viewport: { rotation },
    } = parent;
    const { width: parentWidth, height: parentHeight } =
      target.getBoundingClientRect();

    const ac = (this._currentDrawingAC = new AbortController());
    const signal = parent.combinedSignal(ac);

    this._currentPointerId ||= pointerId;
    this._currentPointerType ||= pointerType;

    window.addEventListener(
      "pointerup",
      e => {
        if (this._currentPointerId === e.pointerId) {
          this._endDraw(e);
        } else {
          this._currentPointerIds?.delete(e.pointerId);
        }
      },
      { signal }
    );
    window.addEventListener(
      "pointercancel",
      e => {
        if (this._currentPointerId === e.pointerId) {
          this._currentParent.endDrawingSession();
        } else {
          this._currentPointerIds?.delete(e.pointerId);
        }
      },
      { signal }
    );
    window.addEventListener(
      "pointerdown",

Review comment (suggestion):
Given that `pointerId` seems to be specified as [a number](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/pointerId#value), it might be zero?
Hence it seems overall safer just change these as follows, to prevent them being modified accidentally.
```suggestion
    this._currentPointerId ??= pointerId;
    this._currentPointerType ??= pointerType;
```

Code after:
  static startDrawing(parent, uiManager, _isLTR, event) {
    // The _currentPointerType is set when the user starts an empty drawing
    // session. If, in the same drawing session, the user starts using a
    // different type of pointer (e.g. a pen and then a finger), we just return.
    //
    // The _currentPointerId  and _currentPointerIds are used to keep track of
    // the pointers with a same type (e.g. two fingers). If the user starts to
    // draw with a finger and then uses a second finger, we just stop the
    // current drawing and let the user zoom the document.

    const { target, offsetX: x, offsetY: y, pointerId, pointerType } = event;
    if (
      DrawingEditor.#currentPointerType &&
      DrawingEditor.#currentPointerType !== pointerType
    ) {
      return;
    }

    const {
      viewport: { rotation },
    } = parent;
    const { width: parentWidth, height: parentHeight } =
      target.getBoundingClientRect();

    const ac = (DrawingEditor.#currentDrawingAC = new AbortController());
    const signal = parent.combinedSignal(ac);

    DrawingEditor.#currentPointerId ||= pointerId;
    DrawingEditor.#currentPointerType ??= pointerType;

    window.addEventListener(
      "pointerup",
      e => {
        if (DrawingEditor.#currentPointerId === e.pointerId) {
          this._endDraw(e);
        } else {
          DrawingEditor.#currentPointerIds?.delete(e.pointerId);
        }
      },
      { signal }
    );
    window.addEventListener(
      "pointercancel",
      e => {
        if (DrawingEditor.#currentPointerId === e.pointerId) {
          this._currentParent.endDrawingSession();
        } else {
          DrawingEditor.#currentPointerIds?.delete(e.pointerId);
        }
      },
      { signal }