From 72f95e26106c77687c911ab3d26c16e3443d507c Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sun, 30 Sep 2018 21:08:12 -0400 Subject: [PATCH] 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 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Luigi Pinca Reviewed-By: Tiancheng "Timothy" Gu --- lib/zlib.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/zlib.js b/lib/zlib.js index 6fb7696849529d..68d06fa93fbaa2 100644 --- a/lib/zlib.js +++ b/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,