Changeset 63805 in webkit
- Timestamp:
- Jul 20, 2010 11:53:12 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r63799 r63805 1 2010-07-20 Yury Semikhatsky <yurys@chromium.org> 2 3 Reviewed by Pavel Feldman. 4 5 console.assert should include stack trace with line numbers. 6 https://bugs.webkit.org/show_bug.cgi?id=22556 7 8 * inspector/console-assert-expected.txt: Added. 9 * inspector/console-assert.html: Added. 10 1 11 2010-07-20 Adam Barth <abarth@webkit.org> 2 12 -
trunk/WebCore/ChangeLog
r63804 r63805 1 2010-07-20 Yury Semikhatsky <yurys@chromium.org> 2 3 Reviewed by Pavel Feldman. 4 5 console.assert should include stack trace with line numbers. 6 https://bugs.webkit.org/show_bug.cgi?id=22556 7 8 Test: inspector/console-assert.html 9 10 * bindings/v8/ScriptCallStack.cpp: 11 (WebCore::getTopFrameLocation): 12 (WebCore::toScriptCallFramesVector): 13 (WebCore::ScriptCallStack::create): 14 (WebCore::ScriptCallStack::ScriptCallStack): 15 * bindings/v8/ScriptCallStack.h: 16 * bindings/v8/ScriptController.cpp: 17 (WebCore::ScriptController::setCaptureCallStackForUncaughtExceptions): 18 * bindings/v8/custom/V8ConsoleCustom.cpp: 19 (WebCore::V8Console::traceCallback): 20 (WebCore::V8Console::assertCallback): 21 * inspector/ConsoleMessage.cpp: 22 (WebCore::ConsoleMessage::ConsoleMessage): 23 * inspector/InspectorController.cpp: 24 (WebCore::InspectorController::addMessageToConsole): 25 * inspector/front-end/ConsoleView.js: 26 (WebInspector.ConsoleMessage.prototype._formatMessage): 27 (WebInspector.ConsoleMessage.prototype.toMessageElement): 28 * page/Console.cpp: 29 (WebCore::Console::lastWMLErrorMessage): 30 * page/Console.idl: 31 1 32 2010-07-20 Rafael Antognolli <antognolli@profusion.mobi> 2 33 -
trunk/WebCore/bindings/v8/ScriptCallStack.cpp
r63753 r63805 52 52 } 53 53 54 static void getTopFrameLocation(v8::Handle<v8::StackTrace> stackTrace, String* sourceName, int* sourceLineNumber, String* functionName) 55 { 56 if (stackTrace->GetFrameCount() <= 0) { 57 // Successfully grabbed stack trace, but there are no frames. It may happen in case of a syntax error for example. 58 // Fallback to setting lineNumber to 0, and source and function name to "undefined". 59 *sourceName = "undefined"; 60 *sourceLineNumber = 0; 61 *functionName = "undefined"; 62 } else { 63 v8::Handle<v8::StackFrame> frame = stackTrace->GetFrame(0); 64 getFrameLocation(frame, sourceName, sourceLineNumber, functionName); 65 } 66 } 67 54 68 static PassOwnPtr<ScriptCallFrame> toScriptCallFrame(v8::Handle<v8::StackFrame> frame) 55 69 { … … 61 75 } 62 76 63 PassOwnPtr<ScriptCallStack> ScriptCallStack::create(const v8::Arguments& arguments, unsigned skipArgumentCount) 77 static void toScriptCallFramesVector(v8::Local<v8::Context> context, v8::Handle<v8::StackTrace> stackTrace, Vector<OwnPtr<ScriptCallFrame> >& scriptCallFrames) 78 { 79 v8::Context::Scope contextScope(context); 80 int frameCount = stackTrace->GetFrameCount(); 81 for (int i = 0; i < frameCount; i++) { 82 v8::Local<v8::StackFrame> stackFrame = stackTrace->GetFrame(i); 83 scriptCallFrames.append(toScriptCallFrame(stackFrame)); 84 } 85 } 86 87 const int ScriptCallStack::maxCallStackSizeToCapture = 200; 88 89 PassOwnPtr<ScriptCallStack> ScriptCallStack::create(const v8::Arguments& arguments, unsigned skipArgumentCount, int framCountLimit) 64 90 { 65 91 v8::HandleScope scope; 66 v8::Context::Scope contextScope(v8::Context::GetCurrent()); 67 v8::Handle<v8::StackTrace> stackTrace(v8::StackTrace::CurrentStackTrace(1)); 92 v8::Local<v8::Context> context = v8::Context::GetCurrent(); 93 v8::Context::Scope contextScope(context); 94 v8::Handle<v8::StackTrace> stackTrace(v8::StackTrace::CurrentStackTrace(framCountLimit)); 68 95 69 96 if (stackTrace.IsEmpty()) … … 73 100 int sourceLineNumber; 74 101 String functionName; 75 if (stackTrace->GetFrameCount() <= 0) { 76 // Successfully grabbed stack trace, but there are no frames. 77 // Fallback to setting lineNumber to 0, and source and function name to "undefined". 78 sourceName = toWebCoreString(v8::Undefined()); 79 sourceLineNumber = 0; 80 functionName = toWebCoreString(v8::Undefined()); 81 } else { 82 v8::Handle<v8::StackFrame> frame = stackTrace->GetFrame(0); 83 getFrameLocation(frame, &sourceName, &sourceLineNumber, &functionName); 84 } 85 return new ScriptCallStack(arguments, skipArgumentCount, sourceName, sourceLineNumber, functionName); 102 getTopFrameLocation(stackTrace, &sourceName, &sourceLineNumber, &functionName); 103 104 Vector<OwnPtr<ScriptCallFrame> > scriptCallFrames; 105 if (framCountLimit > 1) 106 toScriptCallFramesVector(context, stackTrace, scriptCallFrames); 107 108 return new ScriptCallStack(ScriptState::forContext(context), new ScriptCallFrame(functionName, sourceName, sourceLineNumber, arguments, skipArgumentCount), scriptCallFrames); 86 109 } 87 110 88 111 PassOwnPtr<ScriptCallStack> ScriptCallStack::create(ScriptState* state, v8::Handle<v8::StackTrace> stackTrace) 89 112 { 90 return new ScriptCallStack(state, stackTrace); 113 v8::HandleScope scope; 114 Vector<OwnPtr<ScriptCallFrame> > scriptCallFrames; 115 toScriptCallFramesVector(state->context(), stackTrace, scriptCallFrames); 116 117 String sourceName; 118 int sourceLineNumber; 119 String functionName; 120 getTopFrameLocation(stackTrace, &sourceName, &sourceLineNumber, &functionName); 121 122 return new ScriptCallStack(state, new ScriptCallFrame(functionName, sourceName, sourceLineNumber), scriptCallFrames); 91 123 } 92 124 93 ScriptCallStack::ScriptCallStack( const v8::Arguments& arguments, unsigned skipArgumentCount, String sourceName, int sourceLineNumber, String functionName)94 : m_topFrame( new ScriptCallFrame(functionName, sourceName, sourceLineNumber, arguments, skipArgumentCount))95 , m_scriptState( ScriptState::current())125 ScriptCallStack::ScriptCallStack(ScriptState* scriptState, PassOwnPtr<ScriptCallFrame> topFrame, Vector<OwnPtr<ScriptCallFrame> >& scriptCallFrames) 126 : m_topFrame(topFrame) 127 , m_scriptState(scriptState) 96 128 { 97 } 98 99 ScriptCallStack::ScriptCallStack(ScriptState* scriptState, v8::Handle<v8::StackTrace> stackTrace) 100 : m_scriptState(scriptState) 101 { 102 v8::HandleScope handleScope; 103 v8::Context::Scope contextScope(m_scriptState->context()); 104 int frameCount = stackTrace->GetFrameCount(); 105 for (int i = 0; i < frameCount; i++) { 106 v8::Local<v8::StackFrame> stackFrame = stackTrace->GetFrame(i); 107 m_scriptCallFrames.append(toScriptCallFrame(stackFrame)); 108 } 129 m_scriptCallFrames.swap(scriptCallFrames); 109 130 } 110 131 -
trunk/WebCore/bindings/v8/ScriptCallStack.h
r63548 r63805 49 49 class ScriptCallStack : public Noncopyable { 50 50 public: 51 static PassOwnPtr<ScriptCallStack> create(const v8::Arguments&, unsigned skipArgumentCount = 0); 51 static const int maxCallStackSizeToCapture; 52 53 static PassOwnPtr<ScriptCallStack> create(const v8::Arguments&, unsigned skipArgumentCount = 0, int framCountLimit = 1); 52 54 static PassOwnPtr<ScriptCallStack> create(ScriptState*, v8::Handle<v8::StackTrace>); 53 55 ~ScriptCallStack(); … … 71 73 72 74 private: 73 ScriptCallStack( const v8::Arguments& arguments, unsigned skipArgumentCount, String sourceName, int sourceLineNumber, String funcName);75 ScriptCallStack(ScriptState* scriptState, PassOwnPtr<ScriptCallFrame> topFrame, Vector<OwnPtr<ScriptCallFrame> >& scriptCallFrames); 74 76 ScriptCallStack(ScriptState* scriptState, v8::Handle<v8::StackTrace> stackTrace); 75 77 -
trunk/WebCore/bindings/v8/ScriptController.cpp
r63662 r63805 35 35 #include "PlatformBridge.h" 36 36 #include "Document.h" 37 #include "ScriptCallStack.h" 37 38 #include "ScriptableDocumentParser.h" 38 39 #include "DOMWindow.h" … … 455 456 void ScriptController::setCaptureCallStackForUncaughtExceptions(bool) 456 457 { 457 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true, 200);458 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true, ScriptCallStack::maxCallStackSizeToCapture); 458 459 } 459 460 #endif -
trunk/WebCore/bindings/v8/custom/V8ConsoleCustom.cpp
r63548 r63805 65 65 v8::HandleScope handleScope; 66 66 ScriptState* scriptState = ScriptState::current(); 67 v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( 200);67 v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(ScriptCallStack::maxCallStackSizeToCapture); 68 68 OwnPtr<ScriptCallStack> callStack(ScriptCallStack::create(scriptState, stackTrace)); 69 69 imp->trace(callStack.get()); 70 70 return v8::Handle<v8::Value>(); 71 71 } 72 73 v8::Handle<v8::Value> V8Console::assertCallback(const v8::Arguments& args) 74 { 75 INC_STATS("DOM.Console.assertCallback"); 76 Console* imp = V8Console::toNative(args.Holder()); 77 OwnPtr<ScriptCallStack> callStack(ScriptCallStack::create(args, 1, ScriptCallStack::maxCallStackSizeToCapture)); 78 bool condition = args[0]->BooleanValue(); 79 imp->assertCondition(condition, callStack.get()); 80 return v8::Handle<v8::Value>(); 81 } 82 72 83 } // namespace WebCore -
trunk/WebCore/inspector/ConsoleMessage.cpp
r63662 r63805 98 98 m_url = lastCaller.sourceURL().string(); 99 99 100 // FIXME: For now, just store function names as strings.101 // As ScriptCallStack start storing line number and source URL for all102 // frames, refactor to use that, as well.103 100 if (storeTrace) { 104 101 for (unsigned i = 0; i < callStack->size(); ++i) -
trunk/WebCore/inspector/InspectorController.cpp
r63662 r63805 344 344 return; 345 345 346 addConsoleMessage(callStack->state(), new ConsoleMessage(source, type, level, message, callStack, m_groupLevel, type == TraceMessageType || type == UncaughtExceptionMessageType)); 346 bool storeStackTrace = type == TraceMessageType || type == UncaughtExceptionMessageType || type == AssertMessageType; 347 addConsoleMessage(callStack->state(), new ConsoleMessage(source, type, level, message, callStack, m_groupLevel, storeStackTrace)); 347 348 } 348 349 -
trunk/WebCore/inspector/front-end/ConsoleView.js
r63732 r63805 673 673 { 674 674 switch (this.type) { 675 case WebInspector.ConsoleMessage.MessageType.Assert: 675 676 case WebInspector.ConsoleMessage.MessageType.Trace: 676 677 case WebInspector.ConsoleMessage.MessageType.UncaughtException: … … 682 683 683 684 var root = treeOutline; 684 if (this.type === WebInspector.ConsoleMessage.MessageType.UncaughtException) { 685 var li = document.createElement("li"); 686 this._addMessageHeader(li, document.createTextNode(this._messageText)); 687 root = new TreeElement(li.innerHTML, null, true); 685 if (this.type === WebInspector.ConsoleMessage.MessageType.UncaughtException || 686 this.type === WebInspector.ConsoleMessage.MessageType.Assert) { 687 var messageText; 688 if (this.type === WebInspector.ConsoleMessage.MessageType.Assert) 689 messageText = this._format(this._parameters); 690 else 691 messageText = document.createTextNode(this._messageText); 692 693 var content = document.createElement("div"); 694 this._addMessageHeader(content, messageText); 695 root = new TreeElement(content, null, true); 696 content.treeElementForTest = root; 688 697 treeOutline.appendChild(root); 689 698 } … … 842 851 843 852 if (this.type === WebInspector.ConsoleMessage.MessageType.Trace || 853 this.type === WebInspector.ConsoleMessage.MessageType.Assert || 844 854 this.type === WebInspector.ConsoleMessage.MessageType.UncaughtException) 845 855 element.appendChild(this.formattedMessage); -
trunk/WebCore/page/Console.cpp
r63662 r63805 301 301 return String(); 302 302 303 const Vector< ConsoleMessage*>& consoleMessages = page->inspectorController()->consoleMessages();303 const Vector<OwnPtr<ConsoleMessage> >& consoleMessages = page->inspectorController()->consoleMessages(); 304 304 if (consoleMessages.isEmpty()) 305 305 return String(); 306 306 307 Vector< ConsoleMessage*>::const_iterator it = consoleMessages.begin();308 const Vector< ConsoleMessage*>::const_iterator end = consoleMessages.end();307 Vector<OwnPtr<ConsoleMessage> >::const_iterator it = consoleMessages.begin(); 308 const Vector<OwnPtr<ConsoleMessage> >::const_iterator end = consoleMessages.end(); 309 309 310 310 for (; it != end; ++it) { 311 ConsoleMessage* message = *it;311 ConsoleMessage* message = it->get(); 312 312 if (message->source() != WMLMessageSource) 313 313 continue; -
trunk/WebCore/page/Console.idl
r63548 r63805 43 43 [CustomArgumentHandling] void dirxml(); 44 44 [V8Custom, CustomArgumentHandling] void trace(); 45 [ CustomArgumentHandling, ImplementationFunction=assertCondition] void assert(in boolean condition);45 [V8Custom, CustomArgumentHandling, ImplementationFunction=assertCondition] void assert(in boolean condition); 46 46 [CustomArgumentHandling] void count(); 47 47 [CustomArgumentHandling] void markTimeline();
Note: See TracChangeset
for help on using the changeset viewer.