mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-12 19:59:02 +08:00
Merge pull request #22010 from GrabCAD/master
Add types for Error.prepareStackTrace()
This commit is contained in:
84
types/node/v7/index.d.ts
vendored
84
types/node/v7/index.d.ts
vendored
@@ -32,8 +32,18 @@ interface Error {
|
||||
stack?: string;
|
||||
}
|
||||
|
||||
// Declare "static" methods in Error
|
||||
interface ErrorConstructor {
|
||||
/** Create .stack property on a target object */
|
||||
captureStackTrace(targetObject: Object, constructorOpt?: Function): void;
|
||||
|
||||
/**
|
||||
* Optional override for formatting stack traces
|
||||
*
|
||||
* @see https://github.com/v8/v8/wiki/Stack%20Trace%20API#customizing-stack-traces
|
||||
*/
|
||||
prepareStackTrace?: (err: Error, stackTraces: NodeJS.CallSite[]) => any;
|
||||
|
||||
stackTraceLimit: number;
|
||||
}
|
||||
|
||||
@@ -270,6 +280,80 @@ declare namespace NodeJS {
|
||||
new(stdout: WritableStream, stderr?: WritableStream): Console;
|
||||
}
|
||||
|
||||
export interface CallSite {
|
||||
/**
|
||||
* Value of "this"
|
||||
*/
|
||||
getThis(): any;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
getTypeName(): string | null;
|
||||
|
||||
/**
|
||||
* Current function
|
||||
*/
|
||||
getFunction(): Function | undefined;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
getFunctionName(): string | null;
|
||||
|
||||
/**
|
||||
* Name of the property [of "this" or one of its prototypes] that holds
|
||||
* the current function
|
||||
*/
|
||||
getMethodName(): string | null;
|
||||
|
||||
/**
|
||||
* Name of the script [if this function was defined in a script]
|
||||
*/
|
||||
getFileName(): string | null;
|
||||
|
||||
/**
|
||||
* Current line number [if this function was defined in a script]
|
||||
*/
|
||||
getLineNumber(): number | null;
|
||||
|
||||
/**
|
||||
* Current column number [if this function was defined in a script]
|
||||
*/
|
||||
getColumnNumber(): number | null;
|
||||
|
||||
/**
|
||||
* A call site object representing the location where eval was called
|
||||
* [if this function was created using a call to eval]
|
||||
*/
|
||||
getEvalOrigin(): string | undefined;
|
||||
|
||||
/**
|
||||
* Is this a toplevel invocation, that is, is "this" the global object?
|
||||
*/
|
||||
isToplevel(): boolean;
|
||||
|
||||
/**
|
||||
* Does this call take place in code defined by a call to eval?
|
||||
*/
|
||||
isEval(): boolean;
|
||||
|
||||
/**
|
||||
* Is this call in native V8 code?
|
||||
*/
|
||||
isNative(): boolean;
|
||||
|
||||
/**
|
||||
* Is this a constructor call?
|
||||
*/
|
||||
isConstructor(): boolean;
|
||||
}
|
||||
|
||||
export interface ErrnoException extends Error {
|
||||
errno?: number;
|
||||
code?: string;
|
||||
|
||||
@@ -1945,6 +1945,26 @@ namespace errors_tests {
|
||||
const myObject = {};
|
||||
Error.captureStackTrace(myObject);
|
||||
}
|
||||
{
|
||||
let frames: NodeJS.CallSite[] = [];
|
||||
Error.prepareStackTrace(new Error(), frames);
|
||||
}
|
||||
{
|
||||
let frame: NodeJS.CallSite = null;
|
||||
let frameThis: any = frame.getThis();
|
||||
let typeName: string = frame.getTypeName();
|
||||
let func: Function = frame.getFunction();
|
||||
let funcName: string = frame.getFunctionName();
|
||||
let meth: string = frame.getMethodName();
|
||||
let fname: string = frame.getFileName();
|
||||
let lineno: number = frame.getLineNumber();
|
||||
let colno: number = frame.getColumnNumber();
|
||||
let evalOrigin: string = frame.getEvalOrigin();
|
||||
let isTop: boolean = frame.isToplevel();
|
||||
let isEval: boolean = frame.isEval();
|
||||
let isNative: boolean = frame.isNative();
|
||||
let isConstr: boolean = frame.isConstructor();
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user