forked from nodejs/node-addon-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubscript_operator.cc
More file actions
42 lines (35 loc) · 1.13 KB
/
subscript_operator.cc
File metadata and controls
42 lines (35 loc) · 1.13 KB
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
41
42
#include "napi.h"
using namespace Napi;
Value SubscriptGetWithCStyleString(const CallbackInfo& info) {
Object obj = info[0].As<Object>();
String jsKey = info[1].As<String>();
return obj[jsKey.Utf8Value().c_str()];
}
Value SubscriptGetWithCppStyleString(const CallbackInfo& info) {
Object obj = info[0].As<Object>();
String jsKey = info[1].As<String>();
return obj[jsKey.Utf8Value()];
}
Value SubscriptGetAtIndex(const CallbackInfo& info) {
Object obj = info[0].As<Object>();
uint32_t index = info[1].As<Napi::Number>();
return obj[index];
}
void SubscriptSetWithCStyleString(const CallbackInfo& info) {
Object obj = info[0].As<Object>();
String jsKey = info[1].As<String>();
Value value = info[2];
obj[jsKey.Utf8Value().c_str()] = value;
}
void SubscriptSetWithCppStyleString(const CallbackInfo& info) {
Object obj = info[0].As<Object>();
String jsKey = info[1].As<String>();
Value value = info[2];
obj[jsKey.Utf8Value()] = value;
}
void SubscriptSetAtIndex(const CallbackInfo& info) {
Object obj = info[0].As<Object>();
uint32_t index = info[1].As<Napi::Number>();
Value value = info[2];
obj[index] = value;
}