Skip to content

Explicitly restrict escapable scope to escape just one value #255

Description

@RReverser

Allowing an arbitrary number of escaped handles makes scope management more complicated in implementations as scopes are otherwise easily stored directly on a stack or in a vector-based stack implementation. In either case, it's problematic to reserve space for an unknown number of values being inserted into the outer scope.

Even V8 allows to call EscapableHandleScope::Escape only once according to docs, but this is not mentioned in N-API.

There are at least two ways to handle this:

  • Document the restriction. Still doesn't guarantee that someone won't try escaping more than one value, which would be an undefined behaviour, but better than nothing. (done)
  • Explicitly limit escaped values to just one by merging napi_escape_handle into napi_close_escapable_handle_scope as an extra parameter. Given that the most usual case for escaping handles is exactly to return a value outside of a function, it's usually anyway happening at the end, and if not, it's not a problem to store the handle in a variable and pass it to napi_close_escapable_handle_scope when it's called. This will allow no mistakes about the allowed number of escapes.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions