Skip to content

Commit c7f1619

Browse files
legendecasaduh95
authored andcommitted
util: rename CallSite.column to columnNumber
Align the property names `lineNumber` and `columnNumber`. PR-URL: #56584 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 27cfec6 commit c7f1619

File tree

5 files changed

+17
-5
lines changed

5 files changed

+17
-5
lines changed

doc/api/util.md

Lines changed: 6 additions & 3 deletions
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.
@@ -389,8 +392,8 @@ changes:
389392
* `scriptName` {string} Returns the name of the resource that contains the script for the
390393
function for this call site.
391394
* `scriptId` {string} Returns the unique id of the script, as in Chrome DevTools protocol [`Runtime.ScriptId`][].
392-
* `lineNumber` {number} Returns the number, 1-based, of the line for the associate function call.
393-
* `column` {number} Returns the 1-based column offset on the line for the associated function call.
395+
* `lineNumber` {number} Returns the JavaScript script line number (1-based).
396+
* `columnNumber` {number} Returns the JavaScript script column number (1-based).
394397

395398
Returns an array of call site objects containing the stack of
396399
the caller function.
@@ -407,7 +410,7 @@ function exampleFunction() {
407410
console.log(`Function Name: ${callSite.functionName}`);
408411
console.log(`Script Name: ${callSite.scriptName}`);
409412
console.log(`Line Number: ${callSite.lineNumber}`);
410-
console.log(`Column Number: ${callSite.column}`);
413+
console.log(`Column Number: ${callSite.columnNumber}`);
411414
});
412415
// CallSite 1:
413416
// Function Name: exampleFunction

lib/util.js

Lines changed: 3 additions & 2 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy