Init
This commit is contained in:
19
node_modules/stack-trace/License
generated
vendored
Normal file
19
node_modules/stack-trace/License
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2011 Felix Geisendörfer (felix@debuggable.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
100
node_modules/stack-trace/Readme.md
generated
vendored
Normal file
100
node_modules/stack-trace/Readme.md
generated
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
# stack-trace
|
||||
|
||||
[](https://travis-ci.org/felixge/node-stack-trace)
|
||||
|
||||
Get v8 stack traces as an array of CallSite objects.
|
||||
|
||||
## Install
|
||||
|
||||
``` bash
|
||||
npm install stack-trace
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
The stack-trace module makes it easy for you to capture the current stack:
|
||||
|
||||
```javascript
|
||||
import { get } from 'stack-trace';
|
||||
const trace = get();
|
||||
|
||||
expect(trace[0].getFileName()).toBe(__filename);
|
||||
```
|
||||
|
||||
However, sometimes you have already popped the stack you are interested in,
|
||||
and all you have left is an `Error` object. This module can help:
|
||||
|
||||
```javascript
|
||||
import { parse } from 'stack-trace';
|
||||
const err = new Error('something went wrong');
|
||||
const trace = parse(err);
|
||||
|
||||
expect(trace[0].getFileName()).toBe(__filename);
|
||||
```
|
||||
|
||||
Please note that parsing the `Error#stack` property is not perfect, only
|
||||
certain properties can be retrieved with it as noted in the API docs below.
|
||||
|
||||
## Long stack traces
|
||||
|
||||
stack-trace works great with [long-stack-traces][], when parsing an `err.stack`
|
||||
that has crossed the event loop boundary, a `CallSite` object returning
|
||||
`'----------------------------------------'` for `getFileName()` is created.
|
||||
All other methods of the event loop boundary call site return `null`.
|
||||
|
||||
[long-stack-traces]: https://github.com/tlrobinson/long-stack-traces
|
||||
|
||||
## API
|
||||
|
||||
### stackTrace.get([belowFn])
|
||||
|
||||
Returns an array of `CallSite` objects, where element `0` is the current call
|
||||
site.
|
||||
|
||||
When passing a function on the current stack as the `belowFn` parameter, the
|
||||
returned array will only include `CallSite` objects below this function.
|
||||
|
||||
### stackTrace.parse(err)
|
||||
|
||||
Parses the `err.stack` property of an `Error` object into an array compatible
|
||||
with those returned by `stackTrace.get()`. However, only the following methods
|
||||
are implemented on the returned `CallSite` objects.
|
||||
|
||||
* getTypeName
|
||||
* getFunctionName
|
||||
* getMethodName
|
||||
* getFileName
|
||||
* getLineNumber
|
||||
* getColumnNumber
|
||||
* isNative
|
||||
|
||||
Note: Except `getFunctionName()`, all of the above methods return exactly the
|
||||
same values as you would get from `stackTrace.get()`. `getFunctionName()`
|
||||
is sometimes a little different, but still useful.
|
||||
|
||||
### CallSite
|
||||
|
||||
The official v8 CallSite object API can be found [here][https://github.com/v8/v8/wiki/Stack-Trace-API#customizing-stack-traces]. A quick
|
||||
excerpt:
|
||||
|
||||
> A CallSite object defines the following methods:
|
||||
>
|
||||
> * **getThis**: returns the value of this
|
||||
> * **getTypeName**: returns the type of this as a string. This is the name of the function stored in the constructor field of this, if available, otherwise the object's [[Class]] internal property.
|
||||
> * **getFunction**: returns the current function
|
||||
> * **getFunctionName**: returns the name of the current function, typically its name property. If a name property is not available an attempt will be made to try to infer a name from the function's context.
|
||||
> * **getMethodName**: returns the name of the property of this or one of its prototypes that holds the current function
|
||||
> * **getFileName**: if this function was defined in a script returns the name of the script
|
||||
> * **getLineNumber**: if this function was defined in a script returns the current line number
|
||||
> * **getColumnNumber**: if this function was defined in a script returns the current column number
|
||||
> * **getEvalOrigin**: if this function was created using a call to eval returns a CallSite object representing the location where eval was called
|
||||
> * **isToplevel**: is this a toplevel invocation, that is, is this the global object?
|
||||
> * **isEval**: does this call take place in code defined by a call to eval?
|
||||
> * **isNative**: is this call in native V8 code?
|
||||
> * **isConstructor**: is this a constructor call?
|
||||
|
||||
[v8stackapi]: https://v8.dev/docs/stack-trace-api
|
||||
|
||||
## License
|
||||
|
||||
stack-trace is licensed under the MIT license.
|
51
node_modules/stack-trace/__tests__/get-test.js
generated
vendored
Normal file
51
node_modules/stack-trace/__tests__/get-test.js
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
import { get } from "../index.js";
|
||||
|
||||
describe("get", () => {
|
||||
test("basic", () => {
|
||||
(function testBasic() {
|
||||
var trace = get();
|
||||
|
||||
//expect(trace[0].getFunction()).toBe(testBasic);
|
||||
expect(trace[0].getFunctionName()).toBe('testBasic');
|
||||
expect(trace[0].getFileName()).toBe(__filename);
|
||||
})();
|
||||
});
|
||||
|
||||
test("wrapper", () => {
|
||||
(function testWrapper() {
|
||||
(function testBelowFn() {
|
||||
var trace = get(testBelowFn);
|
||||
//expect(trace[0].getFunction()).toBe(testWrapper);
|
||||
expect(trace[0].getFunctionName()).toBe('testWrapper');
|
||||
})();
|
||||
})();
|
||||
});
|
||||
|
||||
test("deep", () => {
|
||||
(function deep1() {
|
||||
(function deep2() {
|
||||
(function deep3() {
|
||||
(function deep4() {
|
||||
(function deep5() {
|
||||
(function deep6() {
|
||||
(function deep7() {
|
||||
(function deep8() {
|
||||
(function deep9() {
|
||||
(function deep10() {
|
||||
(function deep10() {
|
||||
const trace = get();
|
||||
const hasFirstCallSite = trace.some(callSite => callSite.getFunctionName() === 'deep1');
|
||||
expect(hasFirstCallSite).toBe(true);
|
||||
})();
|
||||
})();
|
||||
})();
|
||||
})();
|
||||
})();
|
||||
})();
|
||||
})();
|
||||
})();
|
||||
})();
|
||||
})();
|
||||
})();
|
||||
});
|
||||
});
|
22
node_modules/stack-trace/__tests__/long-stack-trace-test.js
generated
vendored
Normal file
22
node_modules/stack-trace/__tests__/long-stack-trace-test.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
import { parse } from "../index.js";
|
||||
const _ = require('long-stack-traces');
|
||||
|
||||
describe("long stack trace", () => {
|
||||
test("basic", (done) => {
|
||||
function badFn() {
|
||||
var err = new Error('oh no');
|
||||
var trace = parse(err);
|
||||
|
||||
for (var i in trace) {
|
||||
var filename = trace[i].getFileName();
|
||||
if (typeof filename === 'string' && filename.match(/-----/)) {
|
||||
done();
|
||||
return;
|
||||
}
|
||||
}
|
||||
expect.fail();
|
||||
}
|
||||
|
||||
setTimeout(badFn, 10);
|
||||
});
|
||||
});
|
204
node_modules/stack-trace/__tests__/parse-test.js
generated
vendored
Normal file
204
node_modules/stack-trace/__tests__/parse-test.js
generated
vendored
Normal file
@@ -0,0 +1,204 @@
|
||||
import { get, parse } from "../index.js";
|
||||
|
||||
describe("parse", () => {
|
||||
test("object in method name", () => {
|
||||
const err = {};
|
||||
err.stack =
|
||||
'Error: Foo\n' +
|
||||
' at [object Object].global.every [as _onTimeout] (/Users/hoitz/develop/test.coffee:36:3)\n' +
|
||||
' at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)\n';
|
||||
|
||||
const trace = parse(err);
|
||||
expect(trace[0].getFileName()).toBe("/Users/hoitz/develop/test.coffee");
|
||||
expect(trace[1].getFileName()).toBe("timers.js");
|
||||
});
|
||||
|
||||
test("basic", () => {
|
||||
(function testBasic() {
|
||||
const err = new Error('something went wrong');
|
||||
const trace = parse(err);
|
||||
|
||||
expect(trace[0].getFileName()).toBe(__filename);
|
||||
expect(trace[0].getFunctionName()).toBe('testBasic');
|
||||
})();
|
||||
});
|
||||
|
||||
test("wrapper", () => {
|
||||
(function testWrapper() {
|
||||
(function testBelowFn() {
|
||||
const err = new Error('something went wrong');
|
||||
const trace = parse(err);
|
||||
expect(trace[0].getFunctionName()).toBe('testBelowFn');
|
||||
expect(trace[1].getFunctionName()).toBe('testWrapper');
|
||||
})();
|
||||
})();
|
||||
});
|
||||
|
||||
test("no stack", () => {
|
||||
const err = { stack: undefined };
|
||||
const trace = parse(err);
|
||||
|
||||
expect(trace).toStrictEqual([]);
|
||||
});
|
||||
|
||||
test("test corrupt stack", () => {
|
||||
const err = {};
|
||||
err.stack =
|
||||
'AssertionError: true == false\n' +
|
||||
' fuck' +
|
||||
' at Test.run (/Users/felix/code/node-fast-or-slow/lib/test.js:45:10)\n' +
|
||||
'oh no' +
|
||||
' at TestCase.run (/Users/felix/code/node-fast-or-slow/lib/test_case.js:61:8)\n';
|
||||
|
||||
const trace = parse(err);
|
||||
expect(trace.length).toBe(2);
|
||||
});
|
||||
|
||||
test("trace braces in path", () => {
|
||||
const err = {};
|
||||
err.stack =
|
||||
'AssertionError: true == false\n' +
|
||||
' at Test.run (/Users/felix (something)/code/node-fast-or-slow/lib/test.js:45:10)\n' +
|
||||
' at TestCase.run (/Users/felix (something)/code/node-fast-or-slow/lib/test_case.js:61:8)\n';
|
||||
|
||||
const trace = parse(err);
|
||||
expect(trace.length).toBe(2);
|
||||
expect(trace[0].getFileName()).toBe('/Users/felix (something)/code/node-fast-or-slow/lib/test.js');
|
||||
});
|
||||
|
||||
test("trace without column numbers", () => {
|
||||
const err = {};
|
||||
err.stack =
|
||||
'AssertionError: true == false\n' +
|
||||
' at Test.fn (/Users/felix/code/node-fast-or-slow/test/fast/example/test-example.js:6)\n' +
|
||||
' at Test.run (/Users/felix/code/node-fast-or-slow/lib/test.js:45)';
|
||||
|
||||
const trace = parse(err);
|
||||
expect(trace[0].getFileName()).toBe("/Users/felix/code/node-fast-or-slow/test/fast/example/test-example.js");
|
||||
expect(trace[0].getLineNumber()).toBe(6);
|
||||
expect(trace[0].getColumnNumber()).toBeNull();
|
||||
});
|
||||
|
||||
test("compare real with parsed stack trace", () => {
|
||||
var realTrace, err;
|
||||
function TestClass() {
|
||||
}
|
||||
TestClass.prototype.testFunc = function () {
|
||||
realTrace = get();
|
||||
err = new Error('something went wrong');
|
||||
}
|
||||
|
||||
var testObj = new TestClass();
|
||||
testObj.testFunc();
|
||||
var parsedTrace = parse(err);
|
||||
|
||||
realTrace.forEach(function(real, i) {
|
||||
var parsed = parsedTrace[i];
|
||||
|
||||
function compare(method, exceptions) {
|
||||
let realValue = real[method]();
|
||||
const parsedValue = parsed[method]();
|
||||
|
||||
if (exceptions && typeof exceptions[i] != 'undefined') {
|
||||
realValue = exceptions[i];
|
||||
}
|
||||
|
||||
//const realJson = JSON.stringify(realValue);
|
||||
//const parsedJson = JSON.stringify(parsedValue);
|
||||
//console.log(method + ': ' + realJson + ' != ' + parsedJson + ' (#' + i + ')');
|
||||
expect(realValue).toBe(parsedValue);
|
||||
}
|
||||
|
||||
compare('getFileName');
|
||||
compare('getFunctionName', {
|
||||
2: 'Object.asyncJestTest',
|
||||
4: 'new Promise'
|
||||
});
|
||||
compare('getTypeName', {
|
||||
7: null
|
||||
});
|
||||
compare('getMethodName', {
|
||||
2: 'asyncJestTest'
|
||||
});
|
||||
compare('getLineNumber', {
|
||||
0: 88,
|
||||
1: 92
|
||||
});
|
||||
compare('getColumnNumber', {
|
||||
0: 13
|
||||
});
|
||||
compare('isNative');
|
||||
});
|
||||
});
|
||||
|
||||
test("stack with native call", () => {
|
||||
const err = {};
|
||||
err.stack =
|
||||
'AssertionError: true == false\n' +
|
||||
' at Test.fn (/Users/felix/code/node-fast-or-slow/test/fast/example/test-example.js:6:10)\n' +
|
||||
' at Test.run (/Users/felix/code/node-fast-or-slow/lib/test.js:45:10)\n' +
|
||||
' at TestCase.runNext (/Users/felix/code/node-fast-or-slow/lib/test_case.js:73:8)\n' +
|
||||
' at TestCase.run (/Users/felix/code/node-fast-or-slow/lib/test_case.js:61:8)\n' +
|
||||
' at Array.0 (native)\n' +
|
||||
' at EventEmitter._tickCallback (node.js:126:26)';
|
||||
|
||||
const trace = parse(err);
|
||||
var nativeCallSite = trace[4];
|
||||
|
||||
expect(nativeCallSite.getFileName()).toBeNull();
|
||||
expect(nativeCallSite.getFunctionName()).toBe('Array.0');
|
||||
expect(nativeCallSite.getTypeName()).toBe('Array');
|
||||
expect(nativeCallSite.getMethodName()).toBe('0');
|
||||
expect(nativeCallSite.getLineNumber()).toBeNull();
|
||||
expect(nativeCallSite.getColumnNumber()).toBeNull();
|
||||
expect(nativeCallSite.isNative()).toBe(true);
|
||||
});
|
||||
|
||||
test("stack with file only", () => {
|
||||
const err = {};
|
||||
err.stack =
|
||||
'AssertionError: true == false\n' +
|
||||
' at /Users/felix/code/node-fast-or-slow/lib/test_case.js:80:10';
|
||||
|
||||
const trace = parse(err);
|
||||
var callSite = trace[0];
|
||||
|
||||
expect(callSite.getFileName()).toBe('/Users/felix/code/node-fast-or-slow/lib/test_case.js');
|
||||
expect(callSite.getFunctionName()).toBeNull();
|
||||
expect(callSite.getTypeName()).toBeNull();
|
||||
expect(callSite.getMethodName()).toBeNull();
|
||||
expect(callSite.getLineNumber()).toBe(80);
|
||||
expect(callSite.getColumnNumber()).toBe(10);
|
||||
expect(callSite.isNative()).toBe(false);
|
||||
});
|
||||
|
||||
test("stack with multiline message", () => {
|
||||
const err = {};
|
||||
err.stack =
|
||||
'AssertionError: true == false\nAnd some more shit\n' +
|
||||
' at /Users/felix/code/node-fast-or-slow/lib/test_case.js:80:10';
|
||||
|
||||
const trace = parse(err);
|
||||
var callSite = trace[0];
|
||||
|
||||
expect(callSite.getFileName()).toBe('/Users/felix/code/node-fast-or-slow/lib/test_case.js');
|
||||
});
|
||||
|
||||
test("stack with anonymous function call", () => {
|
||||
const err = {};
|
||||
err.stack =
|
||||
'AssertionError: expected [] to be arguments\n' +
|
||||
' at Assertion.prop.(anonymous function) (/Users/den/Projects/should.js/lib/should.js:60:14)\n';
|
||||
|
||||
const trace = parse(err);
|
||||
var callSite0 = trace[0];
|
||||
|
||||
expect(callSite0.getFileName()).toBe('/Users/den/Projects/should.js/lib/should.js');
|
||||
expect(callSite0.getFunctionName()).toBe('Assertion.prop.(anonymous function)');
|
||||
expect(callSite0.getTypeName()).toBe("Assertion.prop");
|
||||
expect(callSite0.getMethodName()).toBe("(anonymous function)");
|
||||
expect(callSite0.getLineNumber()).toBe(60);
|
||||
expect(callSite0.getColumnNumber()).toBe(14);
|
||||
expect(callSite0.isNative()).toBe(false);
|
||||
});
|
||||
});
|
136
node_modules/stack-trace/index.js
generated
vendored
Normal file
136
node_modules/stack-trace/index.js
generated
vendored
Normal file
@@ -0,0 +1,136 @@
|
||||
export function get(belowFn) {
|
||||
const oldLimit = Error.stackTraceLimit;
|
||||
Error.stackTraceLimit = Infinity;
|
||||
|
||||
const dummyObject = {};
|
||||
|
||||
const v8Handler = Error.prepareStackTrace;
|
||||
Error.prepareStackTrace = function(dummyObject, v8StackTrace) {
|
||||
return v8StackTrace;
|
||||
};
|
||||
Error.captureStackTrace(dummyObject, belowFn || get);
|
||||
|
||||
const v8StackTrace = dummyObject.stack;
|
||||
Error.prepareStackTrace = v8Handler;
|
||||
Error.stackTraceLimit = oldLimit;
|
||||
|
||||
return v8StackTrace;
|
||||
}
|
||||
|
||||
export function parse(err) {
|
||||
if (!err.stack) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const lines = err.stack.split('\n').slice(1);
|
||||
return lines
|
||||
.map(function(line) {
|
||||
if (line.match(/^\s*[-]{4,}$/)) {
|
||||
return createParsedCallSite({
|
||||
fileName: line,
|
||||
lineNumber: null,
|
||||
functionName: null,
|
||||
typeName: null,
|
||||
methodName: null,
|
||||
columnNumber: null,
|
||||
'native': null,
|
||||
});
|
||||
}
|
||||
|
||||
const lineMatch = line.match(/at (?:(.+?)\s+\()?(?:(.+?):(\d+)(?::(\d+))?|([^)]+))\)?/);
|
||||
if (!lineMatch) {
|
||||
return;
|
||||
}
|
||||
|
||||
let object = null;
|
||||
let method = null;
|
||||
let functionName = null;
|
||||
let typeName = null;
|
||||
let methodName = null;
|
||||
let isNative = (lineMatch[5] === 'native');
|
||||
|
||||
if (lineMatch[1]) {
|
||||
functionName = lineMatch[1];
|
||||
let methodStart = functionName.lastIndexOf('.');
|
||||
if (functionName[methodStart-1] == '.')
|
||||
methodStart--;
|
||||
if (methodStart > 0) {
|
||||
object = functionName.substr(0, methodStart);
|
||||
method = functionName.substr(methodStart + 1);
|
||||
const objectEnd = object.indexOf('.Module');
|
||||
if (objectEnd > 0) {
|
||||
functionName = functionName.substr(objectEnd + 1);
|
||||
object = object.substr(0, objectEnd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (method) {
|
||||
typeName = object;
|
||||
methodName = method;
|
||||
}
|
||||
|
||||
if (method === '<anonymous>') {
|
||||
methodName = null;
|
||||
functionName = null;
|
||||
}
|
||||
|
||||
const properties = {
|
||||
fileName: lineMatch[2] || null,
|
||||
lineNumber: parseInt(lineMatch[3], 10) || null,
|
||||
functionName: functionName,
|
||||
typeName: typeName,
|
||||
methodName: methodName,
|
||||
columnNumber: parseInt(lineMatch[4], 10) || null,
|
||||
'native': isNative,
|
||||
};
|
||||
|
||||
return createParsedCallSite(properties);
|
||||
})
|
||||
.filter(function(callSite) {
|
||||
return !!callSite;
|
||||
});
|
||||
}
|
||||
|
||||
function CallSite(properties) {
|
||||
for (const property in properties) {
|
||||
this[property] = properties[property];
|
||||
}
|
||||
}
|
||||
|
||||
const strProperties = [
|
||||
'this',
|
||||
'typeName',
|
||||
'functionName',
|
||||
'methodName',
|
||||
'fileName',
|
||||
'lineNumber',
|
||||
'columnNumber',
|
||||
'function',
|
||||
'evalOrigin'
|
||||
];
|
||||
|
||||
const boolProperties = [
|
||||
'topLevel',
|
||||
'eval',
|
||||
'native',
|
||||
'constructor'
|
||||
];
|
||||
|
||||
strProperties.forEach(function (property) {
|
||||
CallSite.prototype[property] = null;
|
||||
CallSite.prototype['get' + property[0].toUpperCase() + property.substr(1)] = function () {
|
||||
return this[property];
|
||||
}
|
||||
});
|
||||
|
||||
boolProperties.forEach(function (property) {
|
||||
CallSite.prototype[property] = false;
|
||||
CallSite.prototype['is' + property[0].toUpperCase() + property.substr(1)] = function () {
|
||||
return this[property];
|
||||
}
|
||||
});
|
||||
|
||||
function createParsedCallSite(properties) {
|
||||
return new CallSite(properties);
|
||||
}
|
37
node_modules/stack-trace/package.json
generated
vendored
Normal file
37
node_modules/stack-trace/package.json
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"author": "Felix Geisendörfer <felix@debuggable.com> (http://debuggable.com/)",
|
||||
"name": "stack-trace",
|
||||
"description": "Get v8 stack traces as an array of CallSite objects.",
|
||||
"version": "1.0.0-pre2",
|
||||
"homepage": "https://github.com/felixge/node-stack-trace",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/felixge/node-stack-trace.git"
|
||||
},
|
||||
"type": "module",
|
||||
"main": "index.js",
|
||||
"exports": {
|
||||
".": "./index.js",
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"jest": {
|
||||
"testEnvironment": "node",
|
||||
"transform": {
|
||||
"^.+\\.js$": "babel-jest"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"test": "jest",
|
||||
"release": "git push && git push --tags && npm publish"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16"
|
||||
},
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@babel/preset-env": "^7.14.1",
|
||||
"babel-jest": "^26.6.3",
|
||||
"jest": "^26.6.3",
|
||||
"long-stack-traces": "0.1.2"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user