Skip to content

Commit 1238f0a

Browse files
authored
util: rename CallSite.column to columnNumber
Align the property names `lineNumber` and `columnNumber`. PR-URL: nodejs#56584 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 97caa4c commit 1238f0a

File tree

5 files changed

+17
-5
lines changed

5 files changed

+17
-5
lines changed

doc/api/util.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,9 @@ util.formatWithOptions({ colors: true }, 'See object %O', { foo: 42 });
371371
<!-- YAML
372372
added: v22.9.0
373373
changes:
374+
- version: REPLACEME
375+
pr-url: https://github.com/nodejs/node/pull/56584
376+
description: Property `column` is deprecated in favor of `columnNumber`.
374377
- version: REPLACEME
375378
pr-url: https://github.com/nodejs/node/pull/56551
376379
description: Property `CallSite.scriptId` is exposed.
@@ -391,8 +394,8 @@ changes:
391394
* `scriptName` {string} Returns the name of the resource that contains the script for the
392395
function for this call site.
393396
* `scriptId` {string} Returns the unique id of the script, as in Chrome DevTools protocol [`Runtime.ScriptId`][].
394-
* `lineNumber` {number} Returns the number, 1-based, of the line for the associate function call.
395-
* `column` {number} Returns the 1-based column offset on the line for the associated function call.
397+
* `lineNumber` {number} Returns the JavaScript script line number (1-based).
398+
* `columnNumber` {number} Returns the JavaScript script column number (1-based).
396399

397400
Returns an array of call site objects containing the stack of
398401
the caller function.
@@ -409,7 +412,7 @@ function exampleFunction() {
409412
console.log(`Function Name: ${callSite.functionName}`);
410413
console.log(`Script Name: ${callSite.scriptName}`);
411414
console.log(`Line Number: ${callSite.lineNumber}`);
412-
console.log(`Column Number: ${callSite.column}`);
415+
console.log(`Column Number: ${callSite.columnNumber}`);
413416
});
414417
// CallSite 1:
415418
// Function Name: exampleFunction

lib/util.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,10 @@ const lazySourceMap = getLazy(() => require('internal/source_map/source_map_cach
348348
* @returns {CallSite | undefined} // The reconstructed call site object
349349
*/
350350
function reconstructCallSite(callSite) {
351-
const { scriptName, lineNumber, column } = callSite;
351+
const { scriptName, lineNumber, columnNumber } = callSite;
352352
const sourceMap = lazySourceMap().findSourceMap(scriptName);
353353
if (!sourceMap) return;
354-
const entry = sourceMap.findEntry(lineNumber - 1, column - 1);
354+
const entry = sourceMap.findEntry(lineNumber - 1, columnNumber - 1);
355355
if (!entry?.originalSource) return;
356356
return {
357357
__proto__: null,
@@ -360,6 +360,7 @@ function reconstructCallSite(callSite) {
360360
scriptName: entry.originalSource,
361361
lineNumber: entry.originalLine + 1,
362362
column: entry.originalColumn + 1,
363+
columnNumber: entry.originalColumn + 1,
363364
};
364365
}
365366

src/env_properties.h

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
"transferList") \
100100
V(clone_untransferable_str, "Found invalid value in transferList.") \
101101
V(code_string, "code") \
102+
V(column_number_string, "columnNumber") \
102103
V(column_string, "column") \
103104
V(commonjs_string, "commonjs") \
104105
V(config_string, "config") \

src/node_util.cc

+4
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ static void GetCallSites(const FunctionCallbackInfo<Value>& args) {
282282
env->script_id_string(),
283283
env->script_name_string(),
284284
env->line_number_string(),
285+
env->column_number_string(),
286+
// TODO(legendecas): deprecate CallSite.column.
285287
env->column_string(),
286288
};
287289
Local<Value> values[] = {
@@ -290,6 +292,8 @@ static void GetCallSites(const FunctionCallbackInfo<Value>& args) {
290292
script_name,
291293
Integer::NewFromUnsigned(isolate, stack_frame->GetLineNumber()),
292294
Integer::NewFromUnsigned(isolate, stack_frame->GetColumn()),
295+
// TODO(legendecas): deprecate CallSite.column.
296+
Integer::NewFromUnsigned(isolate, stack_frame->GetColumn()),
293297
};
294298
Local<Object> obj = Object::New(
295299
isolate, v8::Null(isolate), names, values, arraysize(names));

test/parallel/test-util-getcallsites.js

+3
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ const assert = require('node:assert');
133133
assert.strictEqual(stderr.toString(), '');
134134
assert.match(output, /lineNumber: 8/);
135135
assert.match(output, /column: 18/);
136+
assert.match(output, /columnNumber: 18/);
136137
assert.match(output, /test-get-callsite\.ts/);
137138
assert.strictEqual(status, 0);
138139
}
@@ -150,6 +151,7 @@ const assert = require('node:assert');
150151
// Line should be wrong when sourcemaps are disable
151152
assert.match(output, /lineNumber: 2/);
152153
assert.match(output, /column: 18/);
154+
assert.match(output, /columnNumber: 18/);
153155
assert.match(output, /test-get-callsite\.ts/);
154156
assert.strictEqual(status, 0);
155157
}
@@ -166,6 +168,7 @@ const assert = require('node:assert');
166168
assert.strictEqual(stderr.toString(), '');
167169
assert.match(output, /lineNumber: 2/);
168170
assert.match(output, /column: 18/);
171+
assert.match(output, /columnNumber: 18/);
169172
assert.match(output, /test-get-callsite-explicit\.ts/);
170173
assert.strictEqual(status, 0);
171174
}

0 commit comments

Comments
 (0)