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: https://github.com/nodejs/node/pull/23189 Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
This commit is contained in:
parent
4f0971d366
commit
a9bb653ecc
13
lib/zlib.js
13
lib/zlib.js
@ -42,6 +42,7 @@ const {
|
||||
Buffer,
|
||||
kMaxLength
|
||||
} = require('buffer');
|
||||
const { owner_symbol } = require('internal/async_hooks').symbols;
|
||||
|
||||
const constants = process.binding('constants').zlib;
|
||||
const {
|
||||
@ -143,7 +144,7 @@ function zlibBufferSync(engine, buffer) {
|
||||
}
|
||||
|
||||
function zlibOnError(message, errno) {
|
||||
var self = this.jsref;
|
||||
var self = this[owner_symbol];
|
||||
// there is no way to cleanly recover.
|
||||
// continuing only obscures problems.
|
||||
_close(self);
|
||||
@ -289,7 +290,8 @@ function Zlib(opts, mode) {
|
||||
Transform.call(this, opts);
|
||||
this.bytesWritten = 0;
|
||||
this._handle = new binding.Zlib(mode);
|
||||
this._handle.jsref = this; // Used by processCallback() and zlibOnError()
|
||||
// Used by processCallback() and zlibOnError()
|
||||
this._handle[owner_symbol] = this;
|
||||
this._handle.onerror = zlibOnError;
|
||||
this._hadError = false;
|
||||
this._writeState = new Uint32Array(2);
|
||||
@ -717,6 +719,13 @@ function createProperty(ctor) {
|
||||
};
|
||||
}
|
||||
|
||||
// Legacy alias on the C++ wrapper object. This is not public API, so we may
|
||||
// want to runtime-deprecate it at some point. There's no hurry, though.
|
||||
Object.defineProperty(binding.Zlib.prototype, 'jsref', {
|
||||
get() { return this[owner_symbol]; },
|
||||
set(v) { return this[owner_symbol] = v; }
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
Deflate,
|
||||
Inflate,
|
||||
|
Loading…
x
Reference in New Issue
Block a user