File: callbackInfo.cc

package info (click to toggle)
node-addon-api 8.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,248 kB
  • sloc: cpp: 15,431; javascript: 5,631; ansic: 157; makefile: 7
file content (27 lines) | stat: -rw-r--r-- 760 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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;
}