Skip to content

Commit 0dff212

Browse files
author
homyakov
committed
2 parents 4d72b5c + 3ff73c0 commit 0dff212

15 files changed

+297
-15
lines changed

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ You can also pass in your own Error to get a stacktrace *not in IE or Safari, th
3232
printStackTrace({e: lastError});
3333
</script>
3434

35-
Some people recommend just assigning it to `window.onerror`. Make sure that you have script debugging turned off for IE. *Only in IE, FF and Chrome*
35+
Some people recommend just assigning it to `window.onerror`. Make sure that you have script debugging turned off for IE. *Only in IE*
3636

3737
window.onerror = function(msg, file, line) {
3838
alert(printStackTrace().join('\n\n'));
@@ -63,15 +63,11 @@ It is currently tested and working on:
6363
- Firefox (and Iceweasel) 0.9+
6464
- Google Chrome 1+
6565
- Safari 3.0+
66-
- Opera 10+
66+
- Opera 7+
6767
- IE 5.5+
6868
- Konqueror 3.5+
6969
- Flock 1.0+
7070
- SeaMonkey 1.0+
7171
- K-Meleon 1.5.3+
7272
- Epiphany 2.28.0+
7373
- Iceape 1.1+
74-
75-
Working (readable, valid stack trace) but not perfectly tested on:
76-
77-
- Opera 9-

build/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ task test(dependsOn: 'init') << {
8080
resultproperty: 'exitCode', failonerror: 'false', executable: '/usr/bin/env') {
8181
arg(value: 'DISPLAY=:1')
8282
arg(value: '/usr/local/bin/phantomjs')
83-
arg(value: '../test/phantomjs-qunit-runner.js')
83+
arg(value: '../test/lib/phantomjs-qunit-runner.js')
8484
arg(value: "${spec.canonicalPath}")
8585
}
8686
// Check exit code

jsTestDriver.conf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
server: http://localhost:4224
2+
3+
load:
4+
- test/lib/qunit.js
5+
- test/lib/equiv.js
6+
- test/lib/QUnitAdapter.js
7+
- stacktrace.js
8+
- test/CapturedExceptions.js
9+
10+
test:
11+
- test/TestStacktrace.js
12+
13+
plugin:
14+
- name: "coverage"
15+
jar: "test/lib/plugins/coverage.jar"
16+
module: "com.google.jstestdriver.coverage.CoverageModule"
17+
args: useCoberturaFormat
18+
19+
timeout: 120

stacktrace.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ printStackTrace.implementation.prototype = {
4242
createException: function() {
4343
try {
4444
this.undef();
45-
return null;
4645
} catch (e) {
4746
return e;
4847
}
@@ -279,8 +278,6 @@ printStackTrace.implementation.prototype = {
279278
if (req) {
280279
try {
281280
req.open('GET', url, false);
282-
//req.setRequestHeader('Content-Type', 'text/plain');
283-
//req.send('');
284281
req.send(null);
285282
return req.responseText;
286283
} catch (e) {

test/TestStacktrace.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
<head>
2222
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
2323
<title>stacktrace.js Test Suite</title>
24-
<link rel='stylesheet' href='qunit.css' type='text/css' />
25-
<script type='text/javascript' src='qunit.js'></script>
26-
<script type='text/javascript' src='qunit-junit-outputter.js'></script>
24+
<link rel='stylesheet' href='lib/qunit.css' type='text/css' />
25+
<script type='text/javascript' src='lib/qunit.js'></script>
26+
<script type='text/javascript' src='lib/qunit-junit-outputter.js'></script>
2727
<script type='text/javascript' src='../stacktrace.js'></script>
28-
<script type='text/javascript' src='CapturedExceptions.js'></script>
28+
<script type='text/javascript' src='CapturedExceptions.js'></script>
2929
<script type='text/javascript' src='TestStacktrace.js'></script>
3030
</head>
3131
<body>

test/TestStacktrace.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@
711711
});
712712

713713
test("guessAnonymousFunctions opera10", function() {
714-
// TODO currently failing in Opera 10.60
714+
// FIXME: currently failing in Opera 10.60
715715
var results = [], p = new printStackTrace.implementation();
716716
var file = 'http://' + window.location.hostname + '/file.js';
717717
p.sourceCache[file] = ['var f2 = function() {', 'var b = 2;', '};'];

test/lib/JsTestDriver-1.3.3d.jar

4.09 MB
Binary file not shown.

test/lib/QUnitAdapter.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
QUnitAdapter
3+
Version: 1.1.0
4+
5+
Run qunit tests using JS Test Driver
6+
7+
This provides almost the same api as qunit.
8+
9+
Tests must run sychronously, which means no use of stop and start methods.
10+
You can use jsUnit Clock object to deal with timeouts and intervals:
11+
http://googletesting.blogspot.com/2007/03/javascript-simulating-time-in-jsunit.html
12+
13+
The qunit #main DOM element is not included. If you need to do any DOM manipulation
14+
you need to set it up and tear it down in each test.
15+
16+
*/
17+
(function() {
18+
19+
if(!(window.equiv)) {
20+
throw new Error("QUnitAdapter.js - Unable to find equiv function. Ensure you have added equiv.js to the load section of your jsTestDriver.conf");
21+
}
22+
23+
var QUnitTestCase;
24+
25+
window.module = function(name, lifecycle) {
26+
QUnitTestCase = TestCase(name);
27+
QUnitTestCase.prototype.lifecycle = lifecycle || {};
28+
};
29+
30+
window.test = function(name, expected, test) {
31+
QUnitTestCase.prototype['test ' + name] = function() {
32+
if(this.lifecycle.setup) {
33+
this.lifecycle.setup();
34+
}
35+
if(expected.constructor === Number) {
36+
expectAsserts(expected);
37+
} else {
38+
test = expected;
39+
}
40+
test.call(this.lifecycle);
41+
42+
if(this.lifecycle.teardown) {
43+
this.lifecycle.teardown();
44+
}
45+
};
46+
};
47+
48+
window.expect = function(count) {
49+
expectAsserts(count);
50+
};
51+
52+
window.ok = function(actual, msg) {
53+
assertTrue(msg ? msg : '', !!actual);
54+
};
55+
56+
window.equals = function(a, b, msg) {
57+
assertEquals(msg ? msg : '', b, a);
58+
};
59+
60+
window.start = window.stop = function() {
61+
fail('start and stop methods are not available when using JS Test Driver.\n' +
62+
'Use jsUnit Clock object to deal with timeouts and intervals:\n' +
63+
'http://googletesting.blogspot.com/2007/03/javascript-simulating-time-in-jsunit.html.');
64+
};
65+
66+
window.same = function(a, b, msg) {
67+
assertTrue(msg ? msg : '', window.equiv(b, a));
68+
};
69+
70+
window.reset = function() {
71+
fail('reset method is not available when using JS Test Driver');
72+
};
73+
74+
window.isLocal = function() {
75+
return false;
76+
};
77+
78+
window.QUnit = {
79+
equiv: window.equiv,
80+
ok: window.ok
81+
};
82+
83+
module('Default Module');
84+
85+
})();

test/lib/equiv.js

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
2+
// Tests for equality any JavaScript type and structure without unexpected results.
3+
// Discussions and reference: http://philrathe.com/articles/equiv
4+
// Test suites: http://philrathe.com/tests/equiv
5+
// Author: Philippe RathŽ <prathe@gmail.com>
6+
window.equiv = function () {
7+
8+
var innerEquiv; // the real equiv function
9+
var callers = []; // stack to decide between skip/abort functions
10+
11+
// Determine what is o.
12+
function hoozit(o) {
13+
if (typeof o === "string") {
14+
return "string";
15+
16+
} else if (typeof o === "boolean") {
17+
return "boolean";
18+
19+
} else if (typeof o === "number") {
20+
21+
if (isNaN(o)) {
22+
return "nan";
23+
} else {
24+
return "number";
25+
}
26+
27+
} else if (typeof o === "undefined") {
28+
return "undefined";
29+
30+
// consider: typeof null === object
31+
} else if (o === null) {
32+
return "null";
33+
34+
// consider: typeof [] === object
35+
} else if (o instanceof Array) {
36+
return "array";
37+
38+
// consider: typeof new Date() === object
39+
} else if (o instanceof Date) {
40+
return "date";
41+
42+
// consider: /./ instanceof Object;
43+
// /./ instanceof RegExp;
44+
// typeof /./ === "function"; // => false in IE and Opera,
45+
// true in FF and Safari
46+
} else if (o instanceof RegExp) {
47+
return "regexp";
48+
49+
} else if (typeof o === "object") {
50+
return "object";
51+
52+
} else if (o instanceof Function) {
53+
return "function";
54+
}
55+
}
56+
57+
// Call the o related callback with the given arguments.
58+
function bindCallbacks(o, callbacks, args) {
59+
var prop = hoozit(o);
60+
if (prop) {
61+
if (hoozit(callbacks[prop]) === "function") {
62+
return callbacks[prop].apply(callbacks, args);
63+
} else {
64+
return callbacks[prop]; // or undefined
65+
}
66+
}
67+
}
68+
69+
var callbacks = function () {
70+
71+
// for string, boolean, number and null
72+
function useStrictEquality(b, a) {
73+
return a === b;
74+
}
75+
76+
return {
77+
"string": useStrictEquality,
78+
"boolean": useStrictEquality,
79+
"number": useStrictEquality,
80+
"null": useStrictEquality,
81+
"undefined": useStrictEquality,
82+
83+
"nan": function (b) {
84+
return isNaN(b);
85+
},
86+
87+
"date": function (b, a) {
88+
return hoozit(b) === "date" && a.valueOf() === b.valueOf();
89+
},
90+
91+
"regexp": function (b, a) {
92+
return hoozit(b) === "regexp" &&
93+
a.source === b.source && // the regex itself
94+
a.global === b.global && // and its modifers (gmi) ...
95+
a.ignoreCase === b.ignoreCase &&
96+
a.multiline === b.multiline;
97+
},
98+
99+
// - skip when the property is a method of an instance (OOP)
100+
// - abort otherwise,
101+
// initial === would have catch identical references anyway
102+
"function": function () {
103+
var caller = callers[callers.length - 1];
104+
return caller !== Object &&
105+
typeof caller !== "undefined";
106+
},
107+
108+
"array": function (b, a) {
109+
var i;
110+
var len;
111+
112+
// b could be an object literal here
113+
if ( ! (hoozit(b) === "array")) {
114+
return false;
115+
}
116+
117+
len = a.length;
118+
if (len !== b.length) { // safe and faster
119+
return false;
120+
}
121+
for (i = 0; i < len; i++) {
122+
if( ! innerEquiv(a[i], b[i])) {
123+
return false;
124+
}
125+
}
126+
return true;
127+
},
128+
129+
"object": function (b, a) {
130+
var i;
131+
var eq = true; // unless we can proove it
132+
var aProperties = [], bProperties = []; // collection of strings
133+
134+
// comparing constructors is more strict than using instanceof
135+
if ( a.constructor !== b.constructor) {
136+
return false;
137+
}
138+
139+
// stack constructor before traversing properties
140+
callers.push(a.constructor);
141+
142+
for (i in a) { // be strict: don't ensures hasOwnProperty and go deep
143+
144+
aProperties.push(i); // collect a's properties
145+
146+
if ( ! innerEquiv(a[i], b[i])) {
147+
eq = false;
148+
}
149+
}
150+
151+
callers.pop(); // unstack, we are done
152+
153+
for (i in b) {
154+
bProperties.push(i); // collect b's properties
155+
}
156+
157+
// Ensures identical properties name
158+
return eq && innerEquiv(aProperties.sort(), bProperties.sort());
159+
}
160+
};
161+
}();
162+
163+
innerEquiv = function () { // can take multiple arguments
164+
var args = Array.prototype.slice.apply(arguments);
165+
if (args.length < 2) {
166+
return true; // end transition
167+
}
168+
169+
return (function (a, b) {
170+
if (a === b) {
171+
return true; // catch the most you can
172+
173+
} else if (typeof a !== typeof b || a === null || b === null || typeof a === "undefined" || typeof b === "undefined") {
174+
return false; // don't lose time with error prone cases
175+
176+
} else {
177+
return bindCallbacks(a, callbacks, [b, a]);
178+
}
179+
180+
// apply transition with (1..n) arguments
181+
})(args[0], args[1]) && arguments.callee.apply(this, args.splice(1, args.length -1));
182+
};
183+
184+
return innerEquiv;
185+
}(); // equiv
File renamed without changes.

0 commit comments

Comments
 (0)