Permalink
Browse files

Merge pull request #14 from newclear/master

fix testcase for node
  • Loading branch information...
2 parents c962080 + b81406e commit 4a282316db4a2a93bdc91c6bc06c085ba878d5af @felixge committed Jan 26, 2016
Showing with 69 additions and 35 deletions.
  1. +48 −23 lib/stack-trace.js
  2. +21 −12 test/integration/test-parse.js
View
@@ -52,11 +52,20 @@ exports.parse = function(err) {
var isNative = (lineMatch[5] === 'native');
if (lineMatch[1]) {
- var methodMatch = lineMatch[1].match(/([^\.]+)(?:\.(.+))?/);
- object = methodMatch[1];
- method = methodMatch[2];
functionName = lineMatch[1];
- typeName = 'Object';
+ var methodStart = functionName.lastIndexOf('.');
+ if (functionName[methodStart-1] == '.')
+ methodStart--;
+ if (methodStart > 0) {
+ object = functionName.substr(0, methodStart);
+ method = functionName.substr(methodStart + 1);
+ var objectEnd = object.indexOf('.Module');
+ if (objectEnd > 0) {
+ functionName = functionName.substr(objectEnd + 1);
+ object = object.substr(0, objectEnd);
+ }
+ }
+ typeName = null;
}
if (method) {
@@ -66,7 +75,7 @@ exports.parse = function(err) {
if (method === '<anonymous>') {
methodName = null;
- functionName = '';
+ functionName = null;
}
var properties = {
@@ -86,26 +95,42 @@ exports.parse = function(err) {
});
};
-exports._createParsedCallSite = function(properties) {
- var methods = {};
+function CallSite(properties) {
for (var property in properties) {
- var prefix = 'get';
- if (property === 'native') {
- prefix = 'is';
- }
- var method = prefix + property.substr(0, 1).toUpperCase() + property.substr(1);
-
- (function(property) {
- methods[method] = function() {
- return properties[property];
- }
- })(property);
+ this[property] = properties[property];
}
-
- var callSite = Object.create(methods);
- for (var property in properties) {
- callSite[property] = properties[property];
+}
+
+var strProperties = [
+ 'this',
+ 'typeName',
+ 'functionName',
+ 'methodName',
+ 'fileName',
+ 'lineNumber',
+ 'columnNumber',
+ 'function',
+ 'evalOrigin'
+];
+var boolProperties = [
+ 'topLevel',
+ 'eval',
+ 'native',
+ 'constructor'
+];
+strProperties.forEach(function (property) {
+ CallSite.prototype[property] = null;
+ CallSite.prototype['get' + property[0].toUpperCase() + property.substr(1)] = function () {
+ return this[property];
+ }
+});
+boolProperties.forEach(function (property) {
+ CallSite.prototype[property] = false;
+ CallSite.prototype['is' + property[0].toUpperCase() + property.substr(1)] = function () {
+ return this[property];
}
+});
- return callSite;
+exports._createParsedCallSite = function(properties) {
+ return new CallSite(properties);
};
@@ -54,7 +54,14 @@ var stackTrace = require(common.dir.lib + '/stack-trace');
})();
(function testCompareRealWithParsedStackTrace() {
- var realTrace = stackTrace.get(); var err = new Error('something went wrong');
+ var realTrace, err;
+ function TestClass() {
+ }
+ TestClass.prototype.testFunc = function () {
+ realTrace = stackTrace.get(); err = new Error('something went wrong');
+ }
+ var testObj = new TestClass();
+ testObj.testFunc();
var parsedTrace = stackTrace.parse(err);
realTrace.forEach(function(real, i) {
@@ -64,7 +71,7 @@ var stackTrace = require(common.dir.lib + '/stack-trace');
var realValue = real[method]();
var parsedValue = parsed[method]();
- if (exceptions && exceptions[i]) {
+ if (exceptions && typeof exceptions[i] != 'undefined') {
realValue = exceptions[i];
}
@@ -78,17 +85,19 @@ var stackTrace = require(common.dir.lib + '/stack-trace');
}
compare('getFileName');
- compare('getFunctionName', {
- 3: 'Object..js',
- 5: 'Function._load',
- 6: 'Array.0',
- 7: 'EventEmitter._tickCallback',
+ compare('getFunctionName');
+ compare('getTypeName', {
+ 1: null, //for 0.12.x
+ 8: null, //for 0.12.x
+ 9: null
+ });
+ compare('getMethodName', {
+ 6: '_load', //for 0.12.x
+ 7: 'runMain' //for 0.12.x
});
- compare('getTypeName');
- compare('getMethodName');
compare('getLineNumber');
compare('getColumnNumber', {
- 0: 47
+ 0: 41
});
compare('isNative');
});
@@ -158,8 +167,8 @@ var stackTrace = require(common.dir.lib + '/stack-trace');
assert.strictEqual(callSite0.getFileName(), '/Users/den/Projects/should.js/lib/should.js');
assert.strictEqual(callSite0.getFunctionName(), 'Assertion.prop.(anonymous function)');
- assert.strictEqual(callSite0.getTypeName(), "Assertion");
- assert.strictEqual(callSite0.getMethodName(), "prop.(anonymous function)");
+ assert.strictEqual(callSite0.getTypeName(), "Assertion.prop");
+ assert.strictEqual(callSite0.getMethodName(), "(anonymous function)");
assert.strictEqual(callSite0.getLineNumber(), 60);
assert.strictEqual(callSite0.getColumnNumber(), 14);
assert.strictEqual(callSite0.isNative(), false);

0 comments on commit 4a28231

Please sign in to comment.