Ignore:
Timestamp:
Feb 27, 2014, 12:45:08 PM (11 years ago)
Author:
Joseph Pecoraro
Message:

Web Inspector: JSContext inspection should report exceptions in the console
https://bugs.webkit.org/show_bug.cgi?id=128776

Reviewed by Timothy Hatcher.

Source/JavaScriptCore:

When JavaScript API functions have an exception, let the inspector
know so it can log the JavaScript and Native backtrace that caused
the exception.

Include some clean up of ConsoleMessage and ScriptCallStack construction.

  • API/JSBase.cpp:

(JSEvaluateScript):
(JSCheckScriptSyntax):

  • API/JSObjectRef.cpp:

(JSObjectMakeFunction):
(JSObjectMakeArray):
(JSObjectMakeDate):
(JSObjectMakeError):
(JSObjectMakeRegExp):
(JSObjectGetProperty):
(JSObjectSetProperty):
(JSObjectGetPropertyAtIndex):
(JSObjectSetPropertyAtIndex):
(JSObjectDeleteProperty):
(JSObjectCallAsFunction):
(JSObjectCallAsConstructor):

  • API/JSValue.mm:

(reportExceptionToInspector):
(valueToArray):
(valueToDictionary):

  • API/JSValueRef.cpp:

(JSValueIsEqual):
(JSValueIsInstanceOfConstructor):
(JSValueCreateJSONString):
(JSValueToNumber):
(JSValueToStringCopy):
(JSValueToObject):
When seeing an exception, let the inspector know there was an exception.

  • inspector/JSGlobalObjectInspectorController.h:
  • inspector/JSGlobalObjectInspectorController.cpp:

(Inspector::JSGlobalObjectInspectorController::JSGlobalObjectInspectorController):
(Inspector::JSGlobalObjectInspectorController::appendAPIBacktrace):
(Inspector::JSGlobalObjectInspectorController::reportAPIException):
Log API exceptions by also grabbing the native backtrace.

  • inspector/ScriptCallStack.h:
  • inspector/ScriptCallStack.cpp:

(Inspector::ScriptCallStack::firstNonNativeCallFrame):
(Inspector::ScriptCallStack::append):
Minor extensions to ScriptCallStack to make it easier to work with.

  • inspector/ConsoleMessage.cpp:

(Inspector::ConsoleMessage::ConsoleMessage):
(Inspector::ConsoleMessage::autogenerateMetadata):
Provide better default information if the first call frame was native.

  • inspector/ScriptCallStackFactory.cpp:

(Inspector::createScriptCallStack):
(Inspector::extractSourceInformationFromException):
(Inspector::createScriptCallStackFromException):
Perform the handling here of inserting a fake call frame for exceptions
if there was no call stack (e.g. a SyntaxError) or if the first call
frame had no information.

  • inspector/ConsoleMessage.cpp:

(Inspector::ConsoleMessage::ConsoleMessage):
(Inspector::ConsoleMessage::autogenerateMetadata):

  • inspector/ConsoleMessage.h:
  • inspector/ScriptCallStackFactory.cpp:

(Inspector::createScriptCallStack):
(Inspector::createScriptCallStackForConsole):

  • inspector/ScriptCallStackFactory.h:
  • inspector/agents/InspectorConsoleAgent.cpp:

(Inspector::InspectorConsoleAgent::enable):
(Inspector::InspectorConsoleAgent::addMessageToConsole):
(Inspector::InspectorConsoleAgent::count):

  • inspector/agents/JSGlobalObjectDebuggerAgent.cpp:

(Inspector::JSGlobalObjectDebuggerAgent::breakpointActionLog):
ConsoleMessage cleanup.

Source/WebCore:

Include some clean up of ConsoleMessage and ScriptCallStack construction.

Covered by existing tests.

  • bindings/js/JSDOMBinding.cpp:

(WebCore::reportException):
Simplify code now that createStackTraceFromException handles it.

  • page/ContentSecurityPolicy.cpp:

(WebCore::gatherSecurityPolicyViolationEventData):
(WebCore::ContentSecurityPolicy::reportViolation):
ScriptCallStack can give us the first non-native callframe.

  • inspector/InspectorResourceAgent.cpp:

(WebCore::InspectorResourceAgent::buildInitiatorObject):

  • inspector/PageDebuggerAgent.cpp:

(WebCore::PageDebuggerAgent::breakpointActionLog):

  • inspector/TimelineRecordFactory.cpp:

(WebCore::TimelineRecordFactory::createGenericRecord):

  • page/Console.cpp:

(WebCore::internalAddMessage):
(WebCore::Console::profile):
(WebCore::Console::profileEnd):
(WebCore::Console::timeEnd):

  • page/ContentSecurityPolicy.cpp:

(WebCore::gatherSecurityPolicyViolationEventData):
(WebCore::ContentSecurityPolicy::reportViolation):

  • page/DOMWindow.cpp:

(WebCore::DOMWindow::postMessage):

Source/WebInspectorUI:

  • UserInterface/ConsoleMessageImpl.js:

(WebInspector.ConsoleMessageImpl.prototype._formatMessage):
(WebInspector.ConsoleMessageImpl.prototype._shouldHideURL):
(WebInspector.ConsoleMessageImpl.prototype._firstNonNativeCallFrame):
(WebInspector.ConsoleMessageImpl.prototype._populateStackTraceTreeElement):
Provide better handling for "[native code]" and legacy "undefined"
call frame URLs. Never linkify these. Also, when showing a link
for an exception, always use the first non-native call frame as
the link location.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/API/JSObjectRef.cpp

    r164764 r164824  
    5656#include "RegExpConstructor.h"
    5757
     58#if ENABLE(REMOTE_INSPECTOR)
     59#include "JSGlobalObjectInspectorController.h"
     60#endif
     61
    5862using namespace JSC;
    5963
     
    146150    JSObject* result = constructFunction(exec, exec->lexicalGlobalObject(), args, nameID, sourceURL->string(), TextPosition(OrdinalNumber::fromOneBasedInt(startingLineNumber), OrdinalNumber::first()));
    147151    if (exec->hadException()) {
    148         if (exception)
    149             *exception = toRef(exec, exec->exception());
    150         exec->clearException();
     152        JSValue exceptionValue = exec->exception();
     153        if (exception)
     154            *exception = toRef(exec, exceptionValue);
     155        exec->clearException();
     156#if ENABLE(REMOTE_INSPECTOR)
     157        exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue);
     158#endif
    151159        result = 0;
    152160    }
     
    174182
    175183    if (exec->hadException()) {
    176         if (exception)
    177             *exception = toRef(exec, exec->exception());
    178         exec->clearException();
     184        JSValue exceptionValue = exec->exception();
     185        if (exception)
     186            *exception = toRef(exec, exceptionValue);
     187        exec->clearException();
     188#if ENABLE(REMOTE_INSPECTOR)
     189        exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue);
     190#endif
    179191        result = 0;
    180192    }
     
    198210    JSObject* result = constructDate(exec, exec->lexicalGlobalObject(), argList);
    199211    if (exec->hadException()) {
    200         if (exception)
    201             *exception = toRef(exec, exec->exception());
    202         exec->clearException();
     212        JSValue exceptionValue = exec->exception();
     213        if (exception)
     214            *exception = toRef(exec, exceptionValue);
     215        exec->clearException();
     216#if ENABLE(REMOTE_INSPECTOR)
     217        exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue);
     218#endif
    203219        result = 0;
    204220    }
     
    221237
    222238    if (exec->hadException()) {
    223         if (exception)
    224             *exception = toRef(exec, exec->exception());
    225         exec->clearException();
     239        JSValue exceptionValue = exec->exception();
     240        if (exception)
     241            *exception = toRef(exec, exceptionValue);
     242        exec->clearException();
     243#if ENABLE(REMOTE_INSPECTOR)
     244        exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue);
     245#endif
    226246        result = 0;
    227247    }
     
    245265    JSObject* result = constructRegExp(exec, exec->lexicalGlobalObject(),  argList);
    246266    if (exec->hadException()) {
    247         if (exception)
    248             *exception = toRef(exec, exec->exception());
    249         exec->clearException();
     267        JSValue exceptionValue = exec->exception();
     268        if (exception)
     269            *exception = toRef(exec, exceptionValue);
     270        exec->clearException();
     271#if ENABLE(REMOTE_INSPECTOR)
     272        exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue);
     273#endif
    250274        result = 0;
    251275    }
     
    309333    JSValue jsValue = jsObject->get(exec, propertyName->identifier(&exec->vm()));
    310334    if (exec->hadException()) {
    311         if (exception)
    312             *exception = toRef(exec, exec->exception());
    313         exec->clearException();
     335        JSValue exceptionValue = exec->exception();
     336        if (exception)
     337            *exception = toRef(exec, exceptionValue);
     338        exec->clearException();
     339#if ENABLE(REMOTE_INSPECTOR)
     340        exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue);
     341#endif
    314342    }
    315343    return toRef(exec, jsValue);
     
    338366
    339367    if (exec->hadException()) {
    340         if (exception)
    341             *exception = toRef(exec, exec->exception());
    342         exec->clearException();
     368        JSValue exceptionValue = exec->exception();
     369        if (exception)
     370            *exception = toRef(exec, exceptionValue);
     371        exec->clearException();
     372#if ENABLE(REMOTE_INSPECTOR)
     373        exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue);
     374#endif
    343375    }
    344376}
     
    357389    JSValue jsValue = jsObject->get(exec, propertyIndex);
    358390    if (exec->hadException()) {
    359         if (exception)
    360             *exception = toRef(exec, exec->exception());
    361         exec->clearException();
     391        JSValue exceptionValue = exec->exception();
     392        if (exception)
     393            *exception = toRef(exec, exceptionValue);
     394        exec->clearException();
     395#if ENABLE(REMOTE_INSPECTOR)
     396        exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue);
     397#endif
    362398    }
    363399    return toRef(exec, jsValue);
     
    379415    jsObject->methodTable()->putByIndex(jsObject, exec, propertyIndex, jsValue, false);
    380416    if (exec->hadException()) {
    381         if (exception)
    382             *exception = toRef(exec, exec->exception());
    383         exec->clearException();
     417        JSValue exceptionValue = exec->exception();
     418        if (exception)
     419            *exception = toRef(exec, exceptionValue);
     420        exec->clearException();
     421#if ENABLE(REMOTE_INSPECTOR)
     422        exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue);
     423#endif
    384424    }
    385425}
     
    398438    bool result = jsObject->methodTable()->deleteProperty(jsObject, exec, propertyName->identifier(&exec->vm()));
    399439    if (exec->hadException()) {
    400         if (exception)
    401             *exception = toRef(exec, exec->exception());
    402         exec->clearException();
     440        JSValue exceptionValue = exec->exception();
     441        if (exception)
     442            *exception = toRef(exec, exceptionValue);
     443        exec->clearException();
     444#if ENABLE(REMOTE_INSPECTOR)
     445        exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue);
     446#endif
    403447    }
    404448    return result;
     
    543587    JSValueRef result = toRef(exec, call(exec, jsObject, callType, callData, jsThisObject, argList));
    544588    if (exec->hadException()) {
    545         if (exception)
    546             *exception = toRef(exec, exec->exception());
    547         exec->clearException();
     589        JSValue exceptionValue = exec->exception();
     590        if (exception)
     591            *exception = toRef(exec, exceptionValue);
     592        exec->clearException();
     593#if ENABLE(REMOTE_INSPECTOR)
     594        exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue);
     595#endif
    548596        result = 0;
    549597    }
     
    580628    JSObjectRef result = toRef(construct(exec, jsObject, constructType, constructData, argList));
    581629    if (exec->hadException()) {
    582         if (exception)
    583             *exception = toRef(exec, exec->exception());
    584         exec->clearException();
     630        JSValue exceptionValue = exec->exception();
     631        if (exception)
     632            *exception = toRef(exec, exceptionValue);
     633        exec->clearException();
     634#if ENABLE(REMOTE_INSPECTOR)
     635        exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue);
     636#endif
    585637        result = 0;
    586638    }
Note: See TracChangeset for help on using the changeset viewer.