| <html> |
| <head> |
| <script src="../../http/tests/inspector/resources/inspector-test.js"></script> |
| <script> |
| function typeErrorWrap() |
| { |
| return typeError(); |
| } |
| |
| function typeError() |
| { |
| var object = {}; |
| try { |
| object.propertyDoesnt.exist; |
| } catch (e) { |
| console.trace(); |
| return e.stack; |
| } |
| } |
| |
| function testWithNativeCallInBetween() |
| { |
| return [42].map(typeError)[0]; |
| } |
| |
| var _anonymousFunctionError = null; |
| |
| (function() { |
| var object = {}; |
| try { |
| object.methodDoesntExist(); |
| } catch (e) { |
| _anonymousFunctionError = e.stack; |
| } |
| })(); |
| |
| function getAnonymousFunctionError() { |
| return _anonymousFunctionError; |
| } |
| |
| |
| function test() |
| { |
| WebInspector.logManager.addEventListener(WebInspector.LogManager.Event.MessageAdded, function(event) { |
| InspectorTest.log("\nconsole.trace():"); |
| |
| var stackTrace = []; |
| var callFramesBeforeEval = stripCallFramesAfterEval(event.data.message.stackTrace.callFrames); |
| for (var callFrame of callFramesBeforeEval) { |
| var lineNumber = callFrame.sourceCodeLocation ? callFrame.sourceCodeLocation.lineNumber : null; |
| var columnNumber = callFrame.sourceCodeLocation ? callFrame.sourceCodeLocation.columnNumber : null; |
| stackTrace.push({ |
| lineNumber: lineNumber, |
| columnNumber: columnNumber, |
| functionName: callFrame.functionName, |
| nativeCode: callFrame.nativeCode, |
| programCode: callFrame.programCode, |
| }); |
| } |
| |
| InspectorTest.log(JSON.stringify(stackTrace, null, 4)); |
| }); |
| |
| InspectorTest.evaluateInPage("typeErrorWrap()", function(error, result) { |
| InspectorTest.log("\nError object:"); |
| |
| if (error) |
| InspectorTest.log(error); |
| |
| var stackTrace = stripPayloadAfterEval(WebInspector.StackTrace._parseStackTrace(result.value)); |
| stackTrace = stripFilePaths(stackTrace); |
| |
| InspectorTest.log(JSON.stringify(stackTrace, null, 4)); |
| InspectorTest.completeTest(); |
| }); |
| |
| InspectorTest.evaluateInPage("testWithNativeCallInBetween()", function(error, result) { |
| InspectorTest.log("\nError object:"); |
| |
| if (error) |
| InspectorTest.log(error); |
| |
| var stackTrace = stripPayloadAfterEval(WebInspector.StackTrace._parseStackTrace(result.value)); |
| stackTrace = stripFilePaths(stackTrace); |
| |
| InspectorTest.log(JSON.stringify(stackTrace, null, 4)); |
| InspectorTest.completeTest(); |
| }); |
| |
| InspectorTest.evaluateInPage("getAnonymousFunctionError()", function(error, result) { |
| InspectorTest.log("\nError object:"); |
| |
| if (error) |
| InspectorTest.log(error); |
| |
| var stackTrace = stripPayloadAfterEval(WebInspector.StackTrace._parseStackTrace(result.value)); |
| stackTrace = stripFilePaths(stackTrace); |
| |
| InspectorTest.log(JSON.stringify(stackTrace, null, 4)); |
| InspectorTest.completeTest(); |
| }); |
| |
| function stripFilePaths(stackTrace) |
| { |
| for (var frame of stackTrace) { |
| if (typeof frame.url === "string") |
| frame.url = frame.url.replace(/^.+?LayoutTests/, ""); |
| } |
| return stackTrace; |
| } |
| |
| function stripCallFramesAfterEval(stackTrace) |
| { |
| var index = 0; |
| for (var frame of stackTrace) { |
| index++; |
| if (frame.programCode) |
| break; |
| } |
| return stackTrace.slice(0, index); |
| } |
| |
| function stripPayloadAfterEval(payload) |
| { |
| var index = 0; |
| for (var frame of payload) { |
| index++; |
| if (frame.functionName === "eval code") |
| break; |
| } |
| return payload.slice(0, index); |
| } |
| } |
| </script> |
| </head> |
| <body onload="runTest()"> |
| <p> |
| Test that the inspector can parse the stack trace format used by JSC for Error instances and console.trace.<br> |
| </p> |
| </body> |
| </html> |