Skip to content

Commit

Permalink
Tests failing for Node > 14
Browse files Browse the repository at this point in the history
`napi_create_reference` returns `napi_invalid_arg` instead of `napi_object_expected`.
Extended logic for this case.

Also updated `node-addon-api` to `4.2.0`
  • Loading branch information
takameyer committed Dec 15, 2021
1 parent 643fff6 commit 8da1149
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ x.x.x Release notes (yyyy-MM-dd)
* If the option `user` in a sync configuration was not a `Realm.User` object could lead to a crash. ([#1348](https://github.com/realm/realm-js/issues/1348), since v10.0.0)
* `@sum` and `@avg` queries on Dictionaries of floats or doubles used too much precision for intermediates, resulting in incorrect rounding. (since v10.3.0-rc.1)
* Queries of the form `link.collection.@sum = 0` where `link` is `null` matched when `collection` was a List or Set, but not a Dictionary ([realm/realm-core#5080](https://github.com/realm/realm-core/pull/5080), since v10.5.0)
* Fix Realm for versions of Node greater than 14.

### Compatibility
* MongoDB Realm Cloud.
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"fs-extra": "^4.0.3",
"https-proxy-agent": "^2.2.4",
"ini": "^1.3.7",
"node-addon-api": "^3.1.0",
"node-addon-api": "4.2.0",
"node-fetch": "^2.6.1",
"node-machine-id": "^1.1.10",
"prebuild-install": "^6.1.1",
Expand Down Expand Up @@ -160,4 +160,4 @@
4
]
}
}
}
5 changes: 4 additions & 1 deletion src/node/node_protected.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#pragma once

#include "js_native_api_types.h"
#include "napi.h"
#include "node_types.hpp"

namespace realm {
Expand All @@ -44,12 +46,13 @@ class Protected {
, m_isValue(false)
{
napi_status status = napi_create_reference(env, value, 1, &m_ref);
if (status == napi_object_expected) {
if (status == napi_object_expected || status == napi_invalid_arg) {
m_isValue = true;
Napi::Object object = Napi::Object::New(m_env);
object.Set("value", value);
status = napi_create_reference(env, object, 1, &m_ref);
}
env.Global().Get(Napi::String::New(env, std::string("inspect"))).As<Napi::Function>().Call({value});

if (status != napi_ok) {
throw std::runtime_error(util::format("Can't create protected reference: napi_status %1", status));
Expand Down

0 comments on commit 8da1149

Please sign in to comment.