microsoft / microsoft/vscode-js-debug

Custom toString causes non observable side effects when debugging

Open
#2,011 2 comments 0 reactions 1 assignee View on GitHub

@connor4312 is already working on this.

Since May 18, 2024.

under-discussion
Dominant language
TypeScript
Stars
2k
Forks
373
Avg merge
1d 9m
Merged PRs (30d)
6

Description

Describe the bug
If a object has a toString method that produces side effects, the debugger triggers those side effects in a non observable way.

Seems related to #1296

To Reproduce
Place a breakpoint in the following code:

export class Foo {
  #counter = 0;
  get() {
    console.log("Some side effects happen here");
    // ^--- add breakpoint here
    return this.#counter += 1;
  }
  toString () {
    return String(this.get());
  }
}

const foo = new Foo();

foo.get();

By the time the debugger stops at the breakpoint (before log should run), one log has already happened and the counter has increased.

VS Code Version: 1.89.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.