Skip to content

Methods of wrapper classes should be marked const #870

Closed

Description

@seishun

For example, Object::Set and ThreadSafeFunction::Release. They don't modify the object itself but only call functions on the N-API object they wrap. This is similar to how the constness of a pointer is orthogonal to the constness of the object it points to.

These methods being non-const means that if I have to call them in a lambda, I have to either capture the object by reference (unidiomatic and not always possible, e.g. with TheadSafeFunction) or mark the lambda as mutable (unusual and misleading since the lambda itself doesn't mutate).

Activity

  1. mhdawson commented on Jan 4, 2021

    @mhdawson
    Member

    @seishun is adding const going to break any existing code (I'm expecting not) and any interest in submitting a PR ?

  2. seishun commented on Jan 5, 2021

    @seishun
    ContributorAuthor

    is adding const going to break any existing code (I'm expecting not)

    Object::operator[] returns a different type depending on constness (Value or PropertyLValue), but PropertyLValue is implicitly convertible to Value, so I guess it's fine? 🤔

    any interest in submitting a PR

    Sure, working on it.

  3. github-actions commented on Apr 6, 2021

    @github-actions
    Contributor

    This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions