stackframe
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -19,31 +19,29 @@ (function (root, factory) { | ||
function StackFrame(functionName, args, fileName, lineNumber, columnNumber, source) { | ||
if (functionName !== undefined) { | ||
this.setFunctionName(functionName); | ||
function _capitalize(str) { | ||
return str[0].toUpperCase() + str.substring(1); | ||
} | ||
function _getter(p) { | ||
return function () { | ||
return this[p]; | ||
}; | ||
} | ||
var booleanProps = ['isConstructor', 'isEval', 'isNative', 'isToplevel']; | ||
var numericProps = ['columnNumber', 'lineNumber']; | ||
var stringProps = ['fileName', 'functionName', 'source']; | ||
var arrayProps = ['args']; | ||
function StackFrame(obj) { | ||
if (obj instanceof Object) { | ||
var props = booleanProps.concat(numericProps.concat(stringProps.concat(arrayProps))); | ||
for (var i = 0; i < props.length; i++) { | ||
if (obj.hasOwnProperty(props[i]) && obj[props[i]] !== undefined) { | ||
this['set' + _capitalize(props[i])](obj[props[i]]); | ||
} | ||
} | ||
} | ||
if (args !== undefined) { | ||
this.setArgs(args); | ||
} | ||
if (fileName !== undefined) { | ||
this.setFileName(fileName); | ||
} | ||
if (lineNumber !== undefined) { | ||
this.setLineNumber(lineNumber); | ||
} | ||
if (columnNumber !== undefined) { | ||
this.setColumnNumber(columnNumber); | ||
} | ||
if (source !== undefined) { | ||
this.setSource(source); | ||
} | ||
} | ||
StackFrame.prototype = { | ||
getFunctionName: function () { | ||
return this.functionName; | ||
}, | ||
setFunctionName: function (v) { | ||
this.functionName = String(v); | ||
}, | ||
getArgs: function () { | ||
@@ -59,41 +57,16 @@ return this.args; | ||
// NOTE: Property name may be misleading as it includes the path, | ||
// but it somewhat mirrors V8's JavaScriptStackTraceApi | ||
// https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi and Gecko's | ||
// http://mxr.mozilla.org/mozilla-central/source/xpcom/base/nsIException.idl#14 | ||
getFileName: function () { | ||
return this.fileName; | ||
getEvalOrigin: function () { | ||
return this.evalOrigin; | ||
}, | ||
setFileName: function (v) { | ||
this.fileName = String(v); | ||
}, | ||
getLineNumber: function () { | ||
return this.lineNumber; | ||
}, | ||
setLineNumber: function (v) { | ||
if (!_isNumber(v)) { | ||
throw new TypeError('Line Number must be a Number'); | ||
setEvalOrigin: function (v) { | ||
if (v instanceof StackFrame) { | ||
this.evalOrigin = v; | ||
} else if (v instanceof Object) { | ||
this.evalOrigin = new StackFrame(v); | ||
} else { | ||
throw new TypeError('Eval Origin must be an Object or StackFrame'); | ||
} | ||
this.lineNumber = Number(v); | ||
}, | ||
getColumnNumber: function () { | ||
return this.columnNumber; | ||
}, | ||
setColumnNumber: function (v) { | ||
if (!_isNumber(v)) { | ||
throw new TypeError('Column Number must be a Number'); | ||
} | ||
this.columnNumber = Number(v); | ||
}, | ||
getSource: function () { | ||
return this.source; | ||
}, | ||
setSource: function (v) { | ||
this.source = String(v); | ||
}, | ||
toString: function() { | ||
toString: function () { | ||
var functionName = this.getFunctionName() || '{anonymous}'; | ||
@@ -108,3 +81,33 @@ var args = '(' + (this.getArgs() || []).join(',') + ')'; | ||
for (var i = 0; i < booleanProps.length; i++) { | ||
StackFrame.prototype['get' + _capitalize(booleanProps[i])] = _getter(booleanProps[i]); | ||
StackFrame.prototype['set' + _capitalize(booleanProps[i])] = (function (p) { | ||
return function (v) { | ||
this[p] = Boolean(v); | ||
}; | ||
})(booleanProps[i]); | ||
} | ||
for (var j = 0; j < numericProps.length; j++) { | ||
StackFrame.prototype['get' + _capitalize(numericProps[j])] = _getter(numericProps[j]); | ||
StackFrame.prototype['set' + _capitalize(numericProps[j])] = (function (p) { | ||
return function (v) { | ||
if (!_isNumber(v)) { | ||
throw new TypeError(p + ' must be a Number'); | ||
} | ||
this[p] = Number(v); | ||
}; | ||
})(numericProps[j]); | ||
} | ||
for (var k = 0; k < stringProps.length; k++) { | ||
StackFrame.prototype['get' + _capitalize(stringProps[k])] = _getter(stringProps[k]); | ||
StackFrame.prototype['set' + _capitalize(stringProps[k])] = (function (p) { | ||
return function (v) { | ||
this[p] = String(v); | ||
}; | ||
})(stringProps[k]); | ||
} | ||
return StackFrame; | ||
})); |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"use strict";"function"==typeof define&&define.amd?define("stackframe",[],e):"object"==typeof exports?module.exports=e():t.StackFrame=e()}(this,function(){"use strict";function t(t){return!isNaN(parseFloat(t))&&isFinite(t)}function e(t){return t[0].toUpperCase()+t.substring(1)}function n(t){return function(){return this[t]}}function r(t){if(t instanceof Object)for(var n=i.concat(o.concat(s.concat(u))),r=0;r<n.length;r++)t.hasOwnProperty(n[r])&&this["set"+e(n[r])](t[n[r]])}var i=["isConstructor","isEval","isNative","isToplevel"],o=["columnNumber","lineNumber"],s=["fileName","functionName","source"],u=["args"];r.prototype={getArgs:function(){return this.args},setArgs:function(t){if("[object Array]"!==Object.prototype.toString.call(t))throw new TypeError("Args must be an Array");this.args=t},getEvalOrigin:function(){return this.evalOrigin},setEvalOrigin:function(t){if(t instanceof r)this.evalOrigin=t;else{if(!(t instanceof Object))throw new TypeError("Eval Origin must be an Object or StackFrame");this.evalOrigin=new r(t)}},toString:function(){var e=this.getFunctionName()||"{anonymous}",n="("+(this.getArgs()||[]).join(",")+")",r=this.getFileName()?"@"+this.getFileName():"",i=t(this.getLineNumber())?":"+this.getLineNumber():"",o=t(this.getColumnNumber())?":"+this.getColumnNumber():"";return e+n+r+i+o}};for(var a=0;a<i.length;a++)r.prototype["get"+e(i[a])]=n(i[a]),r.prototype["set"+e(i[a])]=function(t){return function(e){this[t]=Boolean(e)}}(i[a]);for(var c=0;c<o.length;c++)r.prototype["get"+e(o[c])]=n(o[c]),r.prototype["set"+e(o[c])]=function(e){return function(n){if(!t(n))throw new TypeError(e+" must be a Number");this[e]=Number(n)}}(o[c]);for(var f=0;f<s.length;f++)r.prototype["get"+e(s[f])]=n(s[f]),r.prototype["set"+e(s[f])]=function(t){return function(e){this[t]=String(e)}}(s[f]);return r}); | ||
!function(t,e){"use strict";"function"==typeof define&&define.amd?define("stackframe",[],e):"object"==typeof exports?module.exports=e():t.StackFrame=e()}(this,function(){"use strict";function t(t){return!isNaN(parseFloat(t))&&isFinite(t)}function e(t){return t[0].toUpperCase()+t.substring(1)}function n(t){return function(){return this[t]}}function r(t){if(t instanceof Object)for(var n=i.concat(o.concat(s.concat(u))),r=0;r<n.length;r++)t.hasOwnProperty(n[r])&&void 0!==t[n[r]]&&this["set"+e(n[r])](t[n[r]])}var i=["isConstructor","isEval","isNative","isToplevel"],o=["columnNumber","lineNumber"],s=["fileName","functionName","source"],u=["args"];r.prototype={getArgs:function(){return this.args},setArgs:function(t){if("[object Array]"!==Object.prototype.toString.call(t))throw new TypeError("Args must be an Array");this.args=t},getEvalOrigin:function(){return this.evalOrigin},setEvalOrigin:function(t){if(t instanceof r)this.evalOrigin=t;else{if(!(t instanceof Object))throw new TypeError("Eval Origin must be an Object or StackFrame");this.evalOrigin=new r(t)}},toString:function(){var e=this.getFunctionName()||"{anonymous}",n="("+(this.getArgs()||[]).join(",")+")",r=this.getFileName()?"@"+this.getFileName():"",i=t(this.getLineNumber())?":"+this.getLineNumber():"",o=t(this.getColumnNumber())?":"+this.getColumnNumber():"";return e+n+r+i+o}};for(var a=0;a<i.length;a++)r.prototype["get"+e(i[a])]=n(i[a]),r.prototype["set"+e(i[a])]=function(t){return function(e){this[t]=Boolean(e)}}(i[a]);for(var c=0;c<o.length;c++)r.prototype["get"+e(o[c])]=n(o[c]),r.prototype["set"+e(o[c])]=function(e){return function(n){if(!t(n))throw new TypeError(e+" must be a Number");this[e]=Number(n)}}(o[c]);for(var f=0;f<s.length;f++)r.prototype["get"+e(s[f])]=n(s[f]),r.prototype["set"+e(s[f])]=function(t){return function(e){this[t]=String(e)}}(s[f]);return r}); | ||
//# sourceMappingURL=stackframe.min.js.map |
@@ -40,3 +40,3 @@ var coveralls = require('gulp-coveralls'); | ||
gulp.task('dist', function() { | ||
gulp.task('dist', ['copy'], function() { | ||
return gulp.src(sources) | ||
@@ -43,0 +43,0 @@ .pipe(sourcemaps.init()) |
@@ -9,3 +9,3 @@ { | ||
], | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"license": "Unlicense", | ||
@@ -12,0 +12,0 @@ "keywords": [ |
@@ -38,3 +38,3 @@ (function (root, factory) { | ||
for (var i = 0; i < props.length; i++) { | ||
if (obj.hasOwnProperty(props[i])) { | ||
if (obj.hasOwnProperty(props[i]) && obj[props[i]] !== undefined) { | ||
this['set' + _capitalize(props[i])](obj[props[i]]); | ||
@@ -41,0 +41,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31622
474