Skip to content

Commit

Permalink
update util.getCallSites() implementation to follow node.js
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Jan 21, 2025
1 parent b982f8b commit 98fbf99
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/workerd/api/node/tests/util-nodejs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4343,15 +4343,15 @@ export const debuglog = {
},
};

export const getCallSiteTest = {
export const getCallSitesTest = {
test() {
const callSites = util.getCallSite();
const callSites = util.getCallSites();
assert.strictEqual(callSites.length, 1);
const [stack] = callSites;
assert.strictEqual(stack.functionName, 'test');
assert.strictEqual(stack.scriptName, 'worker');
assert.strictEqual(typeof stack.lineNumber, 'number');
assert.strictEqual(typeof stack.column, 'number');
assert.strictEqual(typeof stack.columnNumber, 'number');
},
};

Expand Down
4 changes: 2 additions & 2 deletions src/workerd/api/node/util.c++
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ jsg::Name UtilModule::getResourceTypeInspect(jsg::Lock& js) {
return js.newApiSymbol("kResourceTypeInspect"_kj);
}

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

Expand Down
4 changes: 2 additions & 2 deletions src/workerd/api/node/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,11 @@ class UtilModule final: public jsg::Object {
kj::String functionName;
kj::String scriptName;
int lineNumber;
int column;
int columnNumber;

JSG_STRUCT(functionName, scriptName, lineNumber, column);
};
kj::Array<CallSiteEntry> getCallSite(jsg::Lock& js, int frames);
kj::Array<CallSiteEntry> getCallSites(jsg::Lock& js, int frames);

#define V(Type) bool is##Type(jsg::JsValue value);
JS_UTIL_IS_TYPES(V)
Expand Down

0 comments on commit 98fbf99

Please # to comment.