Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

A small fix #25

Closed
wants to merge 3 commits into from

3 participants

@yhwh

Hi,
Is it correct ?

Nicolas Ferrero Fix for V8 JavaScript stack trace API based browsers
Print more info (filename, linenumber, and stack) when throwing errors
32d7fee
@ragaskar
Owner

There's no specs for this pull, so it might take us awhile to get it in. We'll take a look. Thanks!

@yhwh

Currently how can I write specs for code that could be executed differently in various browsers ?

@infews
Owner

We've got a few pull requests and will be looking at them together. But yes, these are hard to test.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 22, 2010
  1. Fix for V8 JavaScript stack trace API based browsers

    Nicolas Ferrero authored
    Print more info (filename, linenumber, and stack) when throwing errors
Commits on Oct 23, 2010
  1. Undefined stack fix

    Nicolas authored
  2. Chrome syntax error reporting fix

    Nicolas authored
This page is out of date. Refresh to see the latest.
Showing with 69 additions and 5 deletions.
  1. +35 −3 lib/jasmine.js
  2. +2 −1  src/Spec.js
  3. +1 −1  src/base.js
  4. +31 −0 src/util.js
View
38 lib/jasmine.js
@@ -91,7 +91,7 @@ jasmine.ExpectationResult = function(params) {
this.actual = params.actual;
this.message = this.passed_ ? 'Passed.' : params.message;
- this.trace = this.passed_ ? '' : new Error(this.message);
+ this.trace = this.passed_ ? '' : new Error(params.trace || this.message);
};
jasmine.ExpectationResult.prototype.toString = function () {
@@ -633,9 +633,40 @@ jasmine.util.formatException = function(e) {
message += ' in ' + file + ' (line ' + lineNumber + ')';
}
+ if (!file && !lineNumber && typeof e.stack === "string") {
+ message += ' in ' + e.stack.match(/\(file\:.*\)/)[0];
+ }
+
return message;
};
+jasmine.util.formatTrace = function(e) {
+ var lineNumber;
+ if (e.line) {
+ lineNumber = e.line;
+ }
+ else if (e.lineNumber) {
+ lineNumber = e.lineNumber;
+ }
+
+ var file;
+
+ if (e.sourceURL) {
+ file = e.sourceURL;
+ }
+ else if (e.fileName) {
+ file = e.fileName;
+ }
+
+ var trace;
+
+ if (!file && !lineNumber) {
+ trace = e.stack;
+ }
+
+ return trace;
+};
+
jasmine.util.htmlEscape = function(str) {
if (!str) return str;
return str.replace(/&/g, '&')
@@ -1962,7 +1993,8 @@ jasmine.Spec.prototype.waitsFor = function(latchFunction, optional_timeoutMessag
jasmine.Spec.prototype.fail = function (e) {
var expectationResult = new jasmine.ExpectationResult({
passed: false,
- message: e ? jasmine.util.formatException(e) : 'Exception'
+ message: e ? jasmine.util.formatException(e) : 'Exception',
+ trace: e ? jasmine.util.formatTrace(e) : null
});
this.results_.addResult(expectationResult);
};
@@ -2417,5 +2449,5 @@ jasmine.version_= {
"major": 1,
"minor": 0,
"build": 1,
- "revision": 1286311016
+ "revision": 1287873334
};
View
3  src/Spec.js
@@ -120,7 +120,8 @@ jasmine.Spec.prototype.waitsFor = function(latchFunction, optional_timeoutMessag
jasmine.Spec.prototype.fail = function (e) {
var expectationResult = new jasmine.ExpectationResult({
passed: false,
- message: e ? jasmine.util.formatException(e) : 'Exception'
+ message: e ? jasmine.util.formatException(e) : 'Exception',
+ trace: e ? jasmine.util.formatTrace(e) : null
});
this.results_.addResult(expectationResult);
};
View
2  src/base.js
@@ -91,7 +91,7 @@ jasmine.ExpectationResult = function(params) {
this.actual = params.actual;
this.message = this.passed_ ? 'Passed.' : params.message;
- this.trace = this.passed_ ? '' : new Error(this.message);
+ this.trace = this.passed_ ? '' : new Error(params.trace || this.message);
};
jasmine.ExpectationResult.prototype.toString = function () {
View
31 src/util.js
@@ -44,9 +44,40 @@ jasmine.util.formatException = function(e) {
message += ' in ' + file + ' (line ' + lineNumber + ')';
}
+ if (!file && !lineNumber && typeof e.stack === "string") {
+ message += ' in ' + e.stack.match(/\(file\:.*\)/)[0];
+ }
+
return message;
};
+jasmine.util.formatTrace = function(e) {
+ var lineNumber;
+ if (e.line) {
+ lineNumber = e.line;
+ }
+ else if (e.lineNumber) {
+ lineNumber = e.lineNumber;
+ }
+
+ var file;
+
+ if (e.sourceURL) {
+ file = e.sourceURL;
+ }
+ else if (e.fileName) {
+ file = e.fileName;
+ }
+
+ var trace;
+
+ if (!file && !lineNumber) {
+ trace = e.stack;
+ }
+
+ return trace;
+};
+
jasmine.util.htmlEscape = function(str) {
if (!str) return str;
return str.replace(/&/g, '&')
Something went wrong with that request. Please try again.