Skip to content

Commit 5fee7a6

Browse files
committed
Draft Error parsers for V8 and Nitro
1 parent aaa6f28 commit 5fee7a6

File tree

3 files changed

+460
-0
lines changed

3 files changed

+460
-0
lines changed

spec/captured-errors.js

Lines changed: 270 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,270 @@
1+
/* exported CapturedExceptions */
2+
var CapturedExceptions = {};
3+
4+
CapturedExceptions.OPERA_854 = {
5+
message: "Statement on line 44: Type mismatch (usually a non-object value used where an object is required)\n" +
6+
"Backtrace:\n" +
7+
" Line 44 of linked script file://localhost/G:/js/stacktrace.js\n" +
8+
" this.undef();\n" +
9+
" Line 31 of linked script file://localhost/G:/js/stacktrace.js\n" +
10+
" ex = ex || this.createException();\n" +
11+
" Line 18 of linked script file://localhost/G:/js/stacktrace.js\n" +
12+
" var p = new printStackTrace.implementation(), result = p.run(ex);\n" +
13+
" Line 4 of inline#1 script in file://localhost/G:/js/file.js\n" +
14+
" printTrace(printStackTrace());\n" +
15+
" Line 7 of inline#1 script in file://localhost/G:/js/file.js\n" +
16+
" bar(n - 1);\n" +
17+
" Line 11 of inline#1 script in file://localhost/G:/js/file.js\n" +
18+
" bar(2);\n" +
19+
" Line 15 of inline#1 script in file://localhost/G:/js/file.js\n" +
20+
" foo();\n" +
21+
"",
22+
'opera#sourceloc': 44
23+
};
24+
25+
CapturedExceptions.OPERA_902 = {
26+
message: "Statement on line 44: Type mismatch (usually a non-object value used where an object is required)\n" +
27+
"Backtrace:\n" +
28+
" Line 44 of linked script file://localhost/G:/js/stacktrace.js\n" +
29+
" this.undef();\n" +
30+
" Line 31 of linked script file://localhost/G:/js/stacktrace.js\n" +
31+
" ex = ex || this.createException();\n" +
32+
" Line 18 of linked script file://localhost/G:/js/stacktrace.js\n" +
33+
" var p = new printStackTrace.implementation(), result = p.run(ex);\n" +
34+
" Line 4 of inline#1 script in file://localhost/G:/js/file.js\n" +
35+
" printTrace(printStackTrace());\n" +
36+
" Line 7 of inline#1 script in file://localhost/G:/js/file.js\n" +
37+
" bar(n - 1);\n" +
38+
" Line 11 of inline#1 script in file://localhost/G:/js/file.js\n" +
39+
" bar(2);\n" +
40+
" Line 15 of inline#1 script in file://localhost/G:/js/file.js\n" +
41+
" foo();\n" +
42+
"",
43+
'opera#sourceloc': 44
44+
};
45+
46+
CapturedExceptions.OPERA_927 = {
47+
message: "Statement on line 43: Type mismatch (usually a non-object value used where an object is required)\n" +
48+
"Backtrace:\n" +
49+
" Line 43 of linked script file://localhost/G:/js/stacktrace.js\n" +
50+
" this.undef();\n" +
51+
" Line 31 of linked script file://localhost/G:/js/stacktrace.js\n" +
52+
" ex = ex || this.createException();\n" +
53+
" Line 18 of linked script file://localhost/G:/js/stacktrace.js\n" +
54+
" var p = new printStackTrace.implementation(), result = p.run(ex);\n" +
55+
" Line 4 of inline#1 script in file://localhost/G:/js/file.js\n" +
56+
" printTrace(printStackTrace());\n" +
57+
" Line 7 of inline#1 script in file://localhost/G:/js/file.js\n" +
58+
" bar(n - 1);\n" +
59+
" Line 11 of inline#1 script in file://localhost/G:/js/file.js\n" +
60+
" bar(2);\n" +
61+
" Line 15 of inline#1 script in file://localhost/G:/js/file.js\n" +
62+
" foo();\n" +
63+
"",
64+
'opera#sourceloc': 43
65+
};
66+
67+
CapturedExceptions.OPERA_964 = {
68+
message: "Statement on line 42: Type mismatch (usually non-object value supplied where object required)\n" +
69+
"Backtrace:\n" +
70+
" Line 42 of linked script file://localhost/G:/js/stacktrace.js\n" +
71+
" this.undef();\n" +
72+
" Line 27 of linked script file://localhost/G:/js/stacktrace.js\n" +
73+
" ex = ex || this.createException();\n" +
74+
" Line 18 of linked script file://localhost/G:/js/stacktrace.js: In function printStackTrace\n" +
75+
" var p = new printStackTrace.implementation(), result = p.run(ex);\n" +
76+
" Line 4 of inline#1 script in file://localhost/G:/js/file.js: In function bar\n" +
77+
" printTrace(printStackTrace());\n" +
78+
" Line 7 of inline#1 script in file://localhost/G:/js/file.js: In function bar\n" +
79+
" bar(n - 1);\n" +
80+
" Line 11 of inline#1 script in file://localhost/G:/js/file.js: In function foo\n" +
81+
" bar(2);\n" +
82+
" Line 15 of inline#1 script in file://localhost/G:/js/file.js\n" +
83+
" foo();\n" +
84+
"",
85+
'opera#sourceloc': 42,
86+
stacktrace: " ... Line 27 of linked script file://localhost/G:/js/stacktrace.js\n" +
87+
" ex = ex || this.createException();\n" +
88+
" Line 18 of linked script file://localhost/G:/js/stacktrace.js: In function printStackTrace\n" +
89+
" var p = new printStackTrace.implementation(), result = p.run(ex);\n" +
90+
" Line 4 of inline#1 script in file://localhost/G:/js/file.js: In function bar\n" +
91+
" printTrace(printStackTrace());\n" +
92+
" Line 7 of inline#1 script in file://localhost/G:/js/file.js: In function bar\n" +
93+
" bar(n - 1);\n" +
94+
" Line 11 of inline#1 script in file://localhost/G:/js/file.js: In function foo\n" +
95+
" bar(2);\n" +
96+
" Line 15 of inline#1 script in file://localhost/G:/js/file.js\n" +
97+
" foo();\n" +
98+
""
99+
};
100+
101+
CapturedExceptions.OPERA_1010 = {
102+
message: "Statement on line 42: Type mismatch (usually non-object value supplied where object required)",
103+
'opera#sourceloc': 42,
104+
stacktrace: " Line 42 of linked script file://localhost/G:/js/stacktrace.js\n" +
105+
" this.undef();\n" +
106+
" Line 27 of linked script file://localhost/G:/js/stacktrace.js\n" +
107+
" ex = ex || this.createException();\n" +
108+
" Line 18 of linked script file://localhost/G:/js/stacktrace.js: In function printStackTrace\n" +
109+
" var p = new printStackTrace.implementation(), result = p.run(ex);\n" +
110+
" Line 4 of inline#1 script in file://localhost/G:/js/file.js: In function bar\n" +
111+
" printTrace(printStackTrace());\n" +
112+
" Line 7 of inline#1 script in file://localhost/G:/js/file.js: In function bar\n" +
113+
" bar(n - 1);\n" +
114+
" Line 11 of inline#1 script in file://localhost/G:/js/file.js: In function foo\n" +
115+
" bar(2);\n" +
116+
" Line 15 of inline#1 script in file://localhost/G:/js/file.js\n" +
117+
" foo();\n" +
118+
""
119+
};
120+
121+
CapturedExceptions.OPERA_1063 = {
122+
message: "'this.undef' is not a function",
123+
stack: "<anonymous function: createException>([arguments not available])@file://localhost/G:/js/stacktrace.js:42\n" +
124+
"<anonymous function: run>([arguments not available])@file://localhost/G:/js/stacktrace.js:27\n" +
125+
"printStackTrace([arguments not available])@file://localhost/G:/js/stacktrace.js:18\n" +
126+
"bar([arguments not available])@file://localhost/G:/js/file.js:4\n" +
127+
"bar([arguments not available])@file://localhost/G:/js/file.js:7\n" +
128+
"foo([arguments not available])@file://localhost/G:/js/file.js:11\n" +
129+
"@file://localhost/G:/js/file.js:15",
130+
stacktrace: "<anonymous function: createException>([arguments not available])@file://localhost/G:/js/stacktrace.js:42\n" +
131+
"<anonymous function: run>([arguments not available])@file://localhost/G:/js/stacktrace.js:27\n" +
132+
"printStackTrace([arguments not available])@file://localhost/G:/js/stacktrace.js:18\n" +
133+
"bar([arguments not available])@file://localhost/G:/js/file.js:4\n" +
134+
"bar([arguments not available])@file://localhost/G:/js/file.js:7\n" +
135+
"foo([arguments not available])@file://localhost/G:/js/file.js:11\n" +
136+
"@file://localhost/G:/js/file.js:15"
137+
};
138+
139+
CapturedExceptions.OPERA_1111 = {
140+
message: "'this.undef' is not a function",
141+
stack: "<anonymous function: createException>([arguments not available])@file://localhost/G:/js/stacktrace.js:42\n" +
142+
"<anonymous function: run>([arguments not available])@file://localhost/G:/js/stacktrace.js:27\n" +
143+
"printStackTrace([arguments not available])@file://localhost/G:/js/stacktrace.js:18\n" +
144+
"bar([arguments not available])@file://localhost/G:/js/file.js:4\n" +
145+
"bar([arguments not available])@file://localhost/G:/js/file.js:7\n" +
146+
"foo([arguments not available])@file://localhost/G:/js/file.js:11\n" +
147+
"@file://localhost/G:/js/file.js:15",
148+
stacktrace: "Error thrown at line 42, column 12 in <anonymous function: createException>() in file://localhost/G:/js/stacktrace.js:\n" +
149+
" this.undef();\n" +
150+
"called from line 27, column 8 in <anonymous function: run>(ex) in file://localhost/G:/js/stacktrace.js:\n" +
151+
" ex = ex || this.createException();\n" +
152+
"called from line 18, column 4 in printStackTrace(options) in file://localhost/G:/js/stacktrace.js:\n" +
153+
" var p = new printStackTrace.implementation(), result = p.run(ex);\n" +
154+
"called from line 4, column 5 in bar(n) in file://localhost/G:/js/file.js:\n" +
155+
" printTrace(printStackTrace());\n" +
156+
"called from line 7, column 4 in bar(n) in file://localhost/G:/js/file.js:\n" +
157+
" bar(n - 1);\n" +
158+
"called from line 11, column 4 in foo() in file://localhost/G:/js/file.js:\n" +
159+
" bar(2);\n" +
160+
"called from line 15, column 3 in file://localhost/G:/js/file.js:\n" +
161+
" foo();"
162+
};
163+
164+
CapturedExceptions.OPERA_1151 = {
165+
message: "'this.undef' is not a function",
166+
stack: "<anonymous function: createException>([arguments not available])@file://localhost/G:/js/stacktrace.js:42\n" +
167+
"<anonymous function: run>([arguments not available])@file://localhost/G:/js/stacktrace.js:27\n" +
168+
"printStackTrace([arguments not available])@file://localhost/G:/js/stacktrace.js:18\n" +
169+
"bar([arguments not available])@file://localhost/G:/js/file.js:4\n" +
170+
"bar([arguments not available])@file://localhost/G:/js/file.js:7\n" +
171+
"foo([arguments not available])@file://localhost/G:/js/file.js:11\n" +
172+
"@file://localhost/G:/js/file.js:15",
173+
stacktrace: "Error thrown at line 42, column 12 in <anonymous function: createException>() in file://localhost/G:/js/stacktrace.js:\n" +
174+
" this.undef();\n" +
175+
"called from line 27, column 8 in <anonymous function: run>(ex) in file://localhost/G:/js/stacktrace.js:\n" +
176+
" ex = ex || this.createException();\n" +
177+
"called from line 18, column 4 in printStackTrace(options) in file://localhost/G:/js/stacktrace.js:\n" +
178+
" var p = new printStackTrace.implementation(), result = p.run(ex);\n" +
179+
"called from line 4, column 5 in bar(n) in file://localhost/G:/js/file.js:\n" +
180+
" printTrace(printStackTrace());\n" +
181+
"called from line 7, column 4 in bar(n) in file://localhost/G:/js/file.js:\n" +
182+
" bar(n - 1);\n" +
183+
"called from line 11, column 4 in foo() in file://localhost/G:/js/file.js:\n" +
184+
" bar(2);\n" +
185+
"called from line 15, column 3 in file://localhost/G:/js/file.js:\n" +
186+
" foo();"
187+
};
188+
189+
CapturedExceptions.CHROME_15 = {
190+
'arguments': ["undef"],
191+
message: "Object #<Object> has no method 'undef'",
192+
stack: "TypeError: Object #<Object> has no method 'undef'\n" +
193+
" at bar (scheme://path/to/file.js:13:17)\n" +
194+
" at bar (scheme://path/to/file.js:16:5)\n" +
195+
" at foo (scheme://path/to/file.js:20:5)\n" +
196+
" at scheme://path/to/file.js:24:4"
197+
};
198+
199+
CapturedExceptions.FIREFOX_36 = {
200+
fileName: "http://127.0.0.1:8000/js/stacktrace.js",
201+
lineNumber: 44,
202+
message: "this.undef is not a function",
203+
name: "TypeError",
204+
stack: "()@http://127.0.0.1:8000/js/stacktrace.js:44\n" +
205+
"(null)@http://127.0.0.1:8000/js/stacktrace.js:31\n" +
206+
"printStackTrace()@http://127.0.0.1:8000/js/stacktrace.js:18\n" +
207+
"bar(1)@http://127.0.0.1:8000/js/file.js:13\n" +
208+
"bar(2)@http://127.0.0.1:8000/js/file.js:16\n" +
209+
"foo()@http://127.0.0.1:8000/js/file.js:20\n" +
210+
"@http://127.0.0.1:8000/js/file.js:24\n" +
211+
""
212+
};
213+
214+
CapturedExceptions.FIREFOX_36_FILE = {
215+
fileName: "file:///home/user/js/stacktrace.js",
216+
lineNumber: 44,
217+
message: "this.undef is not a function",
218+
name: "TypeError",
219+
stack: "()@file:///home/user/js/stacktrace.js:44\n" +
220+
"(null)@file:///home/user/js/stacktrace.js:31\n" +
221+
"printStackTrace()@file:///home/user/js/stacktrace.js:18\n" +
222+
"bar(1)@file:///home/user/js/file.js:13\n" +
223+
"bar(2)@file:///home/user/js/file.js:16\n" +
224+
"foo()@file:///home/user/js/file.js:20\n" +
225+
"@file:///home/user/js/file.js:24\n" +
226+
""
227+
};
228+
229+
CapturedExceptions.FIREFOX_7 = {
230+
fileName: "file:///G:/js/stacktrace.js",
231+
lineNumber: 44,
232+
stack: "()@file:///G:/js/stacktrace.js:44\n" +
233+
"(null)@file:///G:/js/stacktrace.js:31\n" +
234+
"printStackTrace()@file:///G:/js/stacktrace.js:18\n" +
235+
"bar(1)@file:///G:/js/file.js:13\n" +
236+
"bar(2)@file:///G:/js/file.js:16\n" +
237+
"foo()@file:///G:/js/file.js:20\n" +
238+
"@file:///G:/js/file.js:24\n" +
239+
""
240+
};
241+
242+
CapturedExceptions.FIREFOX_14 = {
243+
message: "x is null",
244+
stack: "@scheme://path/to/file.js:48\n" +
245+
"dumpException3@scheme://path/to/file.js:52\n" +
246+
"onclick@scheme://path/to/file.js:1\n" +
247+
"",
248+
fileName: "scheme://path/to/file.js",
249+
lineNumber: 48
250+
};
251+
252+
CapturedExceptions.SAFARI_6 = {
253+
message: "'null' is not an object (evaluating 'x.undef')",
254+
stack: "@scheme://path/to/file.js:48\n" +
255+
"dumpException3@scheme://path/to/file.js:52\n" +
256+
"onclick@scheme://path/to/file.js:82\n" +
257+
"[native code]",
258+
line: 48,
259+
sourceURL: "scheme://path/to/file.js"
260+
};
261+
262+
CapturedExceptions.IE_10 = {
263+
message: "Unable to get property 'undef' of undefined or null reference",
264+
stack: "TypeError: Unable to get property 'undef' of undefined or null reference\n" +
265+
" at Anonymous function (scheme://path/to/file.js:48:13)\n" +
266+
" at dumpException3 (scheme://path/to/file.js:46:9)\n" +
267+
" at onclick (scheme://path/to/file.js:82:1)",
268+
description: "Unable to get property 'undef' of undefined or null reference",
269+
number: -2146823281
270+
};

