@contrast/code-events
Advanced tools
Comparing version 1.0.1 to 2.0.0
@@ -26,5 +26,5 @@ /* eslint-disable @typescript-eslint/ban-types */ | ||
* Will start listening for code events if not already listening. | ||
* starts a timer which polls for an available code event once every `interval` ms. | ||
* starts a timer which polls for available code events once every `interval` ms. | ||
*/ | ||
setCodeEventListener(cb: (event: CodeEvent) => void, interval?: number): void; | ||
setCodeEventListener(cb: (event: CodeEvent) => void, options?: { interval?: number, excludeNode?: boolean, excludeNonFunction?: boolean }): void; | ||
@@ -31,0 +31,0 @@ /** Stop listening for v8 code events */ |
74
index.js
@@ -9,3 +9,3 @@ 'use strict'; | ||
module.exports = { | ||
const codeEvents = { | ||
/** | ||
@@ -17,5 +17,5 @@ * Sets the function for processing v8 code events. | ||
* @param {Function} cb callback function to process code events | ||
* @param {number} [interval=1000] polling interval in ms | ||
* @param {object} {interval:100, excludeNode:false, array:false} polling interval in ms | ||
*/ | ||
setCodeEventListener(cb, interval = 1000) { | ||
setCodeEventListener(cb, options = {}) { | ||
if (codeEventsInited) { | ||
@@ -26,10 +26,29 @@ codeEventListener = cb; | ||
binding.initHandler(); | ||
const { interval = 100, excludeNode = true, excludeNonFunction = true } = options; | ||
const bits = (excludeNode ? 1 : 0) | (excludeNonFunction ? 2 : 0); | ||
const active = binding.start(bits); | ||
codeEventsInited = true; | ||
codeEventListener = cb; | ||
timer = setInterval(() => { | ||
const codeEvent = binding.getNextCodeEvent(); | ||
if (codeEvent) codeEventListener(codeEvent); | ||
}, interval); | ||
function getEvents() { | ||
const start = process.hrtime.bigint(); | ||
let codeEvent; | ||
let i = 0; | ||
while ((codeEvent = binding.getEvent())) { | ||
i += 1; | ||
codeEventListener(codeEvent); | ||
} | ||
module.exports.totalEvents += i; | ||
module.exports.totalTime += process.hrtime.bigint() - start; | ||
} | ||
// get any outstanding events immediately | ||
getEvents(); | ||
// and then start polling | ||
timer = setInterval(getEvents, interval); | ||
timer.unref(); | ||
return active; | ||
}, | ||
@@ -41,6 +60,7 @@ | ||
stopListening() { | ||
if (!codeEventsInited) return; | ||
if (!codeEventsInited) { | ||
return; | ||
} | ||
clearInterval(timer); | ||
binding.deinitHandler(); | ||
binding.stop(); | ||
codeEventListener = null; | ||
@@ -50,1 +70,33 @@ codeEventsInited = false; | ||
}; | ||
// these are here for only for testing, so they're not enumerable. | ||
Object.defineProperties(codeEvents, { | ||
totalEvents: { | ||
enumerable: false, | ||
writable: true, | ||
value: 0, | ||
}, | ||
totalTime: { | ||
enumerable: false, | ||
writable: true, | ||
value: 0n, | ||
}, | ||
noop: { | ||
enumerable: false, | ||
value: binding.noop, | ||
}, | ||
size: { | ||
enumerable: false, | ||
value: binding.size, | ||
}, | ||
getEvent: { | ||
enumerable: false, | ||
value: binding.getEvent, | ||
}, | ||
stats: { | ||
enumerable: false, | ||
value: binding.stats, | ||
}, | ||
}); | ||
module.exports = codeEvents; |
{ | ||
"name": "@contrast/code-events", | ||
"version": "1.0.1", | ||
"description": "Subscribe to receive queued v8 CodeEvents on polling interval", | ||
"keywords": [ | ||
"instrumentation" | ||
], | ||
"author": "Contrast Security", | ||
"version": "2.0.0", | ||
"description": "Listen for v8 CodeEvents and make them available to JavaScript", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"repository": "", | ||
"author": "Contrast Security, Inc.", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Contrast-Security-Inc/node-code-events.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/Contrast-Security-Inc/node-code-events/issues" | ||
}, | ||
"homepage": "https://github.com/Contrast-Security-Inc/node-code-events#readme", | ||
"homepage": "", | ||
"files": [ | ||
"prebuilds/", | ||
"src/", | ||
"binding.gyp", | ||
"index.d.ts", | ||
"index.js" | ||
"index.js", | ||
"src/*", | ||
"binding.gyp" | ||
], | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"scripts": { | ||
"compile-commands": "node-gyp configure --release -- -f gyp.generator.compile_commands_json.py && mv Release/compile_commands.json ./", | ||
"rebuild": "node-gyp rebuild -j max", | ||
"rebuild-debug": "node-gyp rebuild -j max --debug", | ||
"install": "node-gyp-build", | ||
"prepare": "husky install", | ||
"prebuild": "npm run clean", | ||
"build": "prebuildify -t 12.13.0 -t 14.15.0 -t 16.9.1 -t 18.7.0 -t 20.5.0 --strip", | ||
"build:linux": "prebuildify-cross -i centos7-devtoolset7 -i alpine -i linux-arm64 -t 12.13.0 -t 14.15.0 -t 16.9.1 -t 18.7.0 -t 20.5.0 --strip", | ||
"build": "prebuildify -t 14.15.0 -t 16.9.1 -t 18.7.0 -t 20.6.0 --strip", | ||
"build:linux": "prebuildify-cross -i centos7-devtoolset7 -i alpine -i linux-arm64 -t 14.15.0 -t 16.9.1 -t 18.7.0 -t 20.6.0 --strip", | ||
"build:darwin": "npm run build -- --arch x64+arm64", | ||
@@ -37,10 +31,10 @@ "build:win32": "npm run build", | ||
"download": "node scripts/download-artifacts.js", | ||
"test": "c8 --reporter lcov --reporter text mocha .", | ||
"test:valgrind": "valgrind --xml=yes --xml-file=./valgrind.xml --trace-children=yes --leak-check=full --show-leak-kinds=all mocha . && node scripts/parse-valgrind.js" | ||
"test": "c8 --reporter lcov --reporter text mocha test/*.test.js", | ||
"test:valgrind": "valgrind --xml=yes --xml-file=./valgrind.xml --trace-children=yes --leak-check=full --show-leak-kinds=all node ./scripts/execute-leak-suite.js" | ||
}, | ||
"keywords": [], | ||
"engines": { | ||
"node": ">=12.13.0" | ||
"node": ">=14.15" | ||
}, | ||
"dependencies": { | ||
"nan": "^2.17.0", | ||
"node-gyp-build": "^4.6.0" | ||
@@ -54,5 +48,8 @@ }, | ||
"chai": "^4.3.7", | ||
"fast-xml-parser": "^4.3.3", | ||
"husky": "^8.0.3", | ||
"lint-staged": "^13.2.3", | ||
"mocha": "^10.2.0", | ||
"nan": "^2.18.0", | ||
"node-addon-api": "^7.1.0", | ||
"node-gyp": "^9.4.1", | ||
@@ -59,0 +56,0 @@ "prebuildify": "^5.0.1", |
@@ -5,3 +5,3 @@ # @contrast/code-events | ||
This module exposes CodeEvent data from the underlying v8 engine, such as 'LAZY_COMPILE'. | ||
This module exposes CodeEvent data from the underlying v8 engine, such as the 'LAZY_COMPILE' and 'FUNCTION' types. | ||
@@ -15,3 +15,3 @@ ## Usage | ||
// with the default poll interval of one second: | ||
// with the default poll interval of 100ms: | ||
setCodeEventListener((event) => { | ||
@@ -24,15 +24,3 @@ console.log(event); | ||
console.log(event); | ||
}, 500); | ||
}, { interval: 500 }); | ||
``` | ||
``` | ||
## Building locally | ||
`npm run build` will build the project for your current OS and architecture. | ||
`npm run download` will pull the most recent build artifacts from GitHub. | ||
## Publishing | ||
Simply run `npm version` and `git push && git push --tags`. CI will take care of | ||
releasing on taggedcommits. |
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
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
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
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
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 5 instances in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
1792649
1
115
21
18
29
24
1
- Removednan@^2.17.0
- Removednan@2.22.0(transitive)