aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2015-11-24 19:52:35 -0500
committercjihrig <cjihrig@gmail.com>2015-11-25 13:28:06 -0500
commit8ca412b7a3d5e6e84441bc846c5f42e8dcd2f1b9 (patch)
treefe3e78fb167ad5dd8d8248d0290907450496b269 /test
parent16db4c4d5e79f44e6c974041c40cecb3cd96b78d (diff)
downloadandroid-node-v8-8ca412b7a3d5e6e84441bc846c5f42e8dcd2f1b9.tar.gz
android-node-v8-8ca412b7a3d5e6e84441bc846c5f42e8dcd2f1b9.tar.bz2
android-node-v8-8ca412b7a3d5e6e84441bc846c5f42e8dcd2f1b9.zip
util: add decorateErrorStack()
This commit adds the decorateErrorStack() method. This function uses the internal util's getHiddenValue() method to extract arrow messages from error objects and attach them to the error's stack trace. PR-URL: https://github.com/nodejs/node/pull/4013 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-util-decorate-error-stack.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/test/parallel/test-util-decorate-error-stack.js b/test/parallel/test-util-decorate-error-stack.js
new file mode 100644
index 0000000000..b609ee3372
--- /dev/null
+++ b/test/parallel/test-util-decorate-error-stack.js
@@ -0,0 +1,35 @@
+'use strict';
+const common = require('../common');
+const assert = require('assert');
+const util = require('util');
+
+assert.doesNotThrow(function() {
+ util.decorateErrorStack();
+ util.decorateErrorStack(null);
+ util.decorateErrorStack(1);
+ util.decorateErrorStack(true);
+});
+
+// Verify that a stack property is not added to non-Errors
+const obj = {};
+util.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));
+ util.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;
+util.decorateErrorStack(err);
+assert.strictEqual(originalStack, err.stack);