[Pkg-javascript-commits] [node-stack-utils] 35/67: Added support for wrapping CallSite

Bastien Roucariès rouca at moszumanska.debian.org
Thu Sep 7 09:53:04 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-stack-utils.

commit 548d68577100154cae0cdff0080e15253c7c85b8
Author: Ben McCurdy <bpmccurdy at gmail.com>
Date:   Mon Oct 10 15:42:16 2016 -0700

    Added support for wrapping CallSite
---
 index.js     |  7 +++++++
 test/test.js | 20 ++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/index.js b/index.js
index b297e1f..dcaea0b 100644
--- a/index.js
+++ b/index.js
@@ -7,6 +7,7 @@ function StackUtils(opts) {
 	opts = opts || {};
 	this._cwd = (opts.cwd || process.cwd()).replace(/\\/g, '/');
 	this._internals = opts.internals || [];
+	this._wrapCallSite = opts.wrapCallSite || false;
 }
 
 module.exports.nodeInternals = nodeInternals;
@@ -117,8 +118,14 @@ StackUtils.prototype.capture = function (limit, fn) {
 	}
 	var prepBefore = Error.prepareStackTrace;
 	var limitBefore = Error.stackTraceLimit;
+	var wrapCallSite = this._wrapCallSite;
 
 	Error.prepareStackTrace = function (obj, site) {
+		if (typeof wrapCallSite === 'function') {
+			return site.map(function (callSite) {
+				return wrapCallSite(callSite);
+			});
+		}
 		return site;
 	};
 
diff --git a/test/test.js b/test/test.js
index b0a962d..37af4a0 100644
--- a/test/test.js
+++ b/test/test.js
@@ -236,6 +236,26 @@ test('capture: with limit and stackStart function', t => {
 	t.is(stack[0].getFunctionName(), 'CaptureFixture.redirect2');
 });
 
+test('capture: with wrapCallSite function', t => {
+	var wrapper = function (frame) {
+		var object = {};
+		Object.getOwnPropertyNames(Object.getPrototypeOf(frame)).forEach(function (name) {
+			object[name] = /^(?:is|get)/.test(name) ? function () {
+				return frame[name];
+			} : frame[name];
+		});
+		object.getFunctionName = function () {
+			return 'testFunctionName';
+		};
+		return object;
+	};
+	const stackUtil = new StackUtils({internals: internals(), cwd: fixtureDir, wrapCallSite: wrapper});
+	const capture = new CaptureFixture(stackUtil);
+	const stack = capture.redirect1('redirect2', 'call', 'capture', 1, capture.call);
+	t.is(stack.length, 1);
+	t.is(stack[0].getFunctionName(), 'testFunctionName');
+});
+
 test('at', t => {
 	const stackUtil = new StackUtils({internals: internals(), cwd: fixtureDir});
 	const capture = new CaptureFixture(stackUtil);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-stack-utils.git



More information about the Pkg-javascript-commits mailing list