Skip to content

Commit 7fea06d

Browse files
committed
API Changes for v1.0. Fixes #4 and #8.
StackFrames can be optionally constructed with an Object. This is necessary in order to avoid an explosion of constructor params. eval() origin information can now be represented in a StackFrame. This is done through setEvalOrigin() where one can store a "child" StackFrame that represents location information within the eval'd String or Function.
1 parent 93c2d7f commit 7fea06d

5 files changed

Lines changed: 191 additions & 88 deletions

File tree

README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,23 @@ stackframe
33
## JS Object representation of a stack frame
44
[![Build Status](https://travis-ci.org/stacktracejs/stackframe.svg?branch=master)](https://travis-ci.org/stacktracejs/stackframe) [![Coverage Status](https://img.shields.io/coveralls/stacktracejs/stackframe.svg)](https://coveralls.io/r/stacktracejs/stackframe?branch=master) [![Code Climate](https://codeclimate.com/github/stacktracejs/stackframe/badges/gpa.svg)](https://codeclimate.com/github/stacktracejs/stackframe)
55

6-
Underlies functionality of other modules within [stacktrace.js](http://www.stacktracejs.com).
6+
Underlies functionality of other modules within [stacktrace.js](https://www.stacktracejs.com).
77

8-
Written to closely resemble StackFrame representations in [Gecko](http://mxr.mozilla.org/mozilla-central/source/xpcom/base/nsIException.idl#14) and [V8](https://code.google.com/p/v8-wiki/wiki/JavaScriptStackTraceApi)
8+
Written to closely resemble StackFrame representations in [Gecko](http://mxr.mozilla.org/mozilla-central/source/xpcom/base/nsIException.idl#14) and [V8](https://github.com/v8/v8/wiki/Stack%20Trace%20API)
99

1010
## Usage
1111
```js
1212
// Create StackFrame and set properties
13-
var stackFrame = new StackFrame('funName', ['args'], 'http://localhost:3000/file.js', 1, 3288, 'ORIGINAL_STACK_LINE');
13+
var stackFrame = new StackFrame({
14+
functionName: 'funName',
15+
args: ['args'],
16+
fileName: 'http://localhost:3000/file.js',
17+
lineNumber: 1,
18+
columnNumber: 3288,
19+
isEval: true,
20+
isNative: false,
21+
source: 'ORIGINAL_STACK_LINE'
22+
});
1423

1524
stackFrame.functionName // => "funName"
1625
stackFrame.setFunctionName('newName')
@@ -36,6 +45,14 @@ stackFrame.source // => 'ORIGINAL_STACK_LINE'
3645
stackFrame.setSource('NEW_SOURCE')
3746
stackFrame.getSource() // => 'NEW_SOURCE'
3847

48+
stackFrame.isEval // => true
49+
stackFrame.setIsEval(false)
50+
stackFrame.getIsEval() // => false
51+
52+
stackFrame.isNative // => false
53+
stackFrame.setIsNative(true)
54+
stackFrame.getIsNative() // => true
55+
3956
stackFrame.toString() // => 'funName(args)@http://localhost:3000/file.js:325:20'
4057
```
4158

gulpfile.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var coveralls = require('gulp-coveralls');
22
var del = require('del');
33
var gulp = require('gulp');
44
var jshint = require('gulp-jshint');
5-
var karma = require('karma').server;
5+
var karma = require('karma');
66
var rename = require('gulp-rename');
77
var runSequence = require('run-sequence');
88
var sourcemaps = require('gulp-sourcemaps');
@@ -19,17 +19,17 @@ gulp.task('lint', function () {
1919
});
2020

2121
gulp.task('test', function (done) {
22-
karma.start({
22+
new karma.Server({
2323
configFile: __dirname + '/karma.conf.js',
2424
singleRun: true
25-
}, done);
25+
}, done).start();
2626
});
2727

2828
gulp.task('test-ci', ['copy', 'dist'], function (done) {
29-
karma.start({
29+
new karma.Server({
3030
configFile: __dirname + '/karma.conf.ci.js',
3131
singleRun: true
32-
}, done);
32+
}, done).start();
3333
});
3434

3535
gulp.task('copy', function () {

package.json

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,42 @@
66
"Victor Homyakov <vkhomyackov@gmail.com> (https://github.com/victor-homyakov)",
77
"Oliver Salzburg (https://github.com/oliversalzburg)"
88
],
9-
"version": "0.3.1",
9+
"version": "1.0.0",
1010
"license": "SEE LICENSE IN LICENSE",
1111
"keywords": [
1212
"stacktrace",
1313
"error",
1414
"debugger",
1515
"stack frame"
1616
],
17-
"homepage": "http://www.stacktracejs.com",
17+
"homepage": "https://www.stacktracejs.com",
1818
"repository": {
1919
"type": "git",
2020
"url": "git://github.com/stacktracejs/stackframe.git"
2121
},
2222
"devDependencies": {
2323
"colors": "^1.1.2",
24-
"del": "^1.2.0",
24+
"del": "^2.2.0",
2525
"gulp": "^3.9.0",
2626
"gulp-coveralls": "^0.1.4",
27-
"gulp-jshint": "^1.11.2",
27+
"gulp-jshint": "^2.0.0",
2828
"gulp-rename": "^1.2.2",
29-
"gulp-sourcemaps": "^1.5.2",
30-
"gulp-uglify": "^1.2.0",
31-
"jasmine-node": "~1.14",
32-
"karma": "~0.12",
33-
"karma-chrome-launcher": "^0.1.5",
34-
"karma-coverage": "^0.2.6",
35-
"karma-firefox-launcher": "^0.1.3",
36-
"karma-ie-launcher": "^0.1.5",
37-
"karma-jasmine": "^0.2.3",
38-
"karma-opera-launcher": "^0.1.0",
39-
"karma-phantomjs2-launcher": "^0.3.0",
29+
"gulp-sourcemaps": "^1.6.0",
30+
"gulp-uglify": "^1.5.1",
31+
"jasmine": "^2.4.1",
32+
"jasmine-core": "^2.4.1",
33+
"jshint": "^2.8.0",
34+
"karma": "^0.13.15",
35+
"karma-chrome-launcher": "^0.2.2",
36+
"karma-coverage": "^0.5.3",
37+
"karma-firefox-launcher": "^0.1.7",
38+
"karma-ie-launcher": "^0.2.0",
39+
"karma-jasmine": "^0.3.6",
40+
"karma-opera-launcher": "^0.3.0",
41+
"karma-phantomjs2-launcher": "^0.3.2",
4042
"karma-safari-launcher": "^0.1.1",
41-
"karma-sauce-launcher": "^0.2.10",
42-
"run-sequence": "^1.1.2"
43+
"karma-sauce-launcher": "^0.3.0",
44+
"run-sequence": "^1.1.5"
4345
},
4446
"bugs": {
4547
"url": "https://github.com/stacktracejs/stackframe/issues"
@@ -49,3 +51,4 @@
4951
"test": "gulp test"
5052
}
5153
}
54+

spec/stackframe-spec.js

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe('StackFrame', function () {
88

99
it('throws an error given an illogical line number', function() {
1010
var fn = function () {
11-
new StackFrame('foo', [], 'path/to/file.js', 'BOGUS');
11+
new StackFrame({lineNumber: 'BOGUS'});
1212
};
1313
expect(fn).toThrow();
1414
});
@@ -38,6 +38,26 @@ describe('StackFrame', function () {
3838
});
3939
});
4040

41+
describe('#setEvalOrigin', function() {
42+
var unit = new StackFrame();
43+
44+
it('throws an error given a non-Object', function() {
45+
expect(function() {
46+
unit.setEvalOrigin('BOGUS');
47+
}).toThrow(new TypeError('Eval Origin must be an Object or StackFrame'));
48+
});
49+
50+
it('handles given StackFrame', function() {
51+
unit.setEvalOrigin(new StackFrame({lineNumber: 2}));
52+
expect(unit.getEvalOrigin().getLineNumber()).toEqual(2);
53+
});
54+
55+
it('handles given Object', function() {
56+
unit.setEvalOrigin({functionName: 'evalFn'});
57+
expect(unit.getEvalOrigin().getFunctionName()).toEqual('evalFn');
58+
});
59+
});
60+
4161
describe('#setFileName', function() {
4262
var unit = new StackFrame();
4363
it('coerces input to String', function() {
@@ -57,7 +77,7 @@ describe('StackFrame', function () {
5777
});
5878

5979
it('throws an error given input that cannot be coerced', function() {
60-
expect(function() { unit.setLineNumber('BOGUS'); }).toThrow(new TypeError('Line Number must be a Number'));
80+
expect(function() { unit.setLineNumber('BOGUS'); }).toThrow(new TypeError('lineNumber must be a Number'));
6181
});
6282
});
6383

@@ -69,7 +89,42 @@ describe('StackFrame', function () {
6989
});
7090

7191
it('throws an error given input that cannot be coerced', function() {
72-
expect(function() { unit.setColumnNumber('BOGUS'); }).toThrow(new TypeError('Column Number must be a Number'));
92+
expect(function() { unit.setColumnNumber('BOGUS'); }).toThrow(new TypeError('columnNumber must be a Number'));
93+
});
94+
});
95+
96+
describe('#setIsEval', function() {
97+
var unit = new StackFrame();
98+
it('coerces input to Boolean', function() {
99+
unit.setIsEval('true');
100+
expect(unit.getIsEval()).toBe(true);
101+
});
102+
});
103+
104+
describe('#setIsConstructor', function() {
105+
var unit = new StackFrame();
106+
it('coerces input to Boolean', function() {
107+
unit.setIsConstructor(0);
108+
expect(unit.getIsConstructor()).toBe(false);
109+
expect(unit.isConstructor).toBe(false);
110+
});
111+
});
112+
113+
describe('#setIsNative', function() {
114+
var unit = new StackFrame();
115+
it('coerces input to Boolean', function() {
116+
unit.setIsNative(undefined);
117+
expect(unit.getIsNative()).toBe(false);
118+
expect(unit.isNative).toBe(false);
119+
});
120+
});
121+
122+
describe('#setIsToplevel', function() {
123+
var unit = new StackFrame();
124+
it('coerces input to Boolean', function() {
125+
unit.setIsToplevel(null);
126+
expect(unit.getIsToplevel()).toBe(false);
127+
expect(unit.isToplevel).toBe(false);
73128
});
74129
});
75130

@@ -86,7 +141,16 @@ describe('StackFrame', function () {
86141
expect(new StackFrame().toString()).toEqual('{anonymous}()');
87142
});
88143
it('represents complete StackFrame same as old stacktrace.js', function() {
89-
var unit = new StackFrame('fun', [1, 2], 'http://site.com/path.js', 1, 4567, 'SOURCE');
144+
var unit = new StackFrame({
145+
functionName: 'fun',
146+
args: [1, 2],
147+
fileName: 'http://site.com/path.js',
148+
lineNumber: 1,
149+
columnNumber: 4567,
150+
isEval: false,
151+
isNative: false,
152+
source: 'SOURCE'
153+
});
90154
expect(unit.toString()).toEqual('fun(1,2)@http://site.com/path.js:1:4567');
91155
});
92156
});

0 commit comments

Comments
 (0)