File tree Expand file tree Collapse file tree 5 files changed +66
-1
lines changed
test/addons/parse-encoding Expand file tree Collapse file tree 5 files changed +66
-1
lines changed Original file line number Diff line number Diff line change @@ -145,7 +145,7 @@ ADDONS_BINDING_GYPS := \
145
145
146
146
ADDONS_BINDING_SOURCES := \
147
147
$(filter-out test/addons/??_* /* .cc, $(wildcard test/addons/* /* .cc) ) \
148
- $(filter-out test/addons/??_* /* .h, $(wildcard test/addons/* /* .h) ) \
148
+ $(filter-out test/addons/??_* /* .h, $(wildcard test/addons/* /* .h) )
149
149
150
150
# Implicitly depends on $(NODE_EXE), see the build-addons rule for rationale.
151
151
# Depends on node-gyp package.json so that build-addons is (re)executed when
Original file line number Diff line number Diff line change @@ -1416,6 +1416,7 @@ enum encoding ParseEncoding(const char* encoding,
1416
1416
if (strncmp (encoding + 2 , " tin1" , 4 ) == 0 )
1417
1417
return LATIN1;
1418
1418
}
1419
+ break ;
1419
1420
case ' b' :
1420
1421
// binary
1421
1422
if (encoding[1 ] == ' i' ) {
Original file line number Diff line number Diff line change
1
+ #include " node.h"
2
+ #include " v8.h"
3
+
4
+ namespace {
5
+
6
+ #define ENCODING_MAP (V ) \
7
+ V (ASCII) \
8
+ V (BASE64) \
9
+ V (BUFFER) \
10
+ V (HEX) \
11
+ V (LATIN1) \
12
+ V (UCS2) \
13
+ V (UTF8) \
14
+
15
+ void ParseEncoding (const v8::FunctionCallbackInfo<v8::Value>& args) {
16
+ const node::encoding encoding =
17
+ node::ParseEncoding (args.GetIsolate (), args[0 ],
18
+ static_cast <node::encoding>(-1 ));
19
+ const char * encoding_name = " UNKNOWN" ;
20
+ #define V (name ) if (encoding == node::name) encoding_name = #name;
21
+ ENCODING_MAP (V)
22
+ #undef V
23
+ auto encoding_string =
24
+ v8::String::NewFromUtf8 (args.GetIsolate (), encoding_name,
25
+ v8::NewStringType::kNormal )
26
+ .ToLocalChecked ();
27
+ args.GetReturnValue ().Set (encoding_string);
28
+ }
29
+
30
+ void Initialize (v8::Local<v8::Object> target) {
31
+ NODE_SET_METHOD (target, " parseEncoding" , ParseEncoding);
32
+ }
33
+
34
+ } // anonymous namespace
35
+
36
+ NODE_MODULE (binding, Initialize);
Original file line number Diff line number Diff line change
1
+ {
2
+ 'targets' : [
3
+ {
4
+ 'target_name' : 'binding' ,
5
+ 'defines' : [ 'V8_DEPRECATION_WARNINGS=1' ],
6
+ 'sources' : [ 'binding.cc' ]
7
+ }
8
+ ]
9
+ }
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ require ( '../../common' ) ;
4
+ const assert = require ( 'assert' ) ;
5
+ const { parseEncoding } = require ( './build/Release/binding' ) ;
6
+
7
+ assert . strictEqual ( parseEncoding ( '' ) , 'UNKNOWN' ) ;
8
+
9
+ assert . strictEqual ( parseEncoding ( 'ascii' ) , 'ASCII' ) ;
10
+ assert . strictEqual ( parseEncoding ( 'base64' ) , 'BASE64' ) ;
11
+ assert . strictEqual ( parseEncoding ( 'binary' ) , 'LATIN1' ) ;
12
+ assert . strictEqual ( parseEncoding ( 'buffer' ) , 'BUFFER' ) ;
13
+ assert . strictEqual ( parseEncoding ( 'hex' ) , 'HEX' ) ;
14
+ assert . strictEqual ( parseEncoding ( 'latin1' ) , 'LATIN1' ) ;
15
+ assert . strictEqual ( parseEncoding ( 'ucs2' ) , 'UCS2' ) ;
16
+ assert . strictEqual ( parseEncoding ( 'utf8' ) , 'UTF8' ) ;
17
+
18
+ assert . strictEqual ( parseEncoding ( 'linary' ) , 'UNKNOWN' ) ;
19
+ assert . strictEqual ( parseEncoding ( 'luffer' ) , 'UNKNOWN' ) ;
You can’t perform that action at this time.
0 commit comments