File: boolean.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 (40 lines) | stat: -rw-r--r-- 1,293 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
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "napi.h"

using namespace Napi;

Value CreateBoolean(const CallbackInfo& info) {
  return Boolean::New(info.Env(), info[0].As<Boolean>().Value());
}

Value CreateEmptyBoolean(const CallbackInfo& info) {
  Boolean* boolean = new Boolean();
  return Boolean::New(info.Env(), boolean->IsEmpty());
}

Value CreateBooleanFromExistingValue(const CallbackInfo& info) {
  Boolean boolean(info.Env(), info[0].As<Boolean>());
  return Boolean::New(info.Env(), boolean.Value());
}

Value CreateBooleanFromPrimitive(const CallbackInfo& info) {
  bool boolean = info[0].As<Boolean>();
  return Boolean::New(info.Env(), boolean);
}

Value OperatorBool(const CallbackInfo& info) {
  Boolean boolean(info.Env(), info[0].As<Boolean>());
  return Boolean::New(info.Env(), static_cast<bool>(boolean));
}

Object InitBasicTypesBoolean(Env env) {
  Object exports = Object::New(env);

  exports["createBoolean"] = Function::New(env, CreateBoolean);
  exports["createEmptyBoolean"] = Function::New(env, CreateEmptyBoolean);
  exports["createBooleanFromExistingValue"] =
      Function::New(env, CreateBooleanFromExistingValue);
  exports["createBooleanFromPrimitive"] =
      Function::New(env, CreateBooleanFromPrimitive);
  exports["operatorBool"] = Function::New(env, OperatorBool);
  return exports;
}