diff options
author | Anna Henningsen <anna@addaleax.net> | 2018-10-06 17:26:02 -0700 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-10-12 14:29:52 -0700 |
commit | 4d16d1ed344dd0ff91ae421dab64e44335c2e4e2 (patch) | |
tree | 7d1f4755348801fc2367c1ce5bc6ae9f2194d5dc /src/node_zlib.cc | |
parent | 627bcf7f275e266d8ec5c42bcedd68c188444ead (diff) | |
download | node-new-4d16d1ed344dd0ff91ae421dab64e44335c2e4e2.tar.gz |
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: https://github.com/nodejs/node/pull/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>
Diffstat (limited to 'src/node_zlib.cc')
-rw-r--r-- | src/node_zlib.cc | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/node_zlib.cc b/src/node_zlib.cc index 6e99f68108..aef5e3e40f 100644 --- a/src/node_zlib.cc +++ b/src/node_zlib.cc @@ -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); |