GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — zlib: use common owner symbol to access JS wrapper · nodejs/node@e749a28

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • zlib.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/zlib.js‎

Copy file name to clipboardExpand all lines: lib/zlib.js
+11-2Lines changed: 11 additions & 2 deletions
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 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.