Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: remove getCallSite from common #54947

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions test/common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,6 @@ Returns an instance of all possible `ArrayBufferView`s of the provided Buffer.
Returns an instance of all possible `BufferSource`s of the provided Buffer,
consisting of all `ArrayBufferView` and an `ArrayBuffer`.

### `getCallSite(func)`

* `func` [\<Function>][<Function>]
* return [\<string>][<string>]

Returns the file name and line number for the provided Function.

### `getTTYfd()`

Attempts to get a valid TTY file descriptor. Returns `-1` if it fails.
Expand Down
19 changes: 3 additions & 16 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const net = require('net');
// Do not require 'os' until needed so that test-os-checked-function can
// monkey patch it. If 'os' is required here, that test will fail.
const path = require('path');
const { inspect } = require('util');
const { inspect, getCallSite } = require('util');
const { isMainThread } = require('worker_threads');
const { isModuleNamespaceObject } = require('util/types');

Expand Down Expand Up @@ -551,25 +551,13 @@ function canCreateSymLink() {
return true;
}

function getCallSite(top) {
const originalStackFormatter = Error.prepareStackTrace;
Error.prepareStackTrace = (err, stack) =>
`${stack[0].getFileName()}:${stack[0].getLineNumber()}`;
const err = new Error();
Error.captureStackTrace(err, top);
// With the V8 Error API, the stack is not formatted until it is accessed
err.stack; // eslint-disable-line no-unused-expressions
Error.prepareStackTrace = originalStackFormatter;
return err.stack;
}

function mustNotCall(msg) {
const callSite = getCallSite(mustNotCall);
const callSite = getCallSite()[1];
return function mustNotCall(...args) {
const argsInfo = args.length > 0 ?
`\ncalled with arguments: ${args.map((arg) => inspect(arg)).join(', ')}` : '';
assert.fail(
`${msg || 'function should not have been called'} at ${callSite}` +
`${msg || 'function should not have been called'} at ${callSite.scriptName}:${callSite.lineNumber}` +
RedYetiDev marked this conversation as resolved.
Show resolved Hide resolved
argsInfo);
};
}
Expand Down Expand Up @@ -968,7 +956,6 @@ const common = {
expectWarning,
getArrayBufferViews,
getBufferSources,
getCallSite,
getPrintedStackTrace,
getTTYfd,
hasIntl,
Expand Down
2 changes: 0 additions & 2 deletions test/common/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const {
expectWarning,
getArrayBufferViews,
getBufferSources,
getCallSite,
getTTYfd,
hasCrypto,
hasIntl,
Expand Down Expand Up @@ -69,7 +68,6 @@ export {
expectWarning,
getArrayBufferViews,
getBufferSources,
getCallSite,
getPort,
getTTYfd,
hasCrypto,
Expand Down
Loading