spec/stack-parser-spec.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/* global ErrorParser: false, CapturedExceptions: false */
2+
3+
describe('error-parser.js', function() {
4+
describe('ErrorParser', function() {
5+
describe('#chooseParser', function() {
6+
var unit = new ErrorParser();
7+
it('should detect V8', function() {
8+
expect(unit.chooseParser(CapturedExceptions.CHROME_15)).toBe(unit.parseV8);
9+
});
10+
it('should detect Firefox', function() {
11+
expect(unit.chooseParser(CapturedExceptions.FIREFOX_36)).toBe(unit.parseSpiderMonkey);
12+
expect(unit.chooseParser(CapturedExceptions.FIREFOX_7)).toBe(unit.parseSpiderMonkey);
13+
expect(unit.chooseParser(CapturedExceptions.FIREFOX_14)).toBe(unit.parseSpiderMonkey);
14+
});
15+
it('should detect Safari', function() {
16+
expect(unit.chooseParser(CapturedExceptions.SAFARI_6)).toBe(unit.parseNitro);
17+
});
18+
it('should detect IE', function() {
19+
expect(unit.chooseParser(CapturedExceptions.IE_10)).toBe(unit.parseChakra);
20+
});
21+
it('should detect Opera', function() {
22+
expect(unit.chooseParser(CapturedExceptions.OPERA_854)).toBe(unit.parseOPERA);
23+
expect(unit.chooseParser(CapturedExceptions.OPERA_902)).toBe(unit.parseOPERA);
24+
expect(unit.chooseParser(CapturedExceptions.OPERA_927)).toBe(unit.parseOPERA);
25+
expect(unit.chooseParser(CapturedExceptions.OPERA_1010)).toBe(unit.parseOPERA);
26+
expect(unit.chooseParser(CapturedExceptions.OPERA_1063)).toBe(unit.parseOPERA);
27+
expect(unit.chooseParser(CapturedExceptions.OPERA_1111)).toBe(unit.parseOPERA);
28+
expect(unit.chooseParser(CapturedExceptions.OPERA_1151)).toBe(unit.parseOPERA);
29+
});
30+
});
31+
32+
describe('#parseNitro', function() {
33+
var unit = new ErrorParser();
34+
it('should parse Safari 6 Errors', function() {
35+
var errorInfo = unit.parseNitro(CapturedExceptions.SAFARI_6);
36+
expect(errorInfo.stack).toBeTruthy();
37+
expect(errorInfo.stack.length).toBe(3);
38+
expect(errorInfo.stack[0]).toEqual({fn: '{anonymous}', args: [], src: 'scheme://path/to/file.js', line: '48', column: undefined});
39+
expect(errorInfo.stack[1]).toEqual({fn: 'dumpException3', args: [], src: 'scheme://path/to/file.js', line: '52', column: undefined});
40+
expect(errorInfo.stack[2]).toEqual({fn: 'onclick', args: [], src: 'scheme://path/to/file.js', line: '82', column: undefined});
41+
expect(errorInfo.message).toBeTruthy();
42+
expect(errorInfo.message).toEqual("'null' is not an object (evaluating 'x.undef')");
43+
});
44+
});
45+
46+
describe('#parseV8', function() {
47+
var unit = new ErrorParser();
48+
it('should parse V8 Errors', function() {
49+
var errorInfo = unit.parseV8(CapturedExceptions.CHROME_15);
50+
expect(errorInfo.stack).toBeTruthy();
51+
expect(errorInfo.stack[0]).toEqual({fn: 'bar', args: [], src: 'scheme://path/to/file.js', line: '13', column: '17'});
52+
expect(errorInfo.stack[1]).toEqual({fn: 'bar', args: [], src: 'scheme://path/to/file.js', line: '16', column: '5'});
53+
expect(errorInfo.stack[2]).toEqual({fn: 'foo', args: [], src: 'scheme://path/to/file.js', line: '20', column: '5'});
54+
expect(errorInfo.stack[3]).toEqual({fn: '{anonymous}', args: [], src: 'scheme://path/to/file.js', line: '24', column: '4'});
55+
expect(errorInfo.stack.length).toBe(4);
56+
});
57+
});
58+
59+
describe('#parseChakra', function() {
60+
61+
});
62+
});
63+
});

0 commit comments

Comments
 (0)