Skip to content

Commit d30b3c8

Browse files
committed
Update dist for v1.0.1.
1 parent f9970fe commit d30b3c8

File tree

2 files changed

+64
-61
lines changed

2 files changed

+64
-61
lines changed

dist/stackframe.js

+63-60
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,33 @@
1616
return !isNaN(parseFloat(n)) && isFinite(n);
1717
}
1818

19-
function StackFrame(functionName, args, fileName, lineNumber, columnNumber, source) {
20-
if (functionName !== undefined) {
21-
this.setFunctionName(functionName);
22-
}
23-
if (args !== undefined) {
24-
this.setArgs(args);
25-
}
26-
if (fileName !== undefined) {
27-
this.setFileName(fileName);
28-
}
29-
if (lineNumber !== undefined) {
30-
this.setLineNumber(lineNumber);
31-
}
32-
if (columnNumber !== undefined) {
33-
this.setColumnNumber(columnNumber);
34-
}
35-
if (source !== undefined) {
36-
this.setSource(source);
19+
function _capitalize(str) {
20+
return str[0].toUpperCase() + str.substring(1);
21+
}
22+
23+
function _getter(p) {
24+
return function () {
25+
return this[p];
26+
};
27+
}
28+
29+
var booleanProps = ['isConstructor', 'isEval', 'isNative', 'isToplevel'];
30+
var numericProps = ['columnNumber', 'lineNumber'];
31+
var stringProps = ['fileName', 'functionName', 'source'];
32+
var arrayProps = ['args'];
33+
34+
function StackFrame(obj) {
35+
if (obj instanceof Object) {
36+
var props = booleanProps.concat(numericProps.concat(stringProps.concat(arrayProps)));
37+
for (var i = 0; i < props.length; i++) {
38+
if (obj.hasOwnProperty(props[i])) {
39+
this['set' + _capitalize(props[i])](obj[props[i]]);
40+
}
41+
}
3742
}
3843
}
3944

4045
StackFrame.prototype = {
41-
getFunctionName: function () {
42-
return this.functionName;
43-
},
44-
setFunctionName: function (v) {
45-
this.functionName = String(v);
46-
},
47-
4846
getArgs: function () {
4947
return this.args;
5048
},
@@ -55,45 +53,20 @@
5553
this.args = v;
5654
},
5755

58-
// NOTE: Property name may be misleading as it includes the path,
59-
// but it somewhat mirrors V8's JavaScriptStackTraceApi
60-
// https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi and Gecko's
61-
// http://mxr.mozilla.org/mozilla-central/source/xpcom/base/nsIException.idl#14
62-
getFileName: function () {
63-
return this.fileName;
64-
},
65-
setFileName: function (v) {
66-
this.fileName = String(v);
67-
},
68-
69-
getLineNumber: function () {
70-
return this.lineNumber;
71-
},
72-
setLineNumber: function (v) {
73-
if (!_isNumber(v)) {
74-
throw new TypeError('Line Number must be a Number');
75-
}
76-
this.lineNumber = Number(v);
77-
},
78-
79-
getColumnNumber: function () {
80-
return this.columnNumber;
56+
getEvalOrigin: function () {
57+
return this.evalOrigin;
8158
},
82-
setColumnNumber: function (v) {
83-
if (!_isNumber(v)) {
84-
throw new TypeError('Column Number must be a Number');
59+
setEvalOrigin: function (v) {
60+
if (v instanceof StackFrame) {
61+
this.evalOrigin = v;
62+
} else if (v instanceof Object) {
63+
this.evalOrigin = new StackFrame(v);
64+
} else {
65+
throw new TypeError('Eval Origin must be an Object or StackFrame');
8566
}
86-
this.columnNumber = Number(v);
8767
},
8868

89-
getSource: function () {
90-
return this.source;
91-
},
92-
setSource: function (v) {
93-
this.source = String(v);
94-
},
95-
96-
toString: function() {
69+
toString: function () {
9770
var functionName = this.getFunctionName() || '{anonymous}';
9871
var args = '(' + (this.getArgs() || []).join(',') + ')';
9972
var fileName = this.getFileName() ? ('@' + this.getFileName()) : '';
@@ -103,5 +76,35 @@
10376
}
10477
};
10578

79+
for (var i = 0; i < booleanProps.length; i++) {
80+
StackFrame.prototype['get' + _capitalize(booleanProps[i])] = _getter(booleanProps[i]);
81+
StackFrame.prototype['set' + _capitalize(booleanProps[i])] = (function (p) {
82+
return function (v) {
83+
this[p] = Boolean(v);
84+
};
85+
})(booleanProps[i]);
86+
}
87+
88+
for (var j = 0; j < numericProps.length; j++) {
89+
StackFrame.prototype['get' + _capitalize(numericProps[j])] = _getter(numericProps[j]);
90+
StackFrame.prototype['set' + _capitalize(numericProps[j])] = (function (p) {
91+
return function (v) {
92+
if (!_isNumber(v)) {
93+
throw new TypeError(p + ' must be a Number');
94+
}
95+
this[p] = Number(v);
96+
};
97+
})(numericProps[j]);
98+
}
99+
100+
for (var k = 0; k < stringProps.length; k++) {
101+
StackFrame.prototype['get' + _capitalize(stringProps[k])] = _getter(stringProps[k]);
102+
StackFrame.prototype['set' + _capitalize(stringProps[k])] = (function (p) {
103+
return function (v) {
104+
this[p] = String(v);
105+
};
106+
})(stringProps[k]);
107+
}
108+
106109
return StackFrame;
107110
}));

gulpfile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ gulp.task('copy', function () {
3737
.pipe(gulp.dest('dist'));
3838
});
3939

40-
gulp.task('dist', function() {
40+
gulp.task('dist', ['copy'], function() {
4141
return gulp.src(sources)
4242
.pipe(sourcemaps.init())
4343
.pipe(uglify())

0 commit comments

Comments
 (0)