Ignore:
Timestamp:
Feb 21, 2014, 11:14:17 AM (12 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

Source/JavaScriptCore:

Reviewed by Timothy Hatcher.

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:

Reviewed by Timothy Hatcher.

  • 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/JSValue.mm

    r164136 r164486  
    2121 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    2222 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2424 */
    2525
     
    4848#import <wtf/text/StringHash.h>
    4949
     50#if ENABLE(REMOTE_INSPECTOR)
     51#import "CallFrame.h"
     52#import "JSGlobalObject.h"
     53#import "JSGlobalObjectInspectorController.h"
     54#endif
     55
    5056#if JSC_OBJC_API_ENABLED
    5157
     
    629635    return last;
    630636}
     637
     638#if ENABLE(REMOTE_INSPECTOR)
     639static void reportExceptionToInspector(JSGlobalContextRef context, JSC::JSValue exception)
     640{
     641    JSC::ExecState* exec = toJS(context);
     642    exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exception);
     643}
     644#endif
    631645
    632646static JSContainerConvertor::Task valueToObjectWithoutCopy(JSGlobalContextRef context, JSValueRef value)
     
    782796
    783797    JSC::APIEntryShim shim(toJS(context));
    784     if (!(JSValueIsNull(context, value) || JSValueIsUndefined(context, value)))
    785         *exception = toRef(JSC::createTypeError(toJS(context), ASCIILiteral("Cannot convert primitive to NSArray")));
     798    if (!(JSValueIsNull(context, value) || JSValueIsUndefined(context, value))) {
     799        JSC::JSObject* exceptionObject = JSC::createTypeError(toJS(context), ASCIILiteral("Cannot convert primitive to NSArray"));
     800        *exception = toRef(exceptionObject);
     801#if ENABLE(REMOTE_INSPECTOR)
     802        reportExceptionToInspector(context, exceptionObject);
     803#endif
     804    }
    786805    return nil;
    787806}
     
    799818
    800819    JSC::APIEntryShim shim(toJS(context));
    801     if (!(JSValueIsNull(context, value) || JSValueIsUndefined(context, value)))
    802         *exception = toRef(JSC::createTypeError(toJS(context), ASCIILiteral("Cannot convert primitive to NSDictionary")));
     820    if (!(JSValueIsNull(context, value) || JSValueIsUndefined(context, value))) {
     821        JSC::JSObject* exceptionObject = JSC::createTypeError(toJS(context), ASCIILiteral("Cannot convert primitive to NSDictionary"));
     822        *exception = toRef(exceptionObject);
     823#if ENABLE(REMOTE_INSPECTOR)
     824        reportExceptionToInspector(context, exceptionObject);
     825#endif
     826    }
    803827    return nil;
    804828}
Note: See TracChangeset for help on using the changeset viewer.