-
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.
src: api to get callback_info from CallBackInfo
- Exposing conversion api to fetch underlying napi_callback_info from CallBackInfo - Add test coverage for CallbackInfo SetData method PR-URL: #1253 Reviewed-By: Michael Dawson <[email protected] Reviewed-By: Chengzhong Wu <[email protected]>
- Loading branch information
Showing
6 changed files
with
44 additions
and
0 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,27 @@ | ||
#include <assert.h> | ||
#include "napi.h" | ||
using namespace Napi; | ||
|
||
struct TestCBInfoSetData { | ||
static void Test(napi_env env, napi_callback_info info) { | ||
Napi::CallbackInfo cbInfo(env, info); | ||
int valuePointer = 1220202; | ||
cbInfo.SetData(&valuePointer); | ||
|
||
int* placeHolder = static_cast<int*>(cbInfo.Data()); | ||
assert(*(placeHolder) == valuePointer); | ||
assert(placeHolder == &valuePointer); | ||
} | ||
}; | ||
|
||
void TestCallbackInfoSetData(const Napi::CallbackInfo& info) { | ||
napi_callback_info cb_info = static_cast<napi_callback_info>(info); | ||
TestCBInfoSetData::Test(info.Env(), cb_info); | ||
} | ||
|
||
Object InitCallbackInfo(Env env) { | ||
Object exports = Object::New(env); | ||
|
||
exports["testCbSetData"] = Function::New(env, TestCallbackInfoSetData); | ||
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,9 @@ | ||
'use strict'; | ||
|
||
const common = require('./common'); | ||
|
||
module.exports = common.runTest(test); | ||
|
||
async function test (binding) { | ||
binding.callbackInfo.testCbSetData(); | ||
} |