Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7fd1b4d

Browse filesBrowse files
addaleaxMylesBorins
authored andcommitted
zlib: generate error code names in C++
This makes it easier to implement the lookup in a way that targets error codes from a specific compression library, as a way towards supporting multiple ones (e.g. brotli). PR-URL: #23413 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 65ae332 commit 7fd1b4d
Copy full SHA for 7fd1b4d

File tree

Expand file treeCollapse file tree

2 files changed

+24
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+24
-5
lines changed
Open diff view settings
Collapse file

‎lib/zlib.js‎

Copy file name to clipboardExpand all lines: lib/zlib.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ function zlibBufferSync(engine, buffer) {
143143
return buffer;
144144
}
145145

146-
function zlibOnError(message, errno) {
146+
function zlibOnError(message, errno, code) {
147147
var self = this[owner_symbol];
148148
// there is no way to cleanly recover.
149149
// continuing only obscures problems.
@@ -153,7 +153,7 @@ function zlibOnError(message, errno) {
153153
// eslint-disable-next-line no-restricted-syntax
154154
const error = new Error(message);
155155
error.errno = errno;
156-
error.code = codes[errno];
156+
error.code = code;
157157
self.emit('error', error);
158158
}
159159

Collapse file

‎src/node_zlib.cc‎

Copy file name to clipboardExpand all lines: src/node_zlib.cc
+22-3Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ using v8::FunctionCallbackInfo;
4646
using v8::FunctionTemplate;
4747
using v8::HandleScope;
4848
using v8::Int32;
49+
using v8::Integer;
4950
using v8::Local;
50-
using v8::Number;
5151
using v8::Object;
5252
using v8::String;
5353
using v8::Uint32;
@@ -56,6 +56,24 @@ using v8::Value;
5656

5757
namespace {
5858

59+
#define ZLIB_ERROR_CODES(V) \
60+
V(Z_OK) \
61+
V(Z_STREAM_END) \
62+
V(Z_NEED_DICT) \
63+
V(Z_ERRNO) \
64+
V(Z_STREAM_ERROR) \
65+
V(Z_DATA_ERROR) \
66+
V(Z_MEM_ERROR) \
67+
V(Z_BUF_ERROR) \
68+
V(Z_VERSION_ERROR) \
69+
70+
inline const char* ZlibStrerror(int err) {
71+
#define V(code) if (err == code) return #code;
72+
ZLIB_ERROR_CODES(V)
73+
#undef V
74+
return "Z_UNKNOWN_ERROR";
75+
}
76+
5977
enum node_zlib_mode {
6078
NONE,
6179
DEFLATE,
@@ -404,9 +422,10 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
404422
}
405423

406424
HandleScope scope(env()->isolate());
407-
Local<Value> args[2] = {
425+
Local<Value> args[3] = {
408426
OneByteString(env()->isolate(), message),
409-
Number::New(env()->isolate(), err_)
427+
Integer::New(env()->isolate(), err_),
428+
OneByteString(env()->isolate(), ZlibStrerror(err_))
410429
};
411430
MakeCallback(env()->onerror_string(), arraysize(args), args);
412431

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.