diff --git a/appveyor.yml b/appveyor.yml index 8bf753f..1e6ed81 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -5,9 +5,7 @@ environment: # Test against these versions of Node.js and io.js matrix: # node.js - - nodejs_version: "10" - - nodejs_version: "12" - - nodejs_version: "14" + - nodejs_version: "18" platform: - x86 @@ -52,4 +50,4 @@ deploy: auth_token: $(PREBUILD_GITHUB_TOKEN) on: appveyor_repo_tag: true - nodejs_version: "12" + nodejs_version: "18" diff --git a/package.json b/package.json index 56f79f5..04c8c60 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "ref-napi", "description": "Turn Buffer instances into \"pointers\"", "engines": { - "node": ">= 10.0" + "node": ">= 18.0" }, "keywords": [ "native", diff --git a/src/binding.cc b/src/binding.cc index abd43ae..b1d429f 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -105,12 +105,12 @@ class InstanceData final : public RefNapi::Instance { auto it = pointer_to_orig_buffer.find(ptr); if (it != pointer_to_orig_buffer.end()) { + it->second.finalizer_count++; if (!it->second.ab.Value().IsEmpty()) { // Already have a valid entry, nothing to do. return; } it->second.ab.Reset(buf, 0); - it->second.finalizer_count++; } else { pointer_to_orig_buffer.emplace(ptr, ArrayBufferEntry { Reference::New(buf, 0), @@ -140,8 +140,9 @@ class InstanceData final : public RefNapi::Instance { if (it != pointer_to_orig_buffer.end()) ab = it->second.ab.Value(); - if (ab.IsEmpty()) { - length = std::max(length, kMaxLength); + if (ab.IsEmpty() || (ab.ByteLength() < length)) { + length = std::min(length, kMaxLength); + length = std::max(length,1); ab = Buffer::New(env, ptr, length, [this](Env env, char* ptr) { UnregisterArrayBuffer(ptr); }).ArrayBuffer(); @@ -330,6 +331,8 @@ Value ReadPointer(const CallbackInfo& args) { int64_t size = args[2].ToNumber(); char* val = *reinterpret_cast(ptr); + if(val != nullptr && size == 0) size = 1; + return WrapPointer(env, val, size); }