温馨提示:本站仅提供公开网络链接索引服务,不存储、不篡改任何第三方内容,所有内容版权归原作者所有
AI智能索引来源:http://www.bun.com/reference/node/util/getCallSites
点击访问原文链接

Node util.getCallSites function | API Reference | Bun

Node util.getCallSites function | API Reference | BunBuildDocsReferenceGuidesBlogDiscord/node:util/getCallSitesFgetCallSites

Search the reference...

/

BuildDocsReferenceGuidesBlogDiscord/node:util/getCallSitesFgetCallSites

function

util.getCallSites { console.log(`CallSite ${index + 1}:`); console.log(`Function Name: ${callSite.functionName}`); console.log(`Script Name: ${callSite.scriptName}`); console.log(`Line Number: ${callSite.lineNumber}`); console.log(`Column Number: ${callSite.columnNumber}`); }); // CallSite 1: // Function Name: exampleFunction // Script Name: /home/example.js // Line Number: 5 // Column Number: 26 // CallSite 2: // Function Name: anotherFunction // Script Name: /home/example.js // Line Number: 22 // Column Number: 3 // ... } // A function to simulate another stack layer function anotherFunction() { exampleFunction(); } anotherFunction(); ``` It is possible to reconstruct the original locations by setting the option `sourceMap` to `true`. If the source map is not available, the original location will be the same as the current location. When the `--enable-source-maps` flag is enabled, for example when using `--experimental-transform-types`, `sourceMap` will be true by default. ```ts import { getCallSites } from 'node:util'; interface Foo { foo: string; } const callSites = getCallSites({ sourceMap: true }); // With sourceMap: // Function Name: '' // Script Name: example.js // Line Number: 7 // Column Number: 26 // Without sourceMap: // Function Name: '' // Script Name: example.js // Line Number: 2 // Column Number: 26 ```" data-algolia-static="false" data-algolia-merged="false" data-type="Function">function getCallSites(frameCount?: number,options?: GetCallSitesOptions): CallSiteObject[];

Returns an array of call site objects containing the stack of the caller function.

Unlike accessing an error.stack, the result returned from this API is not interfered with Error.prepareStackTrace.

import { getCallSites } from 'node:util';

function exampleFunction() {
const callSites = getCallSites();

console.log('Call Sites:');
callSites.forEach((callSite, index) => {
console.log(`CallSite ${index + 1}:`);
console.log(`Function Name: ${callSite.functionName}`);
console.log(`Script Name: ${callSite.scriptName}`);
console.log(`Line Number: ${callSite.lineNumber}`);
console.log(`Column Number: ${callSite.columnNumber}`);
});
// CallSite 1:
// Function Name: exampleFunction
// Script Name: /home/example.js
// Line Number: 5
// Column Number: 26

// CallSite 2:
// Function Name: anotherFunction
// Script Name: /home/example.js
// Line Number: 22
// Column Number: 3

// ...
}

// A function to simulate another stack layer
function anotherFunction() {
exampleFunction();
}

anotherFunction();

It is possible to reconstruct the original locations by setting the option sourceMap to true. If the source map is not available, the original location will be the same as the current location. When the --enable-source-maps flag is enabled, for example when using --experimental-transform-types, sourceMap will be true by default.

import { getCallSites } from 'node:util';

interface Foo {
foo: string;
}

const callSites = getCallSites({ sourceMap: true });

// With sourceMap:
// Function Name: ''
// Script Name: example.js
// Line Number: 7
// Column Number: 26

// Without sourceMap:
// Function Name: ''
// Script Name: example.js
// Line Number: 2
// Column Number: 26
@param frameCount

Number of frames to capture as call site objects. Default: 10. Allowable range is between 1 and 200.

@returns

An array of call site objects

function getCallSites(options: GetCallSitesOptions): CallSiteObject[];

Returns an array of call site objects containing the stack of the caller function.

Unlike accessing an error.stack, the result returned from this API is not interfered with Error.prepareStackTrace.

import { getCallSites } from 'node:util';

function exampleFunction() {
const callSites = getCallSites();

console.log('Call Sites:');
callSites.forEach((callSite, index) => {
console.log(`CallSite ${index + 1}:`);
console.log(`Function Name: ${callSite.functionName}`);
console.log(`Script Name: ${callSite.scriptName}`);
console.log(`Line Number: ${callSite.lineNumber}`);
console.log(`Column Number: ${callSite.columnNumber}`);
});
// CallSite 1:
// Function Name: exampleFunction
// Script Name: /home/example.js
// Line Number: 5
// Column Number: 26

// CallSite 2:
// Function Name: anotherFunction
// Script Name: /home/example.js
// Line Number: 22
// Column Number: 3

// ...
}

// A function to simulate another stack layer
function anotherFunction() {
exampleFunction();
}

anotherFunction();

It is possible to reconstruct the original locations by setting the option sourceMap to true. If the source map is not available, the original location will be the same as the current location. When the --enable-source-maps flag is enabled, for example when using --experimental-transform-types, sourceMap will be true by default.

import { getCallSites } from 'node:util';

interface Foo {
foo: string;
}

const callSites = getCallSites({ sourceMap: true });

// With sourceMap:
// Function Name: ''
// Script Name: example.js
// Line Number: 7
// Column Number: 26

// Without sourceMap:
// Function Name: ''
// Script Name: example.js
// Line Number: 2
// Column Number: 26
@returns

An array of call site objects

Referenced typesinterface GetCallSitesOptionssourceMap?: boolean

Reconstruct the original location in the stacktrace from the source-map. Enabled by default with the flag --enable-source-maps.

interface CallSiteObjectcolumnNumber: number

Returns the 1-based column offset on the line for the associated function call.

functionName: string

Returns the name of the function associated with this call site.

lineNumber: number

Returns the number, 1-based, of the line for the associate function call.

scriptId: string

Returns the unique id of the script, as in Chrome DevTools protocol Runtime.ScriptId.

scriptName: string

Returns the name of the resource that contains the script for the function for this call site.

Resources

ReferenceDocsGuidesDiscordMerch StoreGitHubBlog 

Toolkit

RuntimePackage managerTest runnerBundlerPackage runner

Project

Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicense

Baked with ❤️ in San Francisco

We're hiring →

Node util.getCallSites function | API Reference | Bun,AI智能索引,全网链接索引,智能导航,网页索引

    API documentation for function node:util.getCallSites | Bun