File: get_property.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 (34 lines) | stat: -rw-r--r-- 1,083 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
#include "napi.h"
#include "test_helper.h"

using namespace Napi;

Value GetPropertyWithNapiValue(const CallbackInfo& info) {
  Object obj = info[0].UnsafeAs<Object>();
  Name key = info[1].As<Name>();
  return MaybeUnwrapOr(obj.Get(static_cast<napi_value>(key)), Value());
}

Value GetPropertyWithNapiWrapperValue(const CallbackInfo& info) {
  Object obj = info[0].UnsafeAs<Object>();
  Name key = info[1].As<Name>();
  return MaybeUnwrapOr(obj.Get(key), Value());
}

Value GetPropertyWithUint32(const CallbackInfo& info) {
  Object obj = info[0].UnsafeAs<Object>();
  Number key = info[1].As<Number>();
  return MaybeUnwrap(obj.Get(key.Uint32Value()));
}

Value GetPropertyWithCStyleString(const CallbackInfo& info) {
  Object obj = info[0].UnsafeAs<Object>();
  String jsKey = info[1].As<String>();
  return MaybeUnwrapOr(obj.Get(jsKey.Utf8Value().c_str()), Value());
}

Value GetPropertyWithCppStyleString(const CallbackInfo& info) {
  Object obj = info[0].UnsafeAs<Object>();
  String jsKey = info[1].As<String>();
  return MaybeUnwrapOr(obj.Get(jsKey.Utf8Value()), Value());
}