Skip to content

Commit a9fa2da

Browse files
anonrigtargos
authored andcommitted
zlib: throw brotli initialization error from c++
PR-URL: #54698 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent a679669 commit a9fa2da

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-14
lines changed

lib/internal/errors.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1889,4 +1889,3 @@ E('ERR_WORKER_UNSERIALIZABLE_ERROR',
18891889
'Serializing an uncaught exception failed', Error);
18901890
E('ERR_WORKER_UNSUPPORTED_OPERATION',
18911891
'%s is not supported in workers', TypeError);
1892-
E('ERR_ZLIB_INITIALIZATION_FAILED', 'Initialization failed', Error);

lib/zlib.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ const {
4242
ERR_BUFFER_TOO_LARGE,
4343
ERR_INVALID_ARG_TYPE,
4444
ERR_OUT_OF_RANGE,
45-
ERR_ZLIB_INITIALIZATION_FAILED,
4645
},
4746
genericNodeError,
4847
} = require('internal/errors');
@@ -815,14 +814,7 @@ function Brotli(opts, mode) {
815814
new binding.BrotliDecoder(mode) : new binding.BrotliEncoder(mode);
816815

817816
this._writeState = new Uint32Array(2);
818-
// TODO(addaleax): Sometimes we generate better error codes in C++ land,
819-
// e.g. ERR_BROTLI_PARAM_SET_FAILED -- it's hard to access them with
820-
// the current bindings setup, though.
821-
if (!handle.init(brotliInitParamsArray,
822-
this._writeState,
823-
processCallback)) {
824-
throw new ERR_ZLIB_INITIALIZATION_FAILED();
825-
}
817+
handle.init(brotliInitParamsArray, this._writeState, processCallback);
826818

827819
ReflectApply(ZlibBase, this, [opts, mode, handle, brotliDefaultOpts]);
828820
}

src/node_errors.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ void OOMErrorHandler(const char* location, const v8::OOMDetails& details);
108108
V(ERR_VM_MODULE_CACHED_DATA_REJECTED, Error) \
109109
V(ERR_VM_MODULE_LINK_FAILURE, Error) \
110110
V(ERR_WASI_NOT_STARTED, Error) \
111+
V(ERR_ZLIB_INITIALIZATION_FAILED, Error) \
111112
V(ERR_WORKER_INIT_FAILED, Error) \
112113
V(ERR_PROTO_ACCESS, Error)
113114

src/node_zlib.cc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "async_wrap-inl.h"
2727
#include "env-inl.h"
28+
#include "node_errors.h"
2829
#include "node_external_reference.h"
2930
#include "threadpoolwork-inl.h"
3031
#include "util-inl.h"
@@ -271,6 +272,8 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork {
271272
CHECK_EQ(unreported_allocations_, 0);
272273
}
273274

275+
Environment* env() const { return this->ThreadPoolWork::env(); }
276+
274277
void Close() {
275278
if (write_in_progress_) {
276279
pending_close_ = true;
@@ -694,7 +697,11 @@ class BrotliCompressionStream final :
694697
static_cast<CompressionStream<CompressionContext>*>(wrap));
695698
if (err.IsError()) {
696699
wrap->EmitError(err);
697-
args.GetReturnValue().Set(false);
700+
// TODO(addaleax): Sometimes we generate better error codes in C++ land,
701+
// e.g. ERR_BROTLI_PARAM_SET_FAILED -- it's hard to access them with
702+
// the current bindings setup, though.
703+
THROW_ERR_ZLIB_INITIALIZATION_FAILED(wrap->env(),
704+
"Initialization failed");
698705
return;
699706
}
700707

@@ -708,12 +715,11 @@ class BrotliCompressionStream final :
708715
err = wrap->context()->SetParams(i, data[i]);
709716
if (err.IsError()) {
710717
wrap->EmitError(err);
711-
args.GetReturnValue().Set(false);
718+
THROW_ERR_ZLIB_INITIALIZATION_FAILED(wrap->env(),
719+
"Initialization failed");
712720
return;
713721
}
714722
}
715-
716-
args.GetReturnValue().Set(true);
717723
}
718724

719725
static void Params(const FunctionCallbackInfo<Value>& args) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy