Skip to content

Commit 5449c78

Browse files
authored
feat!: upgrade NAPI bindings to latest version (#34)
* chore: upgrade packages to latest * chore: first attempt to GHA * chore: change npm run test test to pass --expose-gc properly * chore: Use Unref instead of Reset to avoid SEGFAULT Since Node.js 20, the test `should invoke *all* callbacks from different weak references` fails because of a SEGFAULT. After debugging, it seems that the issue is that, after the first Immediate Callback and the corresponding Reset call of ObjectInfo, the destructor to this is called, invalidating the reference, and SetImmediate accesses to invalid memory. By using Unref, we ensure that `this` is only destructed after all callbacks are actually called. This matches the expectations of the constructor, where we trigger a new Ref(). * chore: Upgrade AppVeyor dependencies and node versions
1 parent fdafbde commit 5449c78

File tree

4 files changed

+57
-12
lines changed

4 files changed

+57
-12
lines changed

.github/workflows/ci.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: CI
2+
on: [push, pull_request]
3+
4+
jobs:
5+
check:
6+
strategy:
7+
fail-fast: false
8+
matrix:
9+
node-version: ['18.x', '20.x', '22.x', '24.x']
10+
runner: [ubuntu-22.04, ubuntu-latest, macos-latest, windows-latest]
11+
12+
runs-on: ${{ matrix.runner }}
13+
14+
steps:
15+
- uses: actions/checkout@v5
16+
- name: Use Node.js ${{ matrix['node-version'] }}
17+
uses: actions/setup-node@v6
18+
with:
19+
node-version: ${{ matrix['node-version'] }}
20+
21+
- name: Install Clang
22+
if: ${{ startsWith(matrix.runner, 'ubuntu-') }}
23+
uses: egor-tensin/[email protected]
24+
25+
- name: Install dependencies
26+
run: npm install --build-from-source
27+
28+
- name: Run tests
29+
run: npm test
30+
31+
- name: Run prebuild x64
32+
if: ${{ startsWith(matrix.runner, 'ubuntu-') }}
33+
shell: bash
34+
run: |
35+
npm run prebuild --v8_enable_pointer_compression=false \
36+
--v8_enable_31bit_smis_on_64bit_arch=false
37+
38+
- name: Run prebuild i32
39+
if: ${{ startsWith(matrix.runner, 'ubuntu-') }}
40+
shell: bash
41+
run: |
42+
ARCH=ia32 npm run prebuild --v8_enable_pointer_compression=false \
43+
--v8_enable_31bit_smis_on_64bit_arch=false

appveyor.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ environment:
55
# Test against these versions of Node.js and io.js
66
matrix:
77
# node.js
8-
- nodejs_version: "10"
9-
- nodejs_version: "12"
8+
- nodejs_version: "18"
9+
- nodejs_version: "20"
10+
- nodejs_version: "22"
11+
- nodejs_version: "24"
1012

1113
platform:
1214
- x86
@@ -30,7 +32,7 @@ test_script:
3032
- npm test
3133

3234
after_test:
33-
- ps: If ($env:nodejs_version -eq "12") { npm run prebuild --v8_enable_pointer_compression=false --v8_enable_31bit_smis_on_64bit_arch=false }
35+
- ps: npm run prebuild --v8_enable_pointer_compression=false --v8_enable_31bit_smis_on_64bit_arch=false
3436

3537
# Don't actually build.
3638
build: off
@@ -51,4 +53,4 @@ deploy:
5153
auth_token: $(PREBUILD_GITHUB_TOKEN)
5254
on:
5355
appveyor_repo_tag: true
54-
nodejs_version: "12"
56+
nodejs_version: "24"

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,20 @@
2424
},
2525
"main": "lib/weak.js",
2626
"scripts": {
27-
"test": "nyc mocha --expose-gc",
27+
"test": "nyc mocha --node-option=expose-gc",
2828
"install": "node-gyp-build",
2929
"prebuild": "prebuildify --napi --tag-armv --tag-uv",
3030
"prepack": "prebuildify-ci download && ([ $(ls prebuilds | wc -l) = '5' ] || (echo 'Some prebuilds are missing'; exit 1))"
3131
},
3232
"dependencies": {
33-
"node-addon-api": "^3.0.0",
34-
"node-gyp-build": "^4.2.1",
35-
"setimmediate-napi": "^1.0.3"
33+
"node-addon-api": "^8.5.0",
34+
"node-gyp-build": "^4.8.4",
35+
"setimmediate-napi": "^1.0.6"
3636
},
3737
"devDependencies": {
38-
"mocha": "^7.1.1",
39-
"nyc": "^15.0.0",
40-
"prebuildify": "^3.0.4",
38+
"mocha": "^11.1.0",
39+
"nyc": "^17.1.0",
40+
"prebuildify": "^6.0.1",
4141
"prebuildify-ci": "^1.0.5"
4242
}
4343
}

src/weakref.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ObjectInfo : public ObjectWrap<ObjectInfo> {
2121
SetImmediate(Env(), [this]() {
2222
callback_.MakeCallback(Value(), {});
2323
callback_.Reset();
24-
Reset();
24+
Unref();
2525
});
2626
}
2727

0 commit comments

Comments
 (0)