Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v10.x backport] test: refactor common.ddCommand() #23630

Closed
wants to merge 16 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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>
addaleax authored and Trott committed Oct 13, 2018
commit e86b6aa9ed49348176be9f685ae617f39daf6b7d
4 changes: 2 additions & 2 deletions lib/zlib.js
Original file line number Diff line number Diff line change
@@ -143,7 +143,7 @@ function zlibBufferSync(engine, buffer) {
return buffer;
}

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

25 changes: 22 additions & 3 deletions src/node_zlib.cc
Original file line number Diff line number Diff line change
@@ -46,8 +46,8 @@ using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
using v8::HandleScope;
using v8::Int32;
using v8::Integer;
using v8::Local;
using v8::Number;
using v8::Object;
using v8::String;
using v8::Uint32;
@@ -56,6 +56,24 @@ using v8::Value;

namespace {

#define ZLIB_ERROR_CODES(V) \
V(Z_OK) \
V(Z_STREAM_END) \
V(Z_NEED_DICT) \
V(Z_ERRNO) \
V(Z_STREAM_ERROR) \
V(Z_DATA_ERROR) \
V(Z_MEM_ERROR) \
V(Z_BUF_ERROR) \
V(Z_VERSION_ERROR) \

inline const char* ZlibStrerror(int err) {
#define V(code) if (err == code) return #code;
ZLIB_ERROR_CODES(V)
#undef V
return "Z_UNKNOWN_ERROR";
}

enum node_zlib_mode {
NONE,
DEFLATE,
@@ -404,9 +422,10 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
}

HandleScope scope(env()->isolate());
Local<Value> args[2] = {
Local<Value> args[3] = {
OneByteString(env()->isolate(), message),
Number::New(env()->isolate(), err_)
Integer::New(env()->isolate(), err_),
OneByteString(env()->isolate(), ZlibStrerror(err_))
};
MakeCallback(env()->onerror_string(), arraysize(args), args);