Skip to content

Commit e749a28

Browse files
addaleaxtargos
authored andcommitted
zlib: use common owner symbol to access JS wrapper
Use the same symbol that other `AsyncWrap` instances also use for accessing the JS wrapper. PR-URL: #23189 Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
1 parent 4c54f89 commit e749a28

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lib/zlib.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const {
4242
Buffer,
4343
kMaxLength
4444
} = require('buffer');
45+
const { owner_symbol } = require('internal/async_hooks').symbols;
4546

4647
const constants = process.binding('constants').zlib;
4748
const {
@@ -143,7 +144,7 @@ function zlibBufferSync(engine, buffer) {
143144
}
144145

145146
function zlibOnError(message, errno) {
146-
var self = this.jsref;
147+
var self = this[owner_symbol];
147148
// there is no way to cleanly recover.
148149
// continuing only obscures problems.
149150
_close(self);
@@ -289,7 +290,8 @@ function Zlib(opts, mode) {
289290
Transform.call(this, opts);
290291
this.bytesWritten = 0;
291292
this._handle = new binding.Zlib(mode);
292-
this._handle.jsref = this; // Used by processCallback() and zlibOnError()
293+
// Used by processCallback() and zlibOnError()
294+
this._handle[owner_symbol] = this;
293295
this._handle.onerror = zlibOnError;
294296
this._hadError = false;
295297
this._writeState = new Uint32Array(2);
@@ -717,6 +719,13 @@ function createProperty(ctor) {
717719
};
718720
}
719721

722+
// Legacy alias on the C++ wrapper object. This is not public API, so we may
723+
// want to runtime-deprecate it at some point. There's no hurry, though.
724+
Object.defineProperty(binding.Zlib.prototype, 'jsref', {
725+
get() { return this[owner_symbol]; },
726+
set(v) { return this[owner_symbol] = v; }
727+
});
728+
720729
module.exports = {
721730
Deflate,
722731
Inflate,

0 commit comments

Comments
 (0)