mirror of
https://github.com/nodejs/node.git
synced 2025-05-06 21:35:34 +00:00

Move the method that was added in commit 8ca412b
from earlier this month
from lib/util.js to lib/internal/util.js.
Avoids exposing a method that we may not wish to expose just yet, seeing
how it relies on implementation details.
PR-URL: https://github.com/nodejs/node/pull/4026
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
37 lines
987 B
JavaScript
37 lines
987 B
JavaScript
// Flags: --expose_internals
|
|
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const internalUtil = require('internal/util');
|
|
|
|
assert.doesNotThrow(function() {
|
|
internalUtil.decorateErrorStack();
|
|
internalUtil.decorateErrorStack(null);
|
|
internalUtil.decorateErrorStack(1);
|
|
internalUtil.decorateErrorStack(true);
|
|
});
|
|
|
|
// Verify that a stack property is not added to non-Errors
|
|
const obj = {};
|
|
internalUtil.decorateErrorStack(obj);
|
|
assert.strictEqual(obj.stack, undefined);
|
|
|
|
// Verify that the stack is decorated when possible
|
|
let err;
|
|
|
|
try {
|
|
require('../fixtures/syntax/bad_syntax');
|
|
} catch (e) {
|
|
err = e;
|
|
assert(!/var foo bar;/.test(err.stack));
|
|
internalUtil.decorateErrorStack(err);
|
|
}
|
|
|
|
assert(/var foo bar;/.test(err.stack));
|
|
|
|
// Verify that the stack is unchanged when there is no arrow message
|
|
err = new Error('foo');
|
|
const originalStack = err.stack;
|
|
internalUtil.decorateErrorStack(err);
|
|
assert.strictEqual(originalStack, err.stack);
|