|
129 | 129 |
|
130 | 130 | test("function instrumentation", function() { |
131 | 131 | expect(4); |
| 132 | + var p = printStackTrace.implementation.prototype; |
132 | 133 | this.toInstrument = function() { equals(1, 1, 'called instrumented function'); }; |
133 | 134 | this.callback = function(stacktrace) { ok(typeof stacktrace !== 'undefined', 'called callback'); }; |
134 | | - printStackTrace.implementation.prototype.instrumentFunction(this, 'toInstrument', this.callback); |
| 135 | + p.instrumentFunction(this, 'toInstrument', this.callback); |
135 | 136 | ok(this.toInstrument._instrumented, 'function instrumented'); |
136 | 137 | this.toInstrument(); |
137 | | - printStackTrace.implementation.prototype.deinstrumentFunction(this, 'toInstrument'); |
| 138 | + p.deinstrumentFunction(this, 'toInstrument'); |
138 | 139 | ok(!this.toInstrument._instrumented, 'function deinstrumented'); |
139 | 140 | this.toInstrument = this.callback = null; |
140 | 141 | }); |
|
189 | 190 | }); |
190 | 191 |
|
191 | 192 | test("chrome", function() { |
192 | | - var mode = printStackTrace.implementation.prototype.mode(UnitTest.fn.createGenericError()); |
193 | | - var e = []; |
194 | | - e.push({ stack: 'ignored\n at f0 (file.js:132:3)\n at file.js:135:3\n at f1 (file.js:132:13)\n at file.js:135:23\n at Object.<anonymous> (file.js:137:9)\n at file.js:137:32 at process (file.js:594:22)'}); |
195 | | - if(mode == 'chrome') { |
196 | | - function f0() { |
197 | | - try {this.undef();} catch (exception) { |
198 | | - e.push(exception); |
199 | | - } |
| 193 | + var p = printStackTrace.implementation.prototype, e = [], ex; |
| 194 | + |
| 195 | + var stack = "TypeError: Object [object DOMWindow] has no method 'undef'\n" + |
| 196 | + " at f0 (test/test-stacktrace.js:198:20)\n" + |
| 197 | + " at f1 (test/test-stacktrace.js:203:10)\n" + |
| 198 | + " at test/test-stacktrace.js:206:10\n" + |
| 199 | + " at Object.<anonymous> (test/test-stacktrace.js:208:6)\n" + |
| 200 | + " at Object.run (test/qunit.js:89:18)\n" + |
| 201 | + " at test/qunit.js:214:10\n" + |
| 202 | + " at process (test/qunit.js:783:23)\n" + |
| 203 | + " at test/qunit.js:383:5"; |
| 204 | + e.push({ stack: stack}); // test saved Chrome stacktrace |
| 205 | + |
| 206 | + function f0() { |
| 207 | + try {this.undef();} catch (exception) { |
| 208 | + ex = exception; |
200 | 209 | } |
201 | | - function f1(arg1, arg2) { |
202 | | - f0(); |
203 | | - } |
204 | | - var f2 = function() { |
205 | | - f1(1, "abc"); |
206 | | - }; |
207 | | - f2(); |
208 | 210 | } |
209 | | - expect(4 * e.length); |
210 | | - for(var i = 0; i < e.length; i++) { |
211 | | - var message = printStackTrace.implementation.prototype.chrome(e[i]); |
212 | | - //equals(message.join("\n"), '', 'debug'); |
| 211 | + function f1(arg1, arg2) { |
| 212 | + f0(); |
| 213 | + } |
| 214 | + var f2 = function() { |
| 215 | + f1(1, "abc"); |
| 216 | + }; |
| 217 | + f2(); |
| 218 | + if (p.mode(ex) == 'chrome') {e.push(ex);} // test native Chrome stacktrace |
| 219 | + |
| 220 | + expect(3 * e.length); |
| 221 | + for (var i = 0; i < e.length; i++) { |
| 222 | + var message = p.chrome(e[i]); |
| 223 | + //equals(e[i].stack, '', 'original stack trace'); |
| 224 | + //equals(message.join("\n"), '', 'processed stack trace'); |
213 | 225 | equals(message[0].indexOf('f0') >= 0, true, 'f0 is top of stack'); |
214 | 226 | equals(message[1].indexOf('f1') >= 0, true, 'f1 is second called function'); |
215 | 227 | equals(message[2].indexOf('anonymous') >= 0, true, 'f2 anonymous function called'); |
216 | | - equals(message[3].indexOf('unknown source'), -1, 'unknown source discarded'); |
| 228 | + //equals(message[3].indexOf('unknown source'), -1, 'unknown source discarded'); |
217 | 229 | } |
218 | 230 | }); |
219 | 231 |
|
|
337 | 349 |
|
338 | 350 | test("stringify", function() { |
339 | 351 | expect(5); |
340 | | - equals(printStackTrace.implementation.prototype.stringifyArguments(["a", 1, {}, function() {}, undefined]), '"a",1,#object,#function,undefined'); |
341 | | - equals(printStackTrace.implementation.prototype.stringifyArguments([0, 1, 2, 3]), '0,1,2,3'); |
342 | | - equals(printStackTrace.implementation.prototype.stringifyArguments([['a', null]]), '["a",null]'); |
343 | | - equals(printStackTrace.implementation.prototype.stringifyArguments([[2, 4, 6, 8, 10, 12, 14]]), '[2...14]'); |
344 | | - equals(printStackTrace.implementation.prototype.stringifyArguments([]), ''); |
| 352 | + var p = printStackTrace.implementation.prototype; |
| 353 | + equals(p.stringifyArguments(["a", 1, {}, function() {}, undefined]), '"a",1,#object,#function,undefined'); |
| 354 | + equals(p.stringifyArguments([0, 1, 2, 3]), '0,1,2,3'); |
| 355 | + equals(p.stringifyArguments([['a', null]]), '["a",null]'); |
| 356 | + equals(p.stringifyArguments([[2, 4, 6, 8, 10, 12, 14]]), '[2...14]'); |
| 357 | + equals(p.stringifyArguments([]), ''); |
345 | 358 | }); |
346 | 359 |
|
347 | 360 | test("isSameDomain", function() { |
|
350 | 363 | }); |
351 | 364 |
|
352 | 365 | test("guessFunctionNameFromLines", function() { |
353 | | - expect(3); |
354 | | - equals(printStackTrace.implementation.prototype.guessFunctionNameFromLines(2, ['var a = function() {', 'var b = 2;', '};']), 'a'); |
355 | | - equals(printStackTrace.implementation.prototype.guessFunctionNameFromLines(2, ['function a() {', 'var b = 2;', '};']), 'a'); |
356 | | - equals(printStackTrace.implementation.prototype.guessFunctionNameFromLines(2, ['var a = 1;', 'var b = 2;', 'var c = 3;']), '(?)'); |
| 366 | + expect(5); |
| 367 | + var p = printStackTrace.implementation.prototype; |
| 368 | + equals(p.guessFunctionNameFromLines(['var a = function aa() {', 'var b = 2;', '};'], 2), 'a'); |
| 369 | + equals(p.guessFunctionNameFromLines(['var a = function () {', 'var b = 2;', '};'], 2), 'a'); |
| 370 | + equals(p.guessFunctionNameFromLines(['var a = function() {', 'var b = 2;', '};'], 2), 'a'); |
| 371 | + equals(p.guessFunctionNameFromLines(['function a() {', 'var b = 2;', '};'], 2), 'a'); |
| 372 | + equals(p.guessFunctionNameFromLines(['var a = 1;', 'var b = 2;', 'var c = 3;'], 2), '(?)'); |
357 | 373 | }); |
358 | 374 |
|
359 | 375 | test("getSource cache miss", function() { |
360 | 376 | expect(3); |
361 | | - var p = new printStackTrace.implementation(); |
362 | | - var file = 'file:///test'; |
| 377 | + var p = new printStackTrace.implementation(), file = 'file:///test', lines; |
363 | 378 | p.ajax = function(fileArg, callback) { |
364 | 379 | equals(fileArg, file, 'cache miss'); |
365 | 380 | return 'line0\nline1\n'; |
366 | 381 | }; |
367 | | - var lines = p.getSource(file); |
| 382 | + lines = p.getSource(file); |
368 | 383 | equals(lines[0], 'line0'); |
369 | 384 | equals(lines[1], 'line1'); |
370 | 385 | }); |
371 | 386 |
|
372 | 387 | test("getSource cache hit", function() { |
373 | 388 | expect(2); |
374 | | - var p = new printStackTrace.implementation(); |
375 | | - var file = 'file:///test'; |
| 389 | + var p = new printStackTrace.implementation(), file = 'file:///test', lines; |
376 | 390 | p.ajax = function(fileArg, callback) { |
377 | 391 | ok(false, 'not called'); |
378 | 392 | }; |
379 | 393 | p.sourceCache[file] = ['line0', 'line1']; |
380 | | - var lines = p.getSource(file); |
| 394 | + lines = p.getSource(file); |
381 | 395 | equals(lines[0], 'line0'); |
382 | 396 | equals(lines[1], 'line1'); |
383 | 397 | }); |
|
0 commit comments