Huge News!Announcing our $40M Series B led by Abstract Ventures.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.5.2 to 2.6.0

19

context.js

@@ -12,2 +12,3 @@ 'use strict';

var CONTEXTS_SYMBOL = 'cls@contexts';
var ERROR_SYMBOL = 'error@context';

@@ -47,2 +48,6 @@ // load polyfill if native support is unavailable

}
catch (exception) {
exception[ERROR_SYMBOL] = context;
throw exception;
}
finally {

@@ -61,2 +66,6 @@ this.exit(context);

}
catch (exception) {
exception[ERROR_SYMBOL] = context;
throw exception;
}
finally {

@@ -127,2 +136,12 @@ self.exit(context);

/**
* If an error comes out of a namespace, it will have a context attached to it.
* This function knows how to find it.
*
* @param {Error} exception Possibly annotated error.
*/
Namespace.prototype.fromException = function (exception) {
return exception[ERROR_SYMBOL];
};
function get(name) {

@@ -129,0 +148,0 @@ return namespaces[name];

2

package.json
{
"name": "continuation-local-storage",
"version": "2.5.2",
"version": "2.6.0",
"description": "userland implementation of https://github.com/joyent/node/issues/5243",

@@ -5,0 +5,0 @@ "main": "context.js",

@@ -21,2 +21,3 @@ 'use strict';

cls.destroyNamespace('test');
t.end();

@@ -37,1 +38,74 @@ });

});
test("synchronous throw attaches the context", function (t) {
t.plan(3);
var namespace = cls.createNamespace('cls@synchronous');
namespace.set('value', 'transaction clear');
try {
namespace.run(function () {
namespace.set('value', 'transaction set');
throw new Error('cls@synchronous explosion');
});
}
catch (e) {
t.ok(namespace.fromException(e), "context was attached to error");
t.equal(namespace.fromException(e)['value'], 'transaction set',
"found the inner value");
}
t.equal(namespace.get('value'), 'transaction clear', "everything was reset");
cls.destroyNamespace('cls@synchronous');
});
test("throw in process.nextTick attaches the context", function (t) {
t.plan(3);
var namespace = cls.createNamespace('cls@nexttick');
var d = domain.create();
namespace.set('value', 'transaction clear');
d.on('error', function (e) {
t.ok(namespace.fromException(e), "context was attached to error");
t.equal(namespace.fromException(e)['value'], 'transaction set',
"found the inner value");
cls.destroyNamespace('cls@nexttick');
});
// tap is only trying to help
process.nextTick(d.bind(function () {
namespace.run(function () {
namespace.set('value', 'transaction set');
throw new Error("cls@nexttick explosion");
});
}));
t.equal(namespace.get('value'), 'transaction clear', "everything was reset");
});
test("throw in setTimeout attaches the context", function (t) {
t.plan(3);
var namespace = cls.createNamespace('cls@nexttick');
var d = domain.create();
namespace.set('value', 'transaction clear');
d.on('error', function (e) {
t.ok(namespace.fromException(e), "context was attached to error");
t.equal(namespace.fromException(e)['value'], 'transaction set',
"found the inner value");
cls.destroyNamespace('cls@nexttick');
});
// tap is only trying to help
setTimeout(d.bind(function () {
namespace.run(function () {
namespace.set('value', 'transaction set');
throw new Error("cls@nexttick explosion");
});
}));
t.equal(namespace.get('value'), 'transaction clear', "everything was reset");
});
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