11#include " napi.h"
22
3+ #if __cplusplus >= 201703L
4+ #include < string_view>
5+ #endif
6+
37using namespace Napi ;
48
59const char * testValueUtf8 = " 123456789" ;
@@ -43,6 +47,12 @@ Value CreateString(const CallbackInfo& info) {
4347 }
4448}
4549
50+ #if __cplusplus >= 201703L
51+ Value CreateStringFromStringView (const CallbackInfo& info) {
52+ return String::New (info.Env (), std::string_view (" hello1" ));
53+ }
54+ #endif
55+
4656Value CheckString (const CallbackInfo& info) {
4757 String value = info[0 ].As <String>();
4858 String encoding = info[1 ].As <String>();
@@ -80,6 +90,12 @@ Value CreateSymbol(const CallbackInfo& info) {
8090 }
8191}
8292
93+ #if __cplusplus >= 201703L
94+ Value CreateSymbolFromStringView (const CallbackInfo& info) {
95+ return Symbol::New (info.Env (), std::string_view (" hello2" ));
96+ }
97+ #endif
98+
8399Value CheckSymbol (const CallbackInfo& info) {
84100 return Boolean::New (info.Env (), info[0 ].Type () == napi_symbol);
85101}
@@ -99,11 +115,13 @@ Object InitName(Env env) {
99115
100116 exports[" echoString" ] = Function::New (env, EchoString);
101117 exports[" createString" ] = Function::New (env, CreateString);
118+ exports[" createStringFromStringView" ] = Function::New (env, CreateStringFromStringView);
102119 exports[" nullStringShouldThrow" ] = Function::New (env, NullStringShouldThrow);
103120 exports[" nullString16ShouldThrow" ] =
104121 Function::New (env, NullString16ShouldThrow);
105122 exports[" checkString" ] = Function::New (env, CheckString);
106123 exports[" createSymbol" ] = Function::New (env, CreateSymbol);
124+ exports[" CreateSymbolFromStringView" ] = Function::New (env, CreateSymbolFromStringView);
107125 exports[" checkSymbol" ] = Function::New (env, CheckSymbol);
108126
109127 return exports;
0 commit comments