Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
Fix N-API JSRT bugs found by new tests
Browse files Browse the repository at this point in the history
PR-URL: #245
Reviewed-By: Kyle Farnung <Kyle.Farnung@microsoft.com>
  • Loading branch information
jasongin authored and New Name committed May 18, 2017
1 parent 297b176 commit 16922b4
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/node_api_jsrt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ napi_status napi_create_array(napi_env env, napi_value* result) {
}

napi_status napi_create_array_with_length(napi_env env,
int length,
size_t length,
napi_value* result) {
CHECK_ARG(result);
CHECK_JSRT(JsCreateArray(length, reinterpret_cast<JsValueRef*>(result)));
Expand Down Expand Up @@ -1416,7 +1416,7 @@ napi_status napi_create_external(napi_env env,
externalData,
jsrtimpl::ExternalData::Finalize,
reinterpret_cast<JsValueRef*>(result)));
CHECK_JSRT(JsPreventExtension(reinterpret_cast<JsValueRef*>(result)));
CHECK_JSRT(JsPreventExtension(*reinterpret_cast<JsValueRef*>(result)));

return napi_ok;
}
Expand Down Expand Up @@ -1488,7 +1488,7 @@ napi_status napi_delete_reference(napi_env env, napi_ref ref) {
// After this call the reference will be a strong reference because its refcount
// is >0, and the referenced object is effectively "pinned". Calling this when
// the refcount is 0 and the target is unavailable results in an error.
napi_status napi_reference_addref(napi_env env, napi_ref ref, int* result) {
napi_status napi_reference_ref(napi_env env, napi_ref ref, uint32_t* result) {
JsRef weakRef = reinterpret_cast<JsRef>(ref);

JsValueRef target;
Expand All @@ -1501,11 +1501,11 @@ napi_status napi_reference_addref(napi_env env, napi_ref ref, int* result) {

CHECK_JSRT(JsAddRef(target, nullptr));

unsigned int count;
uint32_t count;
CHECK_JSRT(JsAddRef(weakRef, &count));

if (result != nullptr) {
*result = static_cast<int>(count - 1);
*result = count - 1;
}

return napi_ok;
Expand All @@ -1515,7 +1515,7 @@ napi_status napi_reference_addref(napi_env env, napi_ref ref, int* result) {
// If the result is 0 the reference is now weak and the object may be GC'd at
// any time if there are no other references. Calling this when the refcount
// is already 0 results in an error.
napi_status napi_reference_release(napi_env env, napi_ref ref, int* result) {
napi_status napi_reference_unref(napi_env env, napi_ref ref, uint32_t* result) {
JsRef weakRef = reinterpret_cast<JsRef>(ref);

JsValueRef target;
Expand All @@ -1525,7 +1525,7 @@ napi_status napi_reference_release(napi_env env, napi_ref ref, int* result) {
return napi_set_last_error(napi_generic_failure);
}

unsigned int count;
uint32_t count;
CHECK_JSRT(JsRelease(weakRef, &count));
if (count == 0) {
// Called napi_release_reference too many times on a reference!
Expand All @@ -1535,7 +1535,7 @@ napi_status napi_reference_release(napi_env env, napi_ref ref, int* result) {
CHECK_JSRT(JsRelease(target, nullptr));

if (result != nullptr) {
*result = static_cast<int>(count - 1);
*result = count - 1;
}

return napi_ok;
Expand Down

0 comments on commit 16922b4

Please sign in to comment.