Skip to content

Commit

Permalink
Merge pull request #49 from Contrast-Security-Inc/fn-inspect-only
Browse files Browse the repository at this point in the history
Fn inspect only
  • Loading branch information
bmacnaughton authored Dec 20, 2023
2 parents 0779495 + ae77521 commit cd9dbe4
Show file tree
Hide file tree
Showing 16 changed files with 169 additions and 541 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@ jobs:
with:
node-version: ${{ matrix.node }}
architecture: x64
- name: Install
- name: Python version
run: python --version
- name: Install setuptools
run: pip install setuptools
- name: Update npm
run: npm install -g npm@8
- name: Install dependencies
run: npm ci
- name: Show node-gyp version
run: npm ls node-gyp
- name: Test
run: npm test
18 changes: 18 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${default}",
"${NVM_INC}",
"node_modules/nan"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c17",
"cppStandard": "gnu++17",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
7 changes: 2 additions & 5 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
{
"variables" : {
"openssl_fips": "",
"openssl_fips": ""
},
"targets": [
{
"target_name": "fninspect",
"sources": [
"src/addon.cc",
"src/code-events.cc",
"src/event-queue.cc",
"src/func-info.cc"
"src/addon.cc"
],
"include_dirs": [
"<!(node -e \"require('nan')\")"
Expand Down
29 changes: 0 additions & 29 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,9 @@ declare interface FunctionInfo {
type: 'AsyncFunction' | 'Function';
}

declare interface CodeEvent {
func: string;
lineNumber: number;
script: string;
type:
| 'Builtin'
| 'Callback'
| 'Eval'
| 'Function'
| 'InterpretedFunction'
| 'Handler'
| 'BytecodeHandler'
| 'LazyCompile'
| 'RegExp'
| 'Script'
| 'Stub'
| 'Relocation'
}

declare const fnInspect: {
/** Retrieves name, type, column, lineNumber and file from a function reference */
funcInfo(fn: Function): FunctionInfo | 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 `interval` ms.
*/
setCodeEventListener(cb: (event: CodeEvent) => void, interval?: number): void;

/** Stop listening for v8 code events */
stopListening(): void;
};

export = fnInspect;
39 changes: 0 additions & 39 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

const binding = require('node-gyp-build')(__dirname);

let codeEventsInited = false;
let codeEventListener = null;
let timer = null;

module.exports = {
/**
* Retrieves name, type, column, lineNumber and file from a function reference
Expand All @@ -20,39 +16,4 @@ module.exports = {
info.type = fn.constructor.name;
return info;
},

/**
* 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 `interval` value.
*
* @param {Function} cb callback function to call
* @param {number} [interval=1] how often to get code events in ms
*/
setCodeEventListener(cb, interval = 1) {
if (codeEventsInited) {
codeEventListener = cb;
return;
}

binding.initHandler();
codeEventsInited = true;
codeEventListener = cb;
timer = setInterval(() => {
const codeEvent = binding.getNextCodeEvent();
if (codeEvent) codeEventListener(codeEvent);
}, interval);
},

/**
* Stop listening for v8 code events
*/
stopListening() {
if (!codeEventsInited) return;

clearInterval(timer);
binding.deinitHandler();
codeEventListener = null;
codeEventsInited = false;
},
};
Loading

0 comments on commit cd9dbe4

Please sign in to comment.