Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into pr-1401
Browse files Browse the repository at this point in the history
  • Loading branch information
legendecas committed Nov 7, 2023
2 parents 0a8b94b + d605d62 commit 0db323a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/ci-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: Node.js CI Windows Platform

on: [push, pull_request]

env:
PYTHON_VERSION: '3.11'

permissions:
contents: read

Expand All @@ -18,6 +21,10 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4.0.0
with:
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: Node.js CI Unix Platform

on: [push, pull_request]

env:
PYTHON_VERSION: '3.11'

permissions:
contents: read

Expand All @@ -23,6 +26,10 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4.0.0
with:
Expand Down
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
'variables': {
'NAPI_VERSION%': "<!(node -p \"process.versions.napi\")",
'NAPI_VERSION%': "<!(node -p \"process.env.NAPI_VERSION || process.versions.napi\")",
'disable_deprecated': "<!(node -p \"process.env['npm_config_disable_deprecated']\")"
},
'conditions': [
Expand Down
30 changes: 12 additions & 18 deletions napi-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,22 @@ namespace details {
// Node.js releases. Only necessary when they are used in napi.h and napi-inl.h.
constexpr int napi_no_external_buffers_allowed = 22;

template <typename FreeType>
inline void default_finalizer(napi_env /*env*/, void* data, void* /*hint*/) {
delete static_cast<FreeType*>(data);
}

// Attach a data item to an object and delete it when the object gets
// garbage-collected.
// TODO: Replace this code with `napi_add_finalizer()` whenever it becomes
// available on all supported versions of Node.js.
template <typename FreeType>
template <typename FreeType,
napi_finalize finalizer = default_finalizer<FreeType>>
inline napi_status AttachData(napi_env env,
napi_value obj,
FreeType* data,
napi_finalize finalizer = nullptr,
void* hint = nullptr) {
napi_status status;
if (finalizer == nullptr) {
finalizer = [](napi_env /*env*/, void* data, void* /*hint*/) {
delete static_cast<FreeType*>(data);
};
}
#if (NAPI_VERSION < 5)
napi_value symbol, external;
status = napi_create_symbol(env, nullptr, &symbol);
Expand Down Expand Up @@ -1636,11 +1636,8 @@ inline void Object::AddFinalizer(Finalizer finalizeCallback, T* data) const {
new details::FinalizeData<T, Finalizer>(
{std::move(finalizeCallback), nullptr});
napi_status status =
details::AttachData(_env,
*this,
data,
details::FinalizeData<T, Finalizer>::Wrapper,
finalizeData);
details::AttachData<T, details::FinalizeData<T, Finalizer>::Wrapper>(
_env, *this, data, finalizeData);
if (status != napi_ok) {
delete finalizeData;
NAPI_THROW_IF_FAILED_VOID(_env, status);
Expand All @@ -1654,12 +1651,9 @@ inline void Object::AddFinalizer(Finalizer finalizeCallback,
details::FinalizeData<T, Finalizer, Hint>* finalizeData =
new details::FinalizeData<T, Finalizer, Hint>(
{std::move(finalizeCallback), finalizeHint});
napi_status status = details::AttachData(
_env,
*this,
data,
details::FinalizeData<T, Finalizer, Hint>::WrapperWithHint,
finalizeData);
napi_status status = details::
AttachData<T, details::FinalizeData<T, Finalizer, Hint>::WrapperWithHint>(
_env, *this, data, finalizeData);
if (status != napi_ok) {
delete finalizeData;
NAPI_THROW_IF_FAILED_VOID(_env, status);
Expand Down
2 changes: 1 addition & 1 deletion test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ async function whichBuildType () {
if (await checkBuildType(envBuildType)) {
buildType = envBuildType;
} else {
throw new Error(`The ${envBuildType} build doesn't exists.`);
throw new Error(`The ${envBuildType} build doesn't exist.`);
}
} else {
throw new Error('Invalid value for NODE_API_BUILD_CONFIG environment variable. It should be set to Release or Debug.');
Expand Down

0 comments on commit 0db323a

Please sign in to comment.