-
Notifications
You must be signed in to change notification settings - Fork 459
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: allow references to be copyable in APIs
allow non-copyable callbacks be finalizer parameters Fixes: #301 PR-URL: #915 Reviewed-By: Michael Dawson <midawson@redhat.com>
- Loading branch information
1 parent
929709d
commit 74ab50c
Showing
5 changed files
with
69 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "napi.h" | ||
|
||
using namespace Napi; | ||
|
||
Value createExternal(const CallbackInfo& info) { | ||
FunctionReference ref = Reference<Function>::New(info[0].As<Function>(), 1); | ||
auto ret = External<char>::New( | ||
info.Env(), | ||
nullptr, | ||
[ref = std::move(ref)](Napi::Env /*env*/, char* /*data*/) { | ||
ref.Call({}); | ||
}); | ||
|
||
return ret; | ||
} | ||
|
||
Object InitMovableCallbacks(Env env) { | ||
Object exports = Object::New(env); | ||
|
||
exports["createExternal"] = Function::New(env, createExternal); | ||
|
||
return exports; | ||
} |
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,27 @@ | ||
'use strict'; | ||
const buildType = process.config.target_defaults.default_configuration; | ||
const common = require('./common'); | ||
const testUtil = require('./testUtil'); | ||
|
||
Promise.all([ | ||
test(require(`./build/${buildType}/binding.node`).movable_callbacks), | ||
test(require(`./build/${buildType}/binding_noexcept.node`).movable_callbacks), | ||
]).catch(e => { | ||
console.error(e); | ||
process.exitCode = 1; | ||
}); | ||
|
||
async function test(binding) { | ||
await testUtil.runGCTests([ | ||
'External', | ||
() => { | ||
const fn = common.mustCall(() => { | ||
// noop | ||
}, 1); | ||
const external = binding.createExternal(fn); | ||
}, | ||
() => { | ||
// noop, wait for gc | ||
} | ||
]); | ||
} |