Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@contrast/fn-inspect

Package Overview
Dependencies
Maintainers
18
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@contrast/fn-inspect - npm Package Compare versions

Comparing version 1.0.1 to 2.0.1

code-event-types.js

98

index.js
'use strict';
let funcinfo;
const name = 'funcinfo.node';
let codeEventsInited, codeEventListener, _interval;
const version = process.version.split('.')[0].substring(1);
const codeEventTypes = require('./code-event-types');
try {
({ funcinfo } = require(`./build/Release/${name}`));
} catch (e) {
({
funcinfo
} = require(`${__dirname}/${process.platform}-${version}/${name}`));
codeEventsInited = false;
function modLoad(name) {
const locations = [
`./build/Debug/${name}`,
`./build/Release/${name}`,
`${__dirname}/${process.platform}-${version}/${name}`
];
for (let i = 0; i < locations.length; i++) {
try {
const mod = require(locations[i]);
return mod;
// eslint-disable-next-line no-empty
} catch (e) {}
}
throw new Error(`failed to load ${name}`);
}
/**
* Retrieves name, type, lineNumber and file from a function reference
*
* @param {function} fn function reference to obtain info
* @return {object}
*/
module.exports = (fn) => {
if (typeof fn === 'function') {
const info = funcinfo(fn);
info.type = fn.__proto__.constructor.name;
info.method = fn.name;
return info;
} else {
return null;
const { funcinfo } = modLoad('funcinfo.node');
const codeEvents = modLoad('codeevents.node');
module.exports = {
/**
* Retrieves name, type, lineNumber and file from a function reference
*
* @param {function} fn function reference to obtain info
* @return {object}
*/
funcinfo: (fn) => {
if (typeof fn === 'function') {
const info = funcinfo(fn);
info.type = fn.__proto__.constructor.name;
info.method = fn.name;
return info;
} else {
return null;
}
},
/**
* Sets the function for processing v8 code events.
* Will start listening for code events if not already listening.
* starts a timer which polls for an available code event once every 1 ms.
*
* @param {function} cb callback function to call
*/
setCodeEventListener: (cb) => {
if (!codeEventsInited) {
codeEvents.init();
codeEventsInited = true;
codeEventListener = cb;
_interval = setInterval(() => {
const codeEvent = codeEvents.getNext();
if (codeEvent) {
codeEvent.type = codeEventTypes[codeEvent.type];
codeEvent.ts = new Date(codeEvent.ts);
codeEventListener(codeEvent);
}
}, 1); // TODO configurable frequency?
} else {
codeEventListener = cb;
}
},
/**
* Stop listening for v8 code events
*/
stopListening: () => {
if (!codeEventsInited) {
return;
}
clearInterval(_interval);
codeEvents.deinit();
codeEventListener = null;
codeEventsInited = false;
}
};
{
"name": "@contrast/fn-inspect",
"version": "1.0.1",
"version": "2.0.1",
"description": "Retrieve function name and line number from a function reference",
"main": "index.js",
"scripts": {
"test": "mocha test"
"valgrind-test": "valgrind --trace-children=yes --leak-check=full --show-leak-kinds=all mocha --timeout 60000 test",
"test": "nyc --reporter=text-summary --reporter=html --report-dir=./coverage mocha test"
},

@@ -25,3 +26,3 @@ "repository": {

"hooks": {
"pre-commit": "lint-staged"
"pre-commit": "lint-staged && npx ls-lint"
}

@@ -37,2 +38,3 @@ },

"@contrast/eslint-config": "^2.0.0",
"@ls-lint/ls-lint": "^1.8.1",
"chai": "^4.2.0",

@@ -48,2 +50,3 @@ "eslint": "^6.8.0",

"node-gyp": "^6.1.0",
"nyc": "^15.0.1",
"prettier": "^1.19.1"

@@ -50,0 +53,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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