New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

continuation-local-storage

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

continuation-local-storage - npm Package Compare versions

Comparing version 2.3.3 to 2.3.4

63

context.js
'use strict';
var assert = require('assert');
var wrap = require('shimmer').wrap;
var assert = require('assert');
var shimmer = require('shimmer');

@@ -103,4 +103,4 @@ // load polyfill if native support is unavailable

// old-style streaming overwrites .on and .addListener, so rewrap
if (!this.on.__wrapped) wrap(this, 'on', capturer);
if (!this.addListener.__wrapped) wrap(this, 'addListener', capturer);
if (!this.on.__wrapped) shimmer.wrap(this, 'on', capturer);
if (!this.addListener.__wrapped) shimmer.wrap(this, 'addListener', capturer);
}

@@ -116,14 +116,22 @@ };

// find all the handlers with attached contexts
function prepare(handlers) {
var replacements = [];
for (var i = 0; i < handlers.length; i++) {
var handler = handlers[i];
var context = handler[contextName];
function prepare(unwrapped) {
if (typeof unwrapped === 'function' && unwrapped[contextName]) {
return namespace.bind(unwrapped, unwrapped[contextName]);
}
else if (unwrapped && unwrapped.length) {
var replacements = [];
for (var i = 0; i < unwrapped.length; i++) {
var handler = unwrapped[i];
var context = handler[contextName];
if (context) handler = namespace.bind(handler, context);
if (context) handler = namespace.bind(handler, context);
replacements[i] = handler;
replacements[i] = handler;
}
return replacements;
}
return replacements;
else {
return unwrapped;
}
}

@@ -135,9 +143,17 @@

// wrap
var events = this._events[event];
if (typeof events === 'function' && events[contextName]) {
this._events[event] = namespace.bind(events, events[contextName]);
var unwrapped = this._events[event];
function releaser(removeListener) {
return function unwrapRemove() {
this._events[event] = unwrapped;
try {
return removeListener.apply(this, arguments);
}
finally {
unwrapped = this._events[event];
this._events[event] = prepare(unwrapped);
}
};
}
else if (events.length) {
this._events[event] = prepare(events);
}
shimmer.wrap(this, 'removeListener', releaser);
this._events[event] = prepare(unwrapped);

@@ -150,3 +166,4 @@ try {

// reset
this._events[event] = events;
shimmer.unwrap(this, 'removeListener');
this._events[event] = unwrapped;
}

@@ -156,5 +173,5 @@ };

wrap(source, 'addListener', capturer);
wrap(source, 'on', capturer);
wrap(source, 'emit', puncher);
shimmer.wrap(source, 'addListener', capturer);
shimmer.wrap(source, 'on', capturer);
shimmer.wrap(source, 'emit', puncher);
};

@@ -161,0 +178,0 @@

{
"name": "continuation-local-storage",
"version": "2.3.3",
"version": "2.3.4",
"description": "userland implementation of https://github.com/joyent/node/issues/5243",

@@ -37,4 +37,4 @@ "main": "context.js",

"dependencies": {
"shimmer": "~0.7"
"shimmer": "0.7.3"
}
}

@@ -16,3 +16,3 @@ 'use strict';

test("event emitters bound to CLS context", function (t) {
t.plan(8);
t.plan(9);

@@ -138,2 +138,39 @@ t.test("handler registered in context", function (t) {

t.test("emitter with newListener that removes handler", function (t) {
t.plan(3);
var n = fresh('newListener', this)
, ee = new EventEmitter()
;
// add monkeypatching to ee
n.bindEmitter(ee);
function listen() {
ee.on('data', function (chunk) {
t.equal(chunk, 'chunk', 'listener still works');
});
}
ee.on('newListener', function handler(event) {
if (event !== 'data') return;
this.removeListener('newListener', handler);
t.notOk(this.listeners('newListener').length, 'newListener was removed');
process.nextTick(listen);
});
ee.on('drain', function (chunk) {
process.nextTick(function () {
ee.emit('data', chunk);
});
});
ee.on('data', function (chunk) {
t.equal(chunk, 'chunk', 'got data event');
});
ee.emit('drain', 'chunk');
});
t.test("handler registered in context on Readable", function (t) {

@@ -140,0 +177,0 @@ var Readable = require('stream').Readable;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc