Skip to content

Commit db0eb48

Browse files
committed
update util.getCallSites() implementation to follow node.js
1 parent b982f8b commit db0eb48

5 files changed

Lines changed: 18 additions & 10 deletions

File tree

src/node/internal/util.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,6 @@ export function isBoxedPrimitive(
121121
): value is number | string | boolean | bigint | symbol;
122122

123123
export function getBuiltinModule(id: string): any;
124-
export function getCallSite(frames: number): Record<string, string>[];
124+
export function getCallSites(frames: number): Record<string, string>[];
125125
export function processExitImpl(code: number): void;
126126
export const processPlatform: string;

src/node/util.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,13 @@ export function deprecate(
206206
return fn;
207207
}
208208

209-
export function getCallSite(frames: number = 10) {
210-
return utilImpl.getCallSite(frames);
209+
// We leave this implementation for compat reasons.
210+
export function getCallSite(frames: number = 10): Record<string, string>[] {
211+
return utilImpl.getCallSites(frames);
212+
}
213+
214+
export function getCallSites(frames: number = 10): Record<string, string>[] {
215+
return utilImpl.getCallSites(frames);
211216
}
212217

213218
export function isDeepStrictEqual(a: unknown, b: unknown): boolean {

src/workerd/api/node/tests/util-nodejs-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4343,15 +4343,15 @@ export const debuglog = {
43434343
},
43444344
};
43454345

4346-
export const getCallSiteTest = {
4346+
export const getCallSitesTest = {
43474347
test() {
4348-
const callSites = util.getCallSite();
4348+
const callSites = util.getCallSites();
43494349
assert.strictEqual(callSites.length, 1);
43504350
const [stack] = callSites;
43514351
assert.strictEqual(stack.functionName, 'test');
43524352
assert.strictEqual(stack.scriptName, 'worker');
43534353
assert.strictEqual(typeof stack.lineNumber, 'number');
4354-
assert.strictEqual(typeof stack.column, 'number');
4354+
assert.strictEqual(typeof stack.columnNumber, 'number');
43554355
},
43564356
};
43574357

src/workerd/api/node/util.c++

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ jsg::Name UtilModule::getResourceTypeInspect(jsg::Lock& js) {
177177
return js.newApiSymbol("kResourceTypeInspect"_kj);
178178
}
179179

180-
kj::Array<UtilModule::CallSiteEntry> UtilModule::getCallSite(jsg::Lock& js, int frames) {
180+
kj::Array<UtilModule::CallSiteEntry> UtilModule::getCallSites(jsg::Lock& js, int frames) {
181181
JSG_REQUIRE(
182182
frames >= 1 && frames <= 200, Error, "Frame count should be between 1 and 200 inclusive."_kj);
183183
auto stack = v8::StackTrace::CurrentStackTrace(js.v8Isolate, frames + 1);
@@ -193,6 +193,7 @@ kj::Array<UtilModule::CallSiteEntry> UtilModule::getCallSite(jsg::Lock& js, int
193193
.functionName = js.toString(stack_frame->GetFunctionName()),
194194
.scriptName = js.toString(stack_frame->GetScriptName()),
195195
.lineNumber = stack_frame->GetLineNumber(),
196+
.columnNumber = stack_frame->GetColumn(),
196197
.column = stack_frame->GetColumn(),
197198
});
198199
}

src/workerd/api/node/util.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,13 @@ class UtilModule final: public jsg::Object {
212212
kj::String functionName;
213213
kj::String scriptName;
214214
int lineNumber;
215+
// We define column and columnNumber at the same time for compat reasons.
216+
int columnNumber;
215217
int column;
216218

217-
JSG_STRUCT(functionName, scriptName, lineNumber, column);
219+
JSG_STRUCT(functionName, scriptName, lineNumber, columnNumber, column);
218220
};
219-
kj::Array<CallSiteEntry> getCallSite(jsg::Lock& js, int frames);
221+
kj::Array<CallSiteEntry> getCallSites(jsg::Lock& js, int frames);
220222

221223
#define V(Type) bool is##Type(jsg::JsValue value);
222224
JS_UTIL_IS_TYPES(V)
@@ -257,7 +259,7 @@ class UtilModule final: public jsg::Object {
257259
JSG_METHOD(getProxyDetails);
258260
JSG_METHOD(previewEntries);
259261
JSG_METHOD(getConstructorName);
260-
JSG_METHOD(getCallSite);
262+
JSG_METHOD(getCallSites);
261263

262264
#define V(Type) JSG_METHOD(is##Type);
263265
JS_UTIL_IS_TYPES(V)

0 commit comments

Comments
 (0)