[Pkg-javascript-commits] [node-stack-utils] 10/67: refactor methods to use options objects

Bastien Roucariès rouca at moszumanska.debian.org
Thu Sep 7 09:53:01 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 307716fe42d708ff8157e5e7fb5dd7c9af9b44ee
Author: James Talmage <james at talmage.io>
Date:   Mon Jan 4 22:19:29 2016 -0500

    refactor methods to use options objects
---
 index.js | 27 ++++++++++-----------------
 test.js  | 12 ++++++------
 2 files changed, 16 insertions(+), 23 deletions(-)

diff --git a/index.js b/index.js
index 961e6fa..093f8a3 100644
--- a/index.js
+++ b/index.js
@@ -57,14 +57,10 @@ StackUtils.prototype.clean = function (stack) {
 	return null;
 };
 
-StackUtils.prototype.captureString = function (limit, fn) {
-	if (typeof limit === 'function') {
-		fn = limit;
-		limit = Infinity;
-	}
-	if (!fn) {
-		fn = this.captureString;
-	}
+StackUtils.prototype.captureString = function (options) {
+	options = options || {};
+	var limit = options.limit || Infinity;
+	var fn = options.startStackFunction || this.captureString;
 
 	var limitBefore = Error.stackTraceLimit;
 	if (limit) {
@@ -80,14 +76,11 @@ StackUtils.prototype.captureString = function (limit, fn) {
 	return this.clean(stack);
 };
 
-StackUtils.prototype.capture = function (limit, fn) {
-	if (typeof limit === 'function') {
-		fn = limit;
-		limit = Infinity;
-	}
-	if (!fn) {
-		fn = this.capture;
-	}
+StackUtils.prototype.capture = function (options) {
+	options = options || {};
+	var limit = options.limit || Infinity;
+	var fn = options.startStackFunction || this.capture;
+
 	var prepBefore = Error.prepareStackTrace;
 	var limitBefore = Error.stackTraceLimit;
 
@@ -113,7 +106,7 @@ StackUtils.prototype.at = function at(fn) {
 		fn = at;
 	}
 
-	var site = this.capture(1, fn)[0];
+	var site = this.capture({limit: 1, startStackFunction: fn})[0];
 
 	if (!site) {
 		return {};
diff --git a/test.js b/test.js
index 51ce222..1230a38 100644
--- a/test.js
+++ b/test.js
@@ -80,7 +80,7 @@ test('captureString: with startStack function', t => {
 	const stack = new StackUtils({internals: internals(), cwd: fixtureDir});
 	const capture = new CaptureFixture(stack);
 
-	const capturedString = capture.redirect1('redirect2', 'call', 'captureString', capture.call);
+	const capturedString = capture.redirect1('redirect2', 'call', 'captureString', {startStackFunction: capture.call});
 	t.is(capturedString, join([
 		'CaptureFixture.redirect2 (capture-fixture.js:17:22)',
 		'CaptureFixture.redirect1 (capture-fixture.js:11:22)'
@@ -91,7 +91,7 @@ test('captureString: with limit', t => {
 	const stack = new StackUtils({internals: internals(), cwd: fixtureDir});
 	const capture = new CaptureFixture(stack);
 
-	const capturedString = capture.redirect1('redirect2', 'call', 'captureString', 1);
+	const capturedString = capture.redirect1('redirect2', 'call', 'captureString', {limit: 1});
 	t.is(capturedString, join([
 		'CaptureFixture.call (capture-fixture.js:23:28)'
 	]));
@@ -101,7 +101,7 @@ test('captureString: with limit and startStack', t => {
 	const stack = new StackUtils({internals: internals(), cwd: fixtureDir});
 	const capture = new CaptureFixture(stack);
 
-	const capturedString = capture.redirect1('redirect2', 'call', 'captureString', 1, capture.call);
+	const capturedString = capture.redirect1('redirect2', 'call', 'captureString', {limit: 1, startStackFunction: capture.call});
 	t.is(capturedString, join([
 		'CaptureFixture.redirect2 (capture-fixture.js:17:22)'
 	]));
@@ -119,7 +119,7 @@ test('capture returns an array of call sites', t => {
 test('capture: with limit', t => {
 	const stackUtil = new StackUtils({internals: internals(), cwd: fixtureDir});
 	const capture = new CaptureFixture(stackUtil);
-	const stack = capture.redirect1('redirect2', 'call', 'capture', 1);
+	const stack = capture.redirect1('redirect2', 'call', 'capture', {limit: 1});
 	t.is(stack.length, 1);
 	t.is(stack[0].getFunctionName(), 'CaptureFixture.call');
 });
@@ -127,7 +127,7 @@ test('capture: with limit', t => {
 test('capture: with stackStart function', t => {
 	const stackUtil = new StackUtils({internals: internals(), cwd: fixtureDir});
 	const capture = new CaptureFixture(stackUtil);
-	const stack = capture.redirect1('redirect2', 'call', 'capture', capture.call);
+	const stack = capture.redirect1('redirect2', 'call', 'capture', {startStackFunction: capture.call});
 	t.true(stack.length > 1);
 	t.is(stack[0].getFunctionName(), 'CaptureFixture.redirect2');
 });
@@ -135,7 +135,7 @@ test('capture: with stackStart function', t => {
 test('capture: with limit and stackStart function', t => {
 	const stackUtil = new StackUtils({internals: internals(), cwd: fixtureDir});
 	const capture = new CaptureFixture(stackUtil);
-	const stack = capture.redirect1('redirect2', 'call', 'capture', 1, capture.call);
+	const stack = capture.redirect1('redirect2', 'call', 'capture', {limit: 1, startStackFunction: capture.call});
 	t.is(stack.length, 1);
 	t.is(stack[0].getFunctionName(), 'CaptureFixture.redirect2');
 });

-- 
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