@@ -177,22 +177,29 @@ 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) {
181- JSG_REQUIRE (
182- frames >= 1 && frames <= 200 , Error, " Frame count should be between 1 and 200 inclusive." _kj);
183- auto stack = v8::StackTrace::CurrentStackTrace (js.v8Isolate , frames + 1 );
180+ kj::Array<UtilModule::CallSiteEntry> UtilModule::getCallSites (
181+ jsg::Lock& js, jsg::Optional<int > frames) {
182+ KJ_IF_SOME (f, frames) {
183+ JSG_REQUIRE (f >= 1 && f <= 200 , Error, " Frame count should be between 1 and 200 inclusive." _kj);
184+ }
185+
186+ auto stack = v8::StackTrace::CurrentStackTrace (js.v8Isolate , frames.orDefault (10 ) + 1 );
184187 const int frameCount = stack->GetFrameCount ();
185188 auto objects = kj::Vector<CallSiteEntry>();
186189 objects.reserve (frameCount - 1 );
187190
188- // Frame 0 is node:util. It should be skipped.
189- for (int i = 1 ; i < frameCount; ++i) {
191+ for (int i = 0 ; i < frameCount; ++i) {
190192 auto stack_frame = stack->GetFrame (js.v8Isolate , i);
191193
192194 objects.add (CallSiteEntry{
193195 .functionName = js.toString (stack_frame->GetFunctionName ()),
194196 .scriptName = js.toString (stack_frame->GetScriptName ()),
195197 .lineNumber = stack_frame->GetLineNumber (),
198+ // Node.js originally implemented the experimental API using the "column" field
199+ // then later renamed it to columnNumber. We had already implemented the API
200+ // using column. To ensure backwards compat without the complexity of a compat
201+ // flag, we just export both.
202+ .columnNumber = stack_frame->GetColumn (),
196203 .column = stack_frame->GetColumn (),
197204 });
198205 }
0 commit comments