Skip to content

Consider dynamically adding an internal slot to store the stack trace #12

@dminor

Description

@dminor

From @mhofman's comment #10 (comment), instead of the closure based approach, we could dynamically install a new internal slot on the object when Error.captureStackTrace is called.

The specification says that "Unless explicitly specified otherwise, internal slots are allocated as part of the process of creating an object, Symbol, or Private Name and may not be dynamically added." As far as I can tell, this would be the first time in the specification that we would be dynamically adding an internal slot. We could of course just add a normal internal slot to the definition of every object, but that seems like an ugly solution when most objects won't be used with Error.captureStackTrace.

The other part of this approach is that the getter and setter installed would be required to be identical across all calls to Error.captureStackTrace. This comment #10 (comment) suggests making them instrinsics that would be optional.

There was some discussion of the internal slot approach at the July 2025 plenary (https://github.com/tc39/notes/blob/main/meetings/2025-07/july-29.md).

@mhofman, hopefully this captures your suggestions, please let me know if I've missed anything.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions