Skip to content

Proposal: Integration with Symbol.dispose #247

@RReverser

Description

@RReverser

What problem are you trying to solve?

I propose the following methods should integrate with the explicit resource management proposal that has now shipped in several browsers:

  • group
  • groupCollapsed
  • profile
  • time

These methods should return a disposable object so that instead of e.g.

console.group("my group");
console.time("my label");
...
console.timeEnd("my label");
console.groupEnd();

user could write

using group = console.group("my group");
using time = console.time("my label");
...
// groups and times are automatically ended at the end of the scope

What solutions exist today?

Explicit console.*End() methods.

How would you solve it?

The start methods should return an object that has a single Symbol.dispose property. This property is mapped to the explicit methods with the same label as the starting method.

Anything else?

There is a web-compat risk in changing the return type from current undefined to an object, as some code out there might be relying on it being undefined / false-y at the moment.

If so, we might have to either

  • Introduce an option object, so one writes console.group({ label: "my group", disposable: true }) if they want to get a disposable object.
  • Introduce new dedicated methods for the disposable counterparts of all existing methods in the list above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    addition/proposalNew features or enhancementsneeds implementer interestMoving the issue forward requires implementers to express interest

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions