Skip to content

src: set default return value of Reference Ref/Unref to 0#1004

Closed
legendecas wants to merge 1 commit into
nodejs:mainfrom
legendecas:ref-default-value
Closed

src: set default return value of Reference Ref/Unref to 0#1004
legendecas wants to merge 1 commit into
nodejs:mainfrom
legendecas:ref-default-value

Conversation

@legendecas

@legendecas legendecas commented May 23, 2021

Copy link
Copy Markdown
Member

Update the default value to reflect the most possible values when there are any errors occurred on napi_reference_unref.

See: https://github.com/nodejs/node/blob/master/src/js_native_api_v8.cc#L2535
Related: #998 (comment)

@mhdawson

Copy link
Copy Markdown
Member

I'm not sure returning 1 instead of 0 when an error occurs really helps. What would make more sense to me is -1 to indicate an error. If we are going to change the return value, which would affect code that is not properly checking for an exception. I think -1 would be a better value going forward.

From the original post where an issue was reported:

I agree that calling count = this->Unref(); in the destructor does not make sense since if you count on that decrementing the ref count it will never happen except during env teardown and in that case it is not needed anyway.

So the fix for the original issue reported I think is to just remove the Unref() in the ~MyObject() destructor.

@legendecas

Copy link
Copy Markdown
Member Author

The reference count type is uint32_t so that we could not return -1 in the case of error.

@mhdawson

mhdawson commented Jun 4, 2021

Copy link
Copy Markdown
Member

@legendecas right did not see it being uint32_t :(

@mhdawson mhdawson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

mhdawson pushed a commit that referenced this pull request Jun 18, 2021
PR-URL: #1004
Reviewed-By: Michael Dawson <midawson@redhat.com>
@mhdawson

Copy link
Copy Markdown
Member

Landed as 37a9b8e

@mhdawson mhdawson closed this Jun 18, 2021
@legendecas legendecas deleted the ref-default-value branch July 15, 2021 16:49
deepakrkris pushed a commit to deepakrkris/node-addon-api that referenced this pull request Sep 23, 2021
PR-URL: nodejs#1004
Reviewed-By: Michael Dawson <midawson@redhat.com>
deepakrkris pushed a commit to deepakrkris/node-addon-api that referenced this pull request Oct 15, 2021
PR-URL: nodejs#1004
Reviewed-By: Michael Dawson <midawson@redhat.com>
kevindavies8 added a commit to kevindavies8/node-addon-api-Develop that referenced this pull request Aug 24, 2022
PR-URL: nodejs/node-addon-api#1004
Reviewed-By: Michael Dawson <midawson@redhat.com>
Marlyfleitas added a commit to Marlyfleitas/node-api-addon-Development that referenced this pull request Aug 26, 2022
PR-URL: nodejs/node-addon-api#1004
Reviewed-By: Michael Dawson <midawson@redhat.com>
wroy7860 added a commit to wroy7860/addon-api-benchmark-node that referenced this pull request Sep 19, 2022
PR-URL: nodejs/node-addon-api#1004
Reviewed-By: Michael Dawson <midawson@redhat.com>
johnfrench3 pushed a commit to johnfrench3/node-addon-api-git that referenced this pull request Aug 11, 2023
PR-URL: nodejs/node-addon-api#1004
Reviewed-By: Michael Dawson <midawson@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants