pad_utils: New warnWithStack()
function
This commit is contained in:
parent
1bbe0d9215
commit
eae814f5a0
1 changed files with 19 additions and 0 deletions
|
@ -89,6 +89,25 @@ const urlRegex = (() => {
|
|||
})();
|
||||
|
||||
const padutils = {
|
||||
/**
|
||||
* Prints a warning message followed by a stack trace (to make it easier to figure out what code
|
||||
* is using the deprecated function).
|
||||
*
|
||||
* Most browsers include UI widget to examine the stack at the time of the warning, but this
|
||||
* includes the stack in the log message for a couple of reasons:
|
||||
* - This makes it possible to see the stack if the code runs in Node.js.
|
||||
* - Users are more likely to paste the stack in bug reports they might file.
|
||||
*
|
||||
* @param {...*} args - Passed to `console.warn`, with a stack trace appended.
|
||||
*/
|
||||
warnWithStack: (...args) => {
|
||||
const err = new Error();
|
||||
if (Error.captureStackTrace) Error.captureStackTrace(err, padutils.warnWithStack);
|
||||
err.name = '';
|
||||
if (err.stack) args.push(err.stack);
|
||||
console.warn(...args);
|
||||
},
|
||||
|
||||
escapeHtml: (x) => Security.escapeHTML(String(x)),
|
||||
uniqueId: () => {
|
||||
const pad = require('./pad').pad; // Sidestep circular dependency
|
||||
|
|
Loading…
Reference in a new issue