-
-
Notifications
You must be signed in to change notification settings - Fork 35
Closed
Description
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
intonapi_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 tonapi_close_escapable_handle_scope
when it's called. This will allow no mistakes about the allowed number of escapes.
Metadata
Metadata
Assignees
Labels
No labels