-
-
Notifications
You must be signed in to change notification settings - Fork 512
/
Copy pathstrings.cpp
79 lines (59 loc) · 2.09 KB
/
strings.cpp
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*********************************************************************
* NAN - Native Abstractions for Node.js
*
* Copyright (c) 2018 NAN contributors
*
* MIT License <https://github.com/nodejs/nan/blob/master/LICENSE.md>
********************************************************************/
#include <nan.h>
using namespace Nan; // NOLINT(build/namespaces)
NAN_METHOD(ReturnUtf8String) {
info.GetReturnValue().Set(New(*Utf8String(info[0])).ToLocalChecked());
}
NAN_METHOD(HeapString) {
Utf8String *s = new Utf8String(info[0]);
v8::Local<v8::String> res = New(**s).ToLocalChecked();
delete s;
info.GetReturnValue().Set(res);
}
NAN_METHOD(EncodeHex) {
info.GetReturnValue().Set(Encode("hello", 5, HEX));
}
NAN_METHOD(EncodeUCS2) {
info.GetReturnValue().Set(Encode(u"hello", 10, UCS2));
}
Persistent<v8::FunctionTemplate> returnUtf8String_persistent;
Persistent<v8::FunctionTemplate> heapString_persistent;
Persistent<v8::FunctionTemplate> encodeHex_persistent;
Persistent<v8::FunctionTemplate> encodeUCS2_persistent;
NAN_MODULE_INIT(Init) {
v8::Local<v8::FunctionTemplate> returnUtf8String =
New<v8::FunctionTemplate>(ReturnUtf8String);
returnUtf8String_persistent.Reset(returnUtf8String);
Set(target
, New("returnUtf8String").ToLocalChecked()
, GetFunction(returnUtf8String).ToLocalChecked()
).FromJust();
v8::Local<v8::FunctionTemplate> heapString =
New<v8::FunctionTemplate>(HeapString);
heapString_persistent.Reset(heapString);
Set(target
, New("heapString").ToLocalChecked()
, GetFunction(heapString).ToLocalChecked()
).FromJust();
v8::Local<v8::FunctionTemplate> encodeHex =
New<v8::FunctionTemplate>(EncodeHex);
encodeHex_persistent.Reset(encodeHex);
Set(target
, New("encodeHex").ToLocalChecked()
, GetFunction(encodeHex).ToLocalChecked()
).FromJust();
v8::Local<v8::FunctionTemplate> encodeUCS2 =
New<v8::FunctionTemplate>(EncodeUCS2);
encodeUCS2_persistent.Reset(encodeUCS2);
Set(target
, New("encodeUCS2").ToLocalChecked()
, GetFunction(encodeUCS2).ToLocalChecked()
).FromJust();
}
NODE_MODULE(strings, Init)