-
Notifications
You must be signed in to change notification settings - Fork 461
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for requiring basic finalizers (#1568)
* feat: add support for requiring basic finalizers * Address review comments - Use passive voice in existing and new docs - Revert unnecessary change
- Loading branch information
Showing
10 changed files
with
143 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict'; | ||
|
||
const { promisify } = require('util'); | ||
const exec = promisify(require('child_process').exec); | ||
const { copy, remove } = require('fs-extra'); | ||
const path = require('path'); | ||
const assert = require('assert'); | ||
|
||
async function test () { | ||
const addon = 'require-basic-finalizers'; | ||
const ADDON_FOLDER = path.join(__dirname, 'addons', addon); | ||
|
||
await remove(ADDON_FOLDER); | ||
await copy(path.join(__dirname, 'tpl'), ADDON_FOLDER); | ||
|
||
console.log(' >Building addon'); | ||
|
||
// Fail when NODE_ADDON_API_REQUIRE_BASIC_FINALIZERS is enabled | ||
await assert.rejects(exec('npm --require-basic-finalizers install', { | ||
cwd: ADDON_FOLDER | ||
}), 'Addon unexpectedly compiled successfully'); | ||
|
||
// Succeed when NODE_ADDON_API_REQUIRE_BASIC_FINALIZERS is not enabled | ||
return assert.doesNotReject(exec('npm install', { | ||
cwd: ADDON_FOLDER | ||
})); | ||
} | ||
|
||
module.exports = (function () { | ||
// This test will only run under an experimental version test. | ||
const isExperimental = Number(process.env.NAPI_VERSION) === 2147483647; | ||
|
||
if (isExperimental) { | ||
return test(); | ||
} else { | ||
console.log(' >Skipped (non-experimental test run)'); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <napi.h> | ||
|
||
Napi::Object Init(Napi::Env env, Napi::Object exports) { | ||
exports.Set( | ||
"external", | ||
Napi::External<int>::New( | ||
env, new int(1), [](Napi::Env /*env*/, int* data) { delete data; })); | ||
|
||
return exports; | ||
} | ||
|
||
NODE_API_MODULE(NODE_GYP_MODULE_NAME, Init) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
'target_defaults': { | ||
'include_dirs': [ | ||
"<!(node -p \"require('node-addon-api').include_dir\")" | ||
], | ||
'variables': { | ||
'NAPI_VERSION%': "<!(node -p \"process.env.NAPI_VERSION || process.versions.napi\")", | ||
'require_basic_finalizers': "<!(node -p \"process.env['npm_config_require_basic_finalizers']\")", | ||
}, | ||
'conditions': [ | ||
['NAPI_VERSION!=""', { 'defines': ['NAPI_VERSION=<@(NAPI_VERSION)'] } ], | ||
['NAPI_VERSION==2147483647', { 'defines': ['NAPI_EXPERIMENTAL'] } ], | ||
['require_basic_finalizers=="true"', { | ||
'defines': ['NODE_ADDON_API_REQUIRE_BASIC_FINALIZERS'], | ||
}], | ||
['OS=="mac"', { | ||
'cflags+': ['-fvisibility=hidden'], | ||
'xcode_settings': { | ||
'OTHER_CFLAGS': ['-fvisibility=hidden'] | ||
} | ||
}] | ||
], | ||
'sources': [ | ||
'addon.cc', | ||
], | ||
}, | ||
'targets': [ | ||
{ | ||
'target_name': 'addon', | ||
'defines': [ | ||
'NAPI_CPP_EXCEPTIONS' | ||
], | ||
'cflags!': [ '-fno-exceptions' ], | ||
'cflags_cc!': [ '-fno-exceptions' ], | ||
'msvs_settings': { | ||
'VCCLCompilerTool': { | ||
'ExceptionHandling': 1, | ||
'EnablePREfast': 'true', | ||
}, | ||
}, | ||
'xcode_settings': { | ||
'CLANG_CXX_LIBRARY': 'libc++', | ||
'MACOSX_DEPLOYMENT_TARGET': '10.7', | ||
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES', | ||
}, | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
module.exports = require('bindings')('addon'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "addon", | ||
"version": "0.0.0", | ||
"description": "Node.js addon", | ||
"private": true, | ||
"scripts": {}, | ||
"dependencies": { | ||
"node-addon-api": "file:../../../../" | ||
}, | ||
"gypfile": true | ||
} |