Changeset 164554 in webkit


Ignore:
Timestamp:
Feb 22, 2014 9:44:05 PM (10 years ago)
Author:
mitz@apple.com
Message:

REGRESSION (r164507): Crash beneath JSGlobalObjectInspectorController::reportAPIException at facebook.com, twitter.com, youtube.com
https://bugs.webkit.org/show_bug.cgi?id=129227

Reviewed by Eric Carlson.

Reverted r164507.

Source/JavaScriptCore:

  • API/JSBase.cpp:

(JSEvaluateScript):
(JSCheckScriptSyntax):

  • API/JSObjectRef.cpp:

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

  • API/JSValue.mm:

(valueToArray):
(valueToDictionary):

  • API/JSValueRef.cpp:

(JSValueIsEqual):
(JSValueIsInstanceOfConstructor):
(JSValueCreateJSONString):
(JSValueToNumber):
(JSValueToStringCopy):
(JSValueToObject):

  • inspector/ConsoleMessage.cpp:

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

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

(Inspector::JSGlobalObjectInspectorController::JSGlobalObjectInspectorController):

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

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

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

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

  • inspector/agents/JSGlobalObjectDebuggerAgent.cpp:

(Inspector::JSGlobalObjectDebuggerAgent::breakpointActionLog):

Source/WebCore:

  • bindings/js/JSDOMBinding.cpp:

(WebCore::reportException):

  • 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/Views/ConsoleMessageImpl.js:

(WebInspector.ConsoleMessageImpl.prototype._formatMessage):
(WebInspector.ConsoleMessageImpl.prototype._populateStackTraceTreeElement):

Location:
trunk/Source
Files:
25 edited

Legend:

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

    r164507 r164554  
    4141#include <wtf/text/StringHash.h>
    4242
    43 #if ENABLE(REMOTE_INSPECTOR)
    44 #include "JSGlobalObjectInspectorController.h"
    45 #endif
    46 
    4743using namespace JSC;
    4844
     
    7066        if (exception)
    7167            *exception = toRef(exec, evaluationException);
    72 #if ENABLE(REMOTE_INSPECTOR)
    73         // FIXME: If we have a debugger attached we could learn about ParseError exceptions through
    74         // ScriptDebugServer::sourceParsed and this path could produce a duplicate warning. The
    75         // Debugger path is currently ignored by inspector.
    76         // NOTE: If we don't have a debugger, this SourceCode will be forever lost to the inspector.
    77         // We could stash it in the inspector in case an inspector is ever opened.
    78         globalObject->inspectorController().reportAPIException(exec, evaluationException);
    79 #endif
    8068        return 0;
    8169    }
     
    10795        if (exception)
    10896            *exception = toRef(exec, syntaxException);
    109 #if ENABLE(REMOTE_INSPECTOR)
    110         exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, syntaxException);
    111 #endif
    11297        return false;
    11398    }
  • trunk/Source/JavaScriptCore/API/JSObjectRef.cpp

    r164507 r164554  
    5656#include "RegExpConstructor.h"
    5757
    58 #if ENABLE(REMOTE_INSPECTOR)
    59 #include "JSGlobalObjectInspectorController.h"
    60 #endif
    61 
    6258using namespace JSC;
    6359
     
    150146    JSObject* result = constructFunction(exec, exec->lexicalGlobalObject(), args, nameID, sourceURL->string(), TextPosition(OrdinalNumber::fromOneBasedInt(startingLineNumber), OrdinalNumber::first()));
    151147    if (exec->hadException()) {
    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
     148        if (exception)
     149            *exception = toRef(exec, exec->exception());
     150        exec->clearException();
    159151        result = 0;
    160152    }
     
    182174
    183175    if (exec->hadException()) {
    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
     176        if (exception)
     177            *exception = toRef(exec, exec->exception());
     178        exec->clearException();
    191179        result = 0;
    192180    }
     
    210198    JSObject* result = constructDate(exec, exec->lexicalGlobalObject(), argList);
    211199    if (exec->hadException()) {
    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
     200        if (exception)
     201            *exception = toRef(exec, exec->exception());
     202        exec->clearException();
    219203        result = 0;
    220204    }
     
    237221
    238222    if (exec->hadException()) {
    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
     223        if (exception)
     224            *exception = toRef(exec, exec->exception());
     225        exec->clearException();
    246226        result = 0;
    247227    }
     
    265245    JSObject* result = constructRegExp(exec, exec->lexicalGlobalObject(),  argList);
    266246    if (exec->hadException()) {
    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
     247        if (exception)
     248            *exception = toRef(exec, exec->exception());
     249        exec->clearException();
    274250        result = 0;
    275251    }
     
    333309    JSValue jsValue = jsObject->get(exec, propertyName->identifier(&exec->vm()));
    334310    if (exec->hadException()) {
    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
     311        if (exception)
     312            *exception = toRef(exec, exec->exception());
     313        exec->clearException();
    342314    }
    343315    return toRef(exec, jsValue);
     
    366338
    367339    if (exec->hadException()) {
    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
     340        if (exception)
     341            *exception = toRef(exec, exec->exception());
     342        exec->clearException();
    375343    }
    376344}
     
    389357    JSValue jsValue = jsObject->get(exec, propertyIndex);
    390358    if (exec->hadException()) {
    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
     359        if (exception)
     360            *exception = toRef(exec, exec->exception());
     361        exec->clearException();
    398362    }
    399363    return toRef(exec, jsValue);
     
    415379    jsObject->methodTable()->putByIndex(jsObject, exec, propertyIndex, jsValue, false);
    416380    if (exec->hadException()) {
    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
     381        if (exception)
     382            *exception = toRef(exec, exec->exception());
     383        exec->clearException();
    424384    }
    425385}
     
    438398    bool result = jsObject->methodTable()->deleteProperty(jsObject, exec, propertyName->identifier(&exec->vm()));
    439399    if (exec->hadException()) {
    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
     400        if (exception)
     401            *exception = toRef(exec, exec->exception());
     402        exec->clearException();
    447403    }
    448404    return result;
     
    586542    JSValueRef result = toRef(exec, call(exec, jsObject, callType, callData, jsThisObject, argList));
    587543    if (exec->hadException()) {
    588         JSValue exceptionValue = exec->exception();
    589         if (exception)
    590             *exception = toRef(exec, exceptionValue);
    591         exec->clearException();
    592 #if ENABLE(REMOTE_INSPECTOR)
    593         exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue);
    594 #endif
     544        if (exception)
     545            *exception = toRef(exec, exec->exception());
     546        exec->clearException();
    595547        result = 0;
    596548    }
     
    627579    JSObjectRef result = toRef(construct(exec, jsObject, constructType, constructData, argList));
    628580    if (exec->hadException()) {
    629         JSValue exceptionValue = exec->exception();
    630         if (exception)
    631             *exception = toRef(exec, exceptionValue);
    632         exec->clearException();
    633 #if ENABLE(REMOTE_INSPECTOR)
    634         exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue);
    635 #endif
     581        if (exception)
     582            *exception = toRef(exec, exec->exception());
     583        exec->clearException();
    636584        result = 0;
    637585    }
  • trunk/Source/JavaScriptCore/API/JSValue.mm

    r164507 r164554  
    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 
    5650#if JSC_OBJC_API_ENABLED
    5751
     
    635629    return last;
    636630}
    637 
    638 #if ENABLE(REMOTE_INSPECTOR)
    639 static void reportExceptionToInspector(JSGlobalContextRef context, JSC::JSValue exception)
    640 {
    641     JSC::ExecState* exec = toJS(context);
    642     exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exception);
    643 }
    644 #endif
    645631
    646632static JSContainerConvertor::Task valueToObjectWithoutCopy(JSGlobalContextRef context, JSValueRef value)
     
    796782
    797783    JSC::APIEntryShim shim(toJS(context));
    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     }
     784    if (!(JSValueIsNull(context, value) || JSValueIsUndefined(context, value)))
     785        *exception = toRef(JSC::createTypeError(toJS(context), ASCIILiteral("Cannot convert primitive to NSArray")));
    805786    return nil;
    806787}
     
    818799
    819800    JSC::APIEntryShim shim(toJS(context));
    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     }
     801    if (!(JSValueIsNull(context, value) || JSValueIsUndefined(context, value)))
     802        *exception = toRef(JSC::createTypeError(toJS(context), ASCIILiteral("Cannot convert primitive to NSDictionary")));
    827803    return nil;
    828804}
  • trunk/Source/JavaScriptCore/API/JSValueRef.cpp

    r164507 r164554  
    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
     
    4747#if PLATFORM(MAC)
    4848#include <mach-o/dyld.h>
    49 #endif
    50 
    51 #if ENABLE(REMOTE_INSPECTOR)
    52 #include "JSGlobalObjectInspectorController.h"
    5349#endif
    5450
     
    207203    bool result = JSValue::equal(exec, jsA, jsB); // false if an exception is thrown
    208204    if (exec->hadException()) {
    209         JSValue exceptionValue = exec->exception();
    210         if (exception)
    211             *exception = toRef(exec, exceptionValue);
    212         exec->clearException();
    213 #if ENABLE(REMOTE_INSPECTOR)
    214         exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue);
    215 #endif
     205        if (exception)
     206            *exception = toRef(exec, exec->exception());
     207        exec->clearException();
    216208    }
    217209    return result;
     
    249241    bool result = jsConstructor->hasInstance(exec, jsValue); // false if an exception is thrown
    250242    if (exec->hadException()) {
    251         JSValue exceptionValue = exec->exception();
    252         if (exception)
    253             *exception = toRef(exec, exceptionValue);
    254         exec->clearException();
    255 #if ENABLE(REMOTE_INSPECTOR)
    256         exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue);
    257 #endif
     243        if (exception)
     244            *exception = toRef(exec, exec->exception());
     245        exec->clearException();
    258246    }
    259247    return result;
     
    357345        *exception = 0;
    358346    if (exec->hadException()) {
    359         JSValue exceptionValue = exec->exception();
    360         if (exception)
    361             *exception = toRef(exec, exceptionValue);
    362         exec->clearException();
    363 #if ENABLE(REMOTE_INSPECTOR)
    364         exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue);
    365 #endif
     347        if (exception)
     348            *exception = toRef(exec, exec->exception());
     349        exec->clearException();
    366350        return 0;
    367351    }
     
    395379    double number = jsValue.toNumber(exec);
    396380    if (exec->hadException()) {
    397         JSValue exceptionValue = exec->exception();
    398         if (exception)
    399             *exception = toRef(exec, exceptionValue);
    400         exec->clearException();
    401 #if ENABLE(REMOTE_INSPECTOR)
    402         exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue);
    403 #endif
     381        if (exception)
     382            *exception = toRef(exec, exec->exception());
     383        exec->clearException();
    404384        number = QNaN;
    405385    }
     
    420400    RefPtr<OpaqueJSString> stringRef(OpaqueJSString::create(jsValue.toString(exec)->value(exec)));
    421401    if (exec->hadException()) {
    422         JSValue exceptionValue = exec->exception();
    423         if (exception)
    424             *exception = toRef(exec, exceptionValue);
    425         exec->clearException();
    426 #if ENABLE(REMOTE_INSPECTOR)
    427         exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue);
    428 #endif
     402        if (exception)
     403            *exception = toRef(exec, exec->exception());
     404        exec->clearException();
    429405        stringRef.clear();
    430406    }
     
    445421    JSObjectRef objectRef = toRef(jsValue.toObject(exec));
    446422    if (exec->hadException()) {
    447         JSValue exceptionValue = exec->exception();
    448         if (exception)
    449             *exception = toRef(exec, exceptionValue);
    450         exec->clearException();
    451 #if ENABLE(REMOTE_INSPECTOR)
    452         exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue);
    453 #endif
     423        if (exception)
     424            *exception = toRef(exec, exec->exception());
     425        exec->clearException();
    454426        objectRef = 0;
    455427    }
    456428    return objectRef;
    457 }
     429}   
    458430
    459431void JSValueProtect(JSContextRef ctx, JSValueRef value)
  • trunk/Source/JavaScriptCore/ChangeLog

    r164553 r164554  
     12014-02-22  Dan Bernstein  <mitz@apple.com>
     2
     3        REGRESSION (r164507): Crash beneath JSGlobalObjectInspectorController::reportAPIException at facebook.com, twitter.com, youtube.com
     4        https://bugs.webkit.org/show_bug.cgi?id=129227
     5
     6        Reviewed by Eric Carlson.
     7
     8        Reverted r164507.
     9
     10        * API/JSBase.cpp:
     11        (JSEvaluateScript):
     12        (JSCheckScriptSyntax):
     13        * API/JSObjectRef.cpp:
     14        (JSObjectMakeFunction):
     15        (JSObjectMakeArray):
     16        (JSObjectMakeDate):
     17        (JSObjectMakeError):
     18        (JSObjectMakeRegExp):
     19        (JSObjectGetProperty):
     20        (JSObjectSetProperty):
     21        (JSObjectGetPropertyAtIndex):
     22        (JSObjectSetPropertyAtIndex):
     23        (JSObjectDeleteProperty):
     24        (JSObjectCallAsFunction):
     25        (JSObjectCallAsConstructor):
     26        * API/JSValue.mm:
     27        (valueToArray):
     28        (valueToDictionary):
     29        * API/JSValueRef.cpp:
     30        (JSValueIsEqual):
     31        (JSValueIsInstanceOfConstructor):
     32        (JSValueCreateJSONString):
     33        (JSValueToNumber):
     34        (JSValueToStringCopy):
     35        (JSValueToObject):
     36        * inspector/ConsoleMessage.cpp:
     37        (Inspector::ConsoleMessage::ConsoleMessage):
     38        (Inspector::ConsoleMessage::autogenerateMetadata):
     39        * inspector/ConsoleMessage.h:
     40        * inspector/JSGlobalObjectInspectorController.cpp:
     41        (Inspector::JSGlobalObjectInspectorController::JSGlobalObjectInspectorController):
     42        * inspector/JSGlobalObjectInspectorController.h:
     43        * inspector/ScriptCallStack.cpp:
     44        * inspector/ScriptCallStack.h:
     45        * inspector/ScriptCallStackFactory.cpp:
     46        (Inspector::createScriptCallStack):
     47        (Inspector::createScriptCallStackForConsole):
     48        (Inspector::createScriptCallStackFromException):
     49        * inspector/ScriptCallStackFactory.h:
     50        * inspector/agents/InspectorConsoleAgent.cpp:
     51        (Inspector::InspectorConsoleAgent::enable):
     52        (Inspector::InspectorConsoleAgent::addMessageToConsole):
     53        (Inspector::InspectorConsoleAgent::count):
     54        * inspector/agents/JSGlobalObjectDebuggerAgent.cpp:
     55        (Inspector::JSGlobalObjectDebuggerAgent::breakpointActionLog):
     56
    1572014-02-22  Joseph Pecoraro  <pecoraro@apple.com>
    258
  • trunk/Source/JavaScriptCore/inspector/ConsoleMessage.cpp

    r164507 r164554  
    4646namespace Inspector {
    4747
    48 ConsoleMessage::ConsoleMessage(MessageSource source, MessageType type, MessageLevel level, const String& message, unsigned long requestIdentifier)
     48ConsoleMessage::ConsoleMessage(bool canGenerateCallStack, MessageSource source, MessageType type, MessageLevel level, const String& message, unsigned long requestIdentifier)
    4949    : m_source(source)
    5050    , m_type(type)
     
    5757    , m_requestId(IdentifiersFactory::requestId(requestIdentifier))
    5858{
    59 }
    60 
    61 ConsoleMessage::ConsoleMessage(MessageSource source, MessageType type, MessageLevel level, const String& message, const String& url, unsigned line, unsigned column, JSC::ExecState* state, unsigned long requestIdentifier)
     59    autogenerateMetadata(canGenerateCallStack);
     60}
     61
     62ConsoleMessage::ConsoleMessage(bool canGenerateCallStack, MessageSource source, MessageType type, MessageLevel level, const String& message, const String& url, unsigned line, unsigned column, JSC::ExecState* state, unsigned long requestIdentifier)
    6263    : m_source(source)
    6364    , m_type(type)
     
    7071    , m_requestId(IdentifiersFactory::requestId(requestIdentifier))
    7172{
    72     autogenerateMetadata(state);
    73 }
    74 
    75 ConsoleMessage::ConsoleMessage(MessageSource source, MessageType type, MessageLevel level, const String& message, PassRefPtr<ScriptCallStack> callStack, unsigned long requestIdentifier)
    76     : m_source(source)
    77     , m_type(type)
    78     , m_level(level)
    79     , m_message(message)
    80     , m_url()
     73    autogenerateMetadata(canGenerateCallStack, state);
     74}
     75
     76ConsoleMessage::ConsoleMessage(bool, MessageSource source, MessageType type, MessageLevel level, const String& message, PassRefPtr<ScriptCallStack> callStack, unsigned long requestIdentifier)
     77    : m_source(source)
     78    , m_type(type)
     79    , m_level(level)
     80    , m_message(message)
     81    , m_arguments(nullptr)
    8182    , m_line(0)
    8283    , m_column(0)
     
    8485    , m_requestId(IdentifiersFactory::requestId(requestIdentifier))
    8586{
     87    if (callStack && callStack->size()) {
     88        const ScriptCallFrame& frame = callStack->at(0);
     89        m_url = frame.sourceURL();
     90        m_line = frame.lineNumber();
     91        m_column = frame.columnNumber();
     92    }
    8693    m_callStack = callStack;
    87 
    88     const ScriptCallFrame* frame = m_callStack ? m_callStack->firstNonNativeCallFrame() : nullptr;
    89     if (frame) {
    90         m_url = frame->sourceURL();
    91         m_line = frame->lineNumber();
    92         m_column = frame->columnNumber();
    93     }
    94 }
    95 
    96 ConsoleMessage::ConsoleMessage(MessageSource source, MessageType type, MessageLevel level, const String& message, PassRefPtr<ScriptArguments> arguments, JSC::ExecState* state, unsigned long requestIdentifier)
     94}
     95
     96ConsoleMessage::ConsoleMessage(bool canGenerateCallStack, MessageSource source, MessageType type, MessageLevel level, const String& message, PassRefPtr<ScriptArguments> arguments, JSC::ExecState* state, unsigned long requestIdentifier)
    9797    : m_source(source)
    9898    , m_type(type)
     
    106106    , m_requestId(IdentifiersFactory::requestId(requestIdentifier))
    107107{
    108     autogenerateMetadata(state);
     108    autogenerateMetadata(canGenerateCallStack, state);
    109109}
    110110
     
    113113}
    114114
    115 void ConsoleMessage::autogenerateMetadata(JSC::ExecState* state)
    116 {
    117     if (!state)
    118         return;
    119 
     115// FIXME: Remove the generate without ExecState path. The caller should always provide an ExecState.
     116void ConsoleMessage::autogenerateMetadata(bool /*canGenerateCallStack*/, JSC::ExecState* state)
     117{
    120118    if (m_type == MessageType::EndGroup)
    121119        return;
    122120
    123     // FIXME: Should this really be using "for console" in the generic ConsoleMessage autogeneration? This can skip the first frame.
    124     m_callStack = createScriptCallStackForConsole(state, ScriptCallStack::maxCallStackSizeToCapture);
    125 
    126     if (const ScriptCallFrame* frame = m_callStack->firstNonNativeCallFrame()) {
    127         m_url = frame->sourceURL();
    128         m_line = frame->lineNumber();
    129         m_column = frame->columnNumber();
     121    if (state)
     122        m_callStack = createScriptCallStackForConsole(state);
     123    // else if (canGenerateCallStack)
     124    //     m_callStack = createScriptCallStack(ScriptCallStack::maxCallStackSizeToCapture, true);
     125    else
    130126        return;
    131     }
     127
     128    if (m_callStack && m_callStack->size()) {
     129        const ScriptCallFrame& frame = m_callStack->at(0);
     130        m_url = frame.sourceURL();
     131        m_line = frame.lineNumber();
     132        m_column = frame.columnNumber();
     133        return;
     134    }
     135
     136    m_callStack.clear();
    132137}
    133138
  • trunk/Source/JavaScriptCore/inspector/ConsoleMessage.h

    r164507 r164554  
    5252    WTF_MAKE_FAST_ALLOCATED;
    5353public:
    54     ConsoleMessage(MessageSource, MessageType, MessageLevel, const String& message, unsigned long requestIdentifier = 0);
    55     ConsoleMessage(MessageSource, MessageType, MessageLevel, const String& message, const String& url, unsigned line, unsigned column, JSC::ExecState* = nullptr, unsigned long requestIdentifier = 0);
    56     ConsoleMessage(MessageSource, MessageType, MessageLevel, const String& message, PassRefPtr<ScriptCallStack>, unsigned long requestIdentifier = 0);
    57     ConsoleMessage(MessageSource, MessageType, MessageLevel, const String& message, PassRefPtr<ScriptArguments>, JSC::ExecState*, unsigned long requestIdentifier = 0);
     54    ConsoleMessage(bool canGenerateCallStack, MessageSource, MessageType, MessageLevel, const String& message, unsigned long requestIdentifier = 0);
     55    ConsoleMessage(bool canGenerateCallStack, MessageSource, MessageType, MessageLevel, const String& message, const String& url, unsigned line, unsigned column, JSC::ExecState* = nullptr, unsigned long requestIdentifier = 0);
     56    ConsoleMessage(bool canGenerateCallStack, MessageSource, MessageType, MessageLevel, const String& message, PassRefPtr<ScriptCallStack>, unsigned long requestIdentifier = 0);
     57    ConsoleMessage(bool canGenerateCallStack, MessageSource, MessageType, MessageLevel, const String& message, PassRefPtr<ScriptArguments>, JSC::ExecState*, unsigned long requestIdentifier = 0);
    5858    ~ConsoleMessage();
    5959
     
    7575
    7676private:
    77     void autogenerateMetadata(JSC::ExecState* = nullptr);
     77    void autogenerateMetadata(bool canGenerateCallStack, JSC::ExecState* = nullptr);
    7878
    7979    MessageSource m_source;
  • trunk/Source/JavaScriptCore/inspector/JSGlobalObjectInspectorController.cpp

    r164507 r164554  
    3030
    3131#include "Completion.h"
    32 #include "ErrorHandlingScope.h"
    3332#include "InjectedScriptHost.h"
    3433#include "InjectedScriptManager.h"
     
    4039#include "JSGlobalObjectDebuggerAgent.h"
    4140#include "JSGlobalObjectRuntimeAgent.h"
    42 #include "ScriptCallStack.h"
    43 #include "ScriptCallStackFactory.h"
    44 #include <cxxabi.h>
    45 #include <dlfcn.h>
    46 #include <execinfo.h>
    4741
    4842using namespace JSC;
     
    5852    auto consoleAgent = std::make_unique<JSGlobalObjectConsoleAgent>(m_injectedScriptManager.get());
    5953    auto debuggerAgent = std::make_unique<JSGlobalObjectDebuggerAgent>(m_injectedScriptManager.get(), m_globalObject, consoleAgent.get());
    60 
    61     m_consoleAgent = consoleAgent.get();
    6254
    6355    runtimeAgent->setScriptDebugServer(&debuggerAgent->scriptDebugServer());
     
    110102}
    111103
    112 void JSGlobalObjectInspectorController::appendAPIBacktrace(ScriptCallStack* callStack)
    113 {
    114     static const int framesToShow = 31;
    115     static const int framesToSkip = 3; // WTFGetBacktrace, appendAPIBacktrace, reportAPIException.
    116 
    117     void* samples[framesToShow + framesToSkip];
    118     int frames = framesToShow + framesToSkip;
    119     WTFGetBacktrace(samples, &frames);
    120 
    121     void** stack = samples + framesToSkip;
    122     int size = frames - framesToSkip;
    123     for (int i = 0; i < size; ++i) {
    124         const char* mangledName = nullptr;
    125         char* cxaDemangled = nullptr;
    126         Dl_info info;
    127         if (dladdr(stack[i], &info) && info.dli_sname)
    128             mangledName = info.dli_sname;
    129         if (mangledName)
    130             cxaDemangled = abi::__cxa_demangle(mangledName, nullptr, nullptr, nullptr);
    131         if (mangledName || cxaDemangled)
    132             callStack->append(ScriptCallFrame(cxaDemangled ? cxaDemangled : mangledName, ASCIILiteral("[native code]"), 0, 0));
    133         else
    134             callStack->append(ScriptCallFrame(ASCIILiteral("?"), ASCIILiteral("[native code]"), 0, 0));
    135         free(cxaDemangled);
    136     }
    137 }
    138 
    139 void JSGlobalObjectInspectorController::reportAPIException(ExecState* exec, JSValue exception)
    140 {
    141     if (isTerminatedExecutionException(exception))
    142         return;
    143 
    144     ErrorHandlingScope errorScope(exec->vm());
    145 
    146     RefPtr<ScriptCallStack> callStack = createScriptCallStackFromException(exec, exception, ScriptCallStack::maxCallStackSizeToCapture);
    147     appendAPIBacktrace(callStack.get());
    148 
    149     // FIXME: <http://webkit.org/b/115087> Web Inspector: Should not evaluate JavaScript handling exceptions
    150     // If this is a custom exception object, call toString on it to try and get a nice string representation for the exception.
    151     String errorMessage = exception.toString(exec)->value(exec);
    152     exec->clearException();
    153 
    154     m_consoleAgent->addMessageToConsole(MessageSource::JS, MessageType::Log, MessageLevel::Error, errorMessage, callStack);
    155 }
    156 
    157104InspectorFunctionCallHandler JSGlobalObjectInspectorController::functionCallHandler() const
    158105{
  • trunk/Source/JavaScriptCore/inspector/JSGlobalObjectInspectorController.h

    r164507 r164554  
    3838class ExecState;
    3939class JSGlobalObject;
    40 class JSValue;
    4140}
    4241
     
    4544class InjectedScriptManager;
    4645class InspectorBackendDispatcher;
    47 class InspectorConsoleAgent;
    4846class InspectorFrontendChannel;
    49 class ScriptCallStack;
    5047
    5148class JSGlobalObjectInspectorController final : public InspectorEnvironment {
     
    6259    void globalObjectDestroyed();
    6360
    64     void reportAPIException(JSC::ExecState*, JSC::JSValue exception);
    65 
    6661    virtual bool developerExtrasEnabled() const override { return true; }
    6762    virtual bool canAccessInspectedScriptState(JSC::ExecState*) const override { return true; }
     
    7267
    7368private:
    74     void appendAPIBacktrace(ScriptCallStack* callStack);
    75 
    7669    JSC::JSGlobalObject& m_globalObject;
    7770    std::unique_ptr<InjectedScriptManager> m_injectedScriptManager;
    78     InspectorConsoleAgent* m_consoleAgent;
    7971    InspectorAgentRegistry m_agents;
    8072    InspectorFrontendChannel* m_inspectorFrontendChannel;
  • trunk/Source/JavaScriptCore/inspector/ScriptCallStack.cpp

    r164507 r164554  
    3737namespace Inspector {
    3838
    39 PassRefPtr<ScriptCallStack> ScriptCallStack::create()
    40 {
    41     return adoptRef(new ScriptCallStack);
    42 }
    43 
    4439PassRefPtr<ScriptCallStack> ScriptCallStack::create(Vector<ScriptCallFrame>& frames)
    4540{
    4641    return adoptRef(new ScriptCallStack(frames));
    47 }
    48 
    49 ScriptCallStack::ScriptCallStack()
    50 {
    5142}
    5243
     
    6960{
    7061    return m_frames.size();
    71 }
    72 
    73 const ScriptCallFrame* ScriptCallStack::firstNonNativeCallFrame() const
    74 {
    75     if (!m_frames.size())
    76         return nullptr;
    77 
    78     for (size_t i = 0; i < m_frames.size(); ++i) {
    79         const ScriptCallFrame& frame = m_frames[i];
    80         if (frame.sourceURL() != "[native code]")
    81             return &frame;
    82     }
    83 
    84     return nullptr;
    85 }
    86 
    87 void ScriptCallStack::append(const ScriptCallFrame& frame)
    88 {
    89     m_frames.append(frame);
    9062}
    9163
  • trunk/Source/JavaScriptCore/inspector/ScriptCallStack.h

    r164507 r164554  
    4848    static const size_t maxCallStackSizeToCapture = 200;
    4949   
    50     static PassRefPtr<ScriptCallStack> create();
    5150    static PassRefPtr<ScriptCallStack> create(Vector<ScriptCallFrame>&);
    5251
     
    5554    const ScriptCallFrame& at(size_t) const;
    5655    size_t size() const;
    57 
    58     const ScriptCallFrame* firstNonNativeCallFrame() const;
    59 
    60     void append(const ScriptCallFrame&);
    6156
    6257    bool isEqual(ScriptCallStack*) const;
     
    6762
    6863private:
    69     ScriptCallStack();
    7064    ScriptCallStack(Vector<ScriptCallFrame>&);
    7165
  • trunk/Source/JavaScriptCore/inspector/ScriptCallStackFactory.cpp

    r164507 r164554  
    8484};
    8585
    86 PassRefPtr<ScriptCallStack> createScriptCallStack(JSC::ExecState* exec, size_t maxStackSize)
     86PassRefPtr<ScriptCallStack> createScriptCallStack(JSC::ExecState* exec, size_t maxStackSize, bool emptyIsAllowed)
    8787{
    88     if (!exec)
    89         return ScriptCallStack::create();
    90 
    9188    Vector<ScriptCallFrame> frames;
    9289
    93     CallFrame* frame = exec->vm().topCallFrame;
    94     CreateScriptCallStackFunctor functor(false, frames, maxStackSize);
    95     frame->iterate(functor);
     90    if (exec) {
     91        CallFrame* frame = exec->vm().topCallFrame;
     92        CreateScriptCallStackFunctor functor(false, frames, maxStackSize);
     93        frame->iterate(functor);
     94    }
     95
     96    if (frames.isEmpty() && !emptyIsAllowed) {
     97        // No frames found. It may happen in the case where
     98        // a bound function is called from native code for example.
     99        // Fallback to setting lineNumber to 0, and source and function name to "undefined".
     100        frames.append(ScriptCallFrame(ASCIILiteral("undefined"), ASCIILiteral("undefined"), 0, 0));
     101    }
    96102
    97103    return ScriptCallStack::create(frames);
    98104}
    99105
    100 PassRefPtr<ScriptCallStack> createScriptCallStackForConsole(JSC::ExecState* exec, size_t maxStackSize)
     106PassRefPtr<ScriptCallStack> createScriptCallStack(JSC::ExecState* exec, size_t maxStackSize)
    101107{
    102     if (!exec)
    103         return ScriptCallStack::create();
    104 
    105108    Vector<ScriptCallFrame> frames;
    106109
     
    117120}
    118121
    119 static void extractSourceInformationFromException(JSC::ExecState* exec, JSObject* exceptionObject, int* lineNumber, int* columnNumber, String* sourceURL)
     122PassRefPtr<ScriptCallStack> createScriptCallStackForConsole(JSC::ExecState* exec)
    120123{
    121     // FIXME: <http://webkit.org/b/115087> Web Inspector: Should not need to evaluate JavaScript handling exceptions
    122     JSValue lineValue = exceptionObject->getDirect(exec->vm(), Identifier(exec, "line"));
    123     *lineNumber = lineValue && lineValue.isNumber() ? int(lineValue.toNumber(exec)) : 0;
    124     JSValue columnValue = exceptionObject->getDirect(exec->vm(), Identifier(exec, "column"));
    125     *columnNumber = columnValue && columnValue.isNumber() ? int(columnValue.toNumber(exec)) : 0;
    126     JSValue sourceURLValue = exceptionObject->getDirect(exec->vm(), Identifier(exec, "sourceURL"));
    127     *sourceURL = sourceURLValue && sourceURLValue.isString() ? sourceURLValue.toString(exec)->value(exec) : String("undefined");
    128     exec->clearException();
     124    // FIXME: Caller should use createScriptCallStack alternative with the exec and appropriate max.
     125    return createScriptCallStack(exec, ScriptCallStack::maxCallStackSizeToCapture);
    129126}
    130127
     
    134131    RefCountedArray<StackFrame> stackTrace = exec->vm().exceptionStack();
    135132    for (size_t i = 0; i < stackTrace.size() && i < maxStackSize; i++) {
     133        if (!stackTrace[i].callee && frames.size())
     134            break;
     135
    136136        unsigned line;
    137137        unsigned column;
    138138        stackTrace[i].computeLineAndColumn(line, column);
    139139        String functionName = stackTrace[i].friendlyFunctionName(exec);
    140         frames.append(ScriptCallFrame(functionName, stackTrace[i].friendlySourceURL(), line, column));
     140        frames.append(ScriptCallFrame(functionName, stackTrace[i].sourceURL, line, column));
    141141    }
    142142
    143     // Fallback to getting at least the line and sourceURL from the exception object if it has values and the exceptionStack doesn't.
    144     JSObject* exceptionObject = exception.toObject(exec);
    145     if (exception.isObject()) {
    146         int lineNumber;
    147         int columnNumber;
    148         String exceptionSourceURL;
    149         if (!frames.size()) {
    150             extractSourceInformationFromException(exec, exceptionObject, &lineNumber, &columnNumber, &exceptionSourceURL);
    151             frames.append(ScriptCallFrame(String(), exceptionSourceURL, lineNumber, columnNumber));
    152         } else {
    153             if (stackTrace[0].sourceURL.isEmpty()) {
    154                 const ScriptCallFrame& firstCallFrame = frames.first();
    155                 extractSourceInformationFromException(exec, exceptionObject, &lineNumber, &columnNumber, &exceptionSourceURL);
    156                 frames[0] = ScriptCallFrame(firstCallFrame.functionName(), exceptionSourceURL, lineNumber, columnNumber);
    157             }
     143    // FIXME: <http://webkit.org/b/115087> Web Inspector: WebCore::reportException should not evaluate JavaScript handling exceptions
     144    // Fallback to getting at least the line and sourceURL from the exception if it has values and the exceptionStack doesn't.
     145    if (frames.size() > 0) {
     146        const ScriptCallFrame& firstCallFrame = frames.first();
     147        JSObject* exceptionObject = exception.toObject(exec);
     148        if (exception.isObject() && firstCallFrame.sourceURL().isEmpty()) {
     149            JSValue lineValue = exceptionObject->getDirect(exec->vm(), Identifier(exec, "line"));
     150            int lineNumber = lineValue && lineValue.isNumber() ? int(lineValue.toNumber(exec)) : 0;
     151            JSValue columnValue = exceptionObject->getDirect(exec->vm(), Identifier(exec, "column"));
     152            int columnNumber = columnValue && columnValue.isNumber() ? int(columnValue.toNumber(exec)) : 0;
     153            JSValue sourceURLValue = exceptionObject->getDirect(exec->vm(), Identifier(exec, "sourceURL"));
     154            String exceptionSourceURL = sourceURLValue && sourceURLValue.isString() ? sourceURLValue.toString(exec)->value(exec) : ASCIILiteral("undefined");
     155            frames[0] = ScriptCallFrame(firstCallFrame.functionName(), exceptionSourceURL, lineNumber, columnNumber);
    158156        }
    159157    }
  • trunk/Source/JavaScriptCore/inspector/ScriptCallStackFactory.h

    r164507 r164554  
    4646
    4747// FIXME: The subtle differences between these should be eliminated.
     48JS_EXPORT_PRIVATE PassRefPtr<ScriptCallStack> createScriptCallStack(JSC::ExecState*, size_t maxStackSize, bool emptyIsAllowed);
    4849JS_EXPORT_PRIVATE PassRefPtr<ScriptCallStack> createScriptCallStack(JSC::ExecState*, size_t maxStackSize);
    49 JS_EXPORT_PRIVATE PassRefPtr<ScriptCallStack> createScriptCallStackForConsole(JSC::ExecState*, size_t maxStackSize);
     50JS_EXPORT_PRIVATE PassRefPtr<ScriptCallStack> createScriptCallStackForConsole(JSC::ExecState*);
    5051JS_EXPORT_PRIVATE PassRefPtr<ScriptCallStack> createScriptCallStackFromException(JSC::ExecState*, JSC::JSValue& exception, size_t maxStackSize);
    5152JS_EXPORT_PRIVATE PassRefPtr<ScriptArguments> createScriptArguments(JSC::ExecState*, unsigned skipArgumentCount);
  • trunk/Source/JavaScriptCore/inspector/agents/InspectorConsoleAgent.cpp

    r164507 r164554  
    8181
    8282    if (m_expiredConsoleMessageCount) {
    83         ConsoleMessage expiredMessage(MessageSource::Other, MessageType::Log, MessageLevel::Warning, String::format("%d console messages are not shown.", m_expiredConsoleMessageCount));
     83        ConsoleMessage expiredMessage(!isWorkerAgent(), MessageSource::Other, MessageType::Log, MessageLevel::Warning, String::format("%d console messages are not shown.", m_expiredConsoleMessageCount));
    8484        expiredMessage.addToFrontend(m_frontendDispatcher.get(), m_injectedScriptManager, false);
    8585    }
     
    129129    }
    130130
    131     addConsoleMessage(std::make_unique<ConsoleMessage>(source, type, level, message, callStack, requestIdentifier));
     131    addConsoleMessage(std::make_unique<ConsoleMessage>(!isWorkerAgent(), source, type, level, message, callStack, requestIdentifier));
    132132}
    133133
     
    142142    }
    143143
    144     addConsoleMessage(std::make_unique<ConsoleMessage>(source, type, level, message, arguments, state, requestIdentifier));
     144    addConsoleMessage(std::make_unique<ConsoleMessage>(!isWorkerAgent(), source, type, level, message, arguments, state, requestIdentifier));
    145145}
    146146
     
    155155    }
    156156
    157     addConsoleMessage(std::make_unique<ConsoleMessage>(source, type, level, message, scriptID, lineNumber, columnNumber, state, requestIdentifier));
     157    bool canGenerateCallStack = !isWorkerAgent() && m_frontendDispatcher;
     158    addConsoleMessage(std::make_unique<ConsoleMessage>(canGenerateCallStack, source, type, level, message, scriptID, lineNumber, columnNumber, state, requestIdentifier));
    158159}
    159160
     
    197198void InspectorConsoleAgent::count(JSC::ExecState* state, PassRefPtr<ScriptArguments> arguments)
    198199{
    199     RefPtr<ScriptCallStack> callStack(createScriptCallStackForConsole(state, ScriptCallStack::maxCallStackSizeToCapture));
     200    RefPtr<ScriptCallStack> callStack(createScriptCallStackForConsole(state));
    200201    const ScriptCallFrame& lastCaller = callStack->at(0);
    201202    // Follow Firebug's behavior of counting with null and undefined title in
  • trunk/Source/JavaScriptCore/inspector/agents/JSGlobalObjectDebuggerAgent.cpp

    r164507 r164554  
    7070void JSGlobalObjectDebuggerAgent::breakpointActionLog(JSC::ExecState* exec, const String& message)
    7171{
    72     m_consoleAgent->addMessageToConsole(MessageSource::JS, MessageType::Log, MessageLevel::Log, message, createScriptCallStack(exec, ScriptCallStack::maxCallStackSizeToCapture), 0);
     72    m_consoleAgent->addMessageToConsole(MessageSource::JS, MessageType::Log, MessageLevel::Log, message, createScriptCallStack(exec, ScriptCallStack::maxCallStackSizeToCapture, true), 0);
    7373}
    7474
  • trunk/Source/WebCore/ChangeLog

    r164553 r164554  
     12014-02-22  Dan Bernstein  <mitz@apple.com>
     2
     3        REGRESSION (r164507): Crash beneath JSGlobalObjectInspectorController::reportAPIException at facebook.com, twitter.com, youtube.com
     4        https://bugs.webkit.org/show_bug.cgi?id=129227
     5
     6        Reviewed by Eric Carlson.
     7
     8        Reverted r164507.
     9
     10        * bindings/js/JSDOMBinding.cpp:
     11        (WebCore::reportException):
     12        * inspector/InspectorResourceAgent.cpp:
     13        (WebCore::InspectorResourceAgent::buildInitiatorObject):
     14        * inspector/PageDebuggerAgent.cpp:
     15        (WebCore::PageDebuggerAgent::breakpointActionLog):
     16        * inspector/TimelineRecordFactory.cpp:
     17        (WebCore::TimelineRecordFactory::createGenericRecord):
     18        * page/Console.cpp:
     19        (WebCore::internalAddMessage):
     20        (WebCore::Console::profile):
     21        (WebCore::Console::profileEnd):
     22        (WebCore::Console::timeEnd):
     23        * page/ContentSecurityPolicy.cpp:
     24        (WebCore::gatherSecurityPolicyViolationEventData):
     25        (WebCore::ContentSecurityPolicy::reportViolation):
     26        * page/DOMWindow.cpp:
     27        (WebCore::DOMWindow::postMessage):
     28
    1292014-02-22  Joseph Pecoraro  <pecoraro@apple.com>
    230
  • trunk/Source/WebCore/bindings/js/JSDOMBinding.cpp

    r164507 r164554  
    172172    int columnNumber = 0;
    173173    String exceptionSourceURL;
    174     if (const ScriptCallFrame* callFrame = callStack->firstNonNativeCallFrame()) {
    175         lineNumber = callFrame->lineNumber();
    176         columnNumber = callFrame->columnNumber();
    177         exceptionSourceURL = callFrame->sourceURL();
     174    if (callStack->size()) {
     175        const ScriptCallFrame& frame = callStack->at(0);
     176        lineNumber = frame.lineNumber();
     177        columnNumber = frame.columnNumber();
     178        exceptionSourceURL = frame.sourceURL();
     179    } else {
     180        // There may not be an exceptionStack for a <script> SyntaxError. Fallback to getting at least the line and sourceURL from the exception.
     181        JSObject* exceptionObject = exception.toObject(exec);
     182        JSValue lineValue = exceptionObject->getDirect(exec->vm(), Identifier(exec, "line"));
     183        lineNumber = lineValue && lineValue.isNumber() ? int(lineValue.toNumber(exec)) : 0;
     184        JSValue columnValue = exceptionObject->getDirect(exec->vm(), Identifier(exec, "column"));
     185        columnNumber = columnValue && columnValue.isNumber() ? int(columnValue.toNumber(exec)) : 0;
     186        JSValue sourceURLValue = exceptionObject->getDirect(exec->vm(), Identifier(exec, "sourceURL"));
     187        exceptionSourceURL = sourceURLValue && sourceURLValue.isString() ? sourceURLValue.toString(exec)->value(exec) : ASCIILiteral("undefined");
    178188    }
    179189
  • trunk/Source/WebCore/inspector/InspectorResourceAgent.cpp

    r164507 r164554  
    440440PassRefPtr<Inspector::TypeBuilder::Network::Initiator> InspectorResourceAgent::buildInitiatorObject(Document* document)
    441441{
    442     RefPtr<ScriptCallStack> stackTrace = createScriptCallStack(JSMainThreadExecState::currentState(), ScriptCallStack::maxCallStackSizeToCapture);
     442    RefPtr<ScriptCallStack> stackTrace = createScriptCallStack(JSMainThreadExecState::currentState(), ScriptCallStack::maxCallStackSizeToCapture, true);
    443443    if (stackTrace && stackTrace->size() > 0) {
    444444        RefPtr<Inspector::TypeBuilder::Network::Initiator> initiatorObject = Inspector::TypeBuilder::Network::Initiator::create()
  • trunk/Source/WebCore/inspector/PageDebuggerAgent.cpp

    r164507 r164554  
    118118void PageDebuggerAgent::breakpointActionLog(JSC::ExecState* exec, const String& message)
    119119{
    120     m_pageAgent->page()->console().addMessage(MessageSource::JS, MessageLevel::Log, message, createScriptCallStack(exec, ScriptCallStack::maxCallStackSizeToCapture));
     120    m_pageAgent->page()->console().addMessage(MessageSource::JS, MessageLevel::Log, message, createScriptCallStack(exec, ScriptCallStack::maxCallStackSizeToCapture, true));
    121121}
    122122
  • trunk/Source/WebCore/inspector/TimelineRecordFactory.cpp

    r164507 r164554  
    5858
    5959    if (maxCallStackDepth) {
    60         RefPtr<ScriptCallStack> stackTrace = createScriptCallStack(JSMainThreadExecState::currentState(), maxCallStackDepth);
     60        RefPtr<ScriptCallStack> stackTrace = createScriptCallStack(JSMainThreadExecState::currentState(), maxCallStackDepth, true);
    6161        if (stackTrace && stackTrace->size())
    6262            record->setValue("stackTrace", stackTrace->buildInspectorArray());
  • trunk/Source/WebCore/page/Console.cpp

    r164507 r164554  
    7878
    7979    size_t stackSize = printTrace ? ScriptCallStack::maxCallStackSizeToCapture : 1;
    80     RefPtr<ScriptCallStack> callStack(createScriptCallStackForConsole(state, stackSize));
     80    RefPtr<ScriptCallStack> callStack(createScriptCallStack(state, stackSize));
    8181    const ScriptCallFrame& lastCaller = callStack->at(0);
    8282
     
    204204    ScriptProfiler::start(state, resolvedTitle);
    205205
    206     RefPtr<ScriptCallStack> callStack(createScriptCallStackForConsole(state, 1));
     206    RefPtr<ScriptCallStack> callStack(createScriptCallStack(state, 1));
    207207    const ScriptCallFrame& lastCaller = callStack->at(0);
    208208    InspectorInstrumentation::addStartProfilingMessageToConsole(page, resolvedTitle, lastCaller.lineNumber(), lastCaller.columnNumber(), lastCaller.sourceURL());
     
    223223
    224224    m_profiles.append(profile);
    225     RefPtr<ScriptCallStack> callStack(createScriptCallStackForConsole(state, 1));
     225    RefPtr<ScriptCallStack> callStack(createScriptCallStack(state, 1));
    226226    InspectorInstrumentation::addProfile(page, profile, callStack);
    227227}
     
    234234void Console::timeEnd(JSC::ExecState* state, const String& title)
    235235{
    236     RefPtr<ScriptCallStack> callStack(createScriptCallStackForConsole(state, 1));
     236    RefPtr<ScriptCallStack> callStack(createScriptCallStackForConsole(state));
    237237    InspectorInstrumentation::stopConsoleTiming(m_frame, title, callStack.release());
    238238}
  • trunk/Source/WebCore/page/ContentSecurityPolicy.cpp

    r164507 r164554  
    170170    ASSERT_NOT_REACHED();
    171171    return FeatureObserver::NumberOfFeatures;
     172}
     173
     174const ScriptCallFrame& getFirstNonNativeFrame(PassRefPtr<ScriptCallStack> stack)
     175{
     176    int frameNumber = 0;
     177    if (!stack->at(0).lineNumber() && stack->size() > 1 && stack->at(1).lineNumber())
     178        frameNumber = 1;
     179
     180    return stack->at(frameNumber);
    172181}
    173182
     
    17191728    init.lineNumber = 0;
    17201729
    1721     RefPtr<ScriptCallStack> stack = createScriptCallStack(JSMainThreadExecState::currentState(), 2);
    1722     const ScriptCallFrame* callFrame = stack->firstNonNativeCallFrame();
    1723     if (callFrame && callFrame->lineNumber()) {
    1724         URL source = URL(URL(), callFrame->sourceURL());
     1730    RefPtr<ScriptCallStack> stack = createScriptCallStack(JSMainThreadExecState::currentState(), 2, false);
     1731    if (!stack)
     1732        return;
     1733
     1734    const ScriptCallFrame& callFrame = getFirstNonNativeFrame(stack);
     1735
     1736    if (callFrame.lineNumber()) {
     1737        URL source = URL(ParsedURLString, callFrame.sourceURL());
    17251738        init.sourceFile = stripURLForUseInReport(document, source);
    1726         init.lineNumber = callFrame->lineNumber();
     1739        init.lineNumber = callFrame.lineNumber();
    17271740    }
    17281741}
     
    17651778
    17661779    RefPtr<InspectorObject> cspReport = InspectorObject::create();
    1767     cspReport->setString(ASCIILiteral("document-uri"), document->url().strippedForUseAsReferrer());
    1768     cspReport->setString(ASCIILiteral("referrer"), document->referrer());
    1769     cspReport->setString(ASCIILiteral("violated-directive"), directiveText);
     1780    cspReport->setString("document-uri", document->url().strippedForUseAsReferrer());
     1781    cspReport->setString("referrer", document->referrer());
     1782    cspReport->setString("violated-directive", directiveText);
    17701783#if ENABLE(CSP_NEXT)
    17711784    if (experimentalFeaturesEnabled())
    1772         cspReport->setString(ASCIILiteral("effective-directive"), effectiveDirective);
     1785        cspReport->setString("effective-directive", effectiveDirective);
    17731786#else
    17741787    UNUSED_PARAM(effectiveDirective);
    17751788#endif
    1776     cspReport->setString(ASCIILiteral("original-policy"), header);
    1777     cspReport->setString(ASCIILiteral("blocked-uri"), stripURLForUseInReport(document, blockedURL));
    1778 
    1779     RefPtr<ScriptCallStack> stack = createScriptCallStack(JSMainThreadExecState::currentState(), 2);
    1780     const ScriptCallFrame* callFrame = stack->firstNonNativeCallFrame();
    1781     if (callFrame && callFrame->lineNumber()) {
    1782         URL source = URL(URL(), callFrame->sourceURL());
    1783         cspReport->setString(ASCIILiteral("source-file"), stripURLForUseInReport(document, source));
    1784         cspReport->setNumber(ASCIILiteral("line-number"), callFrame->lineNumber());
     1789    cspReport->setString("original-policy", header);
     1790    cspReport->setString("blocked-uri", stripURLForUseInReport(document, blockedURL));
     1791
     1792    RefPtr<ScriptCallStack> stack = createScriptCallStack(JSMainThreadExecState::currentState(), 2, false);
     1793    if (stack) {
     1794        const ScriptCallFrame& callFrame = getFirstNonNativeFrame(stack);
     1795
     1796        if (callFrame.lineNumber()) {
     1797            URL source = URL(ParsedURLString, callFrame.sourceURL());
     1798            cspReport->setString("source-file", stripURLForUseInReport(document, source));
     1799            cspReport->setNumber("line-number", callFrame.lineNumber());
     1800        }
    17851801    }
    17861802
    17871803    RefPtr<InspectorObject> reportObject = InspectorObject::create();
    1788     reportObject->setObject(ASCIILiteral("csp-report"), cspReport.release());
     1804    reportObject->setObject("csp-report", cspReport.release());
    17891805
    17901806    RefPtr<FormData> report = FormData::create(reportObject->toJSONString().utf8());
  • trunk/Source/WebCore/page/DOMWindow.cpp

    r164507 r164554  
    847847    RefPtr<ScriptCallStack> stackTrace;
    848848    if (InspectorInstrumentation::consoleAgentEnabled(sourceDocument))
    849         stackTrace = createScriptCallStack(JSMainThreadExecState::currentState(), ScriptCallStack::maxCallStackSizeToCapture);
     849        stackTrace = createScriptCallStack(JSMainThreadExecState::currentState(), ScriptCallStack::maxCallStackSizeToCapture, true);
    850850
    851851    // Schedule the message.
  • trunk/Source/WebInspectorUI/ChangeLog

    r164543 r164554  
     12014-02-22  Dan Bernstein  <mitz@apple.com>
     2
     3        REGRESSION (r164507): Crash beneath JSGlobalObjectInspectorController::reportAPIException at facebook.com, twitter.com, youtube.com
     4        https://bugs.webkit.org/show_bug.cgi?id=129227
     5
     6        Reviewed by Eric Carlson.
     7
     8        Reverted r164507.
     9
     10        * UserInterface/Views/ConsoleMessageImpl.js:
     11        (WebInspector.ConsoleMessageImpl.prototype._formatMessage):
     12        (WebInspector.ConsoleMessageImpl.prototype._populateStackTraceTreeElement):
     13
    1142014-02-21  Timothy Hatcher  <timothy@apple.com>
    215
  • trunk/Source/WebInspectorUI/UserInterface/Views/ConsoleMessageImpl.js

    r164543 r164554  
    110110
    111111        if (this.source !== WebInspector.ConsoleMessage.MessageSource.Network || this._request) {
    112             var firstNonNativeCallFrame = this._firstNonNativeCallFrame();
    113             if (firstNonNativeCallFrame) {
    114                 var urlElement = this._linkifyCallFrame(firstNonNativeCallFrame);
     112            if (this._stackTrace && this._stackTrace.length && this._stackTrace[0].url) {
     113                var urlElement = this._linkifyCallFrame(this._stackTrace[0]);
    115114                this._formattedMessage.appendChild(urlElement);
    116             } else if (this.url && !this._shouldHideURL(this.url)) {
     115            } else if (this.url && this.url !== "undefined") {
    117116                var urlElement = this._linkifyLocation(this.url, this.line, this.column);
    118117                this._formattedMessage.appendChild(urlElement);
     
    145144    {
    146145        return !!this._stackTrace && this._stackTrace.length && (this.source === WebInspector.ConsoleMessage.MessageSource.Network || this.level === WebInspector.ConsoleMessage.MessageLevel.Error || this.type === WebInspector.ConsoleMessage.MessageType.Trace);
    147     },
    148 
    149     _shouldHideURL: function(url)
    150     {
    151         return url === "undefined" || url === "[native code]";
    152     },
    153 
    154     _firstNonNativeCallFrame: function()
    155     {
    156         if (!this._stackTrace)
    157             return null;
    158 
    159         for (var i = 0; i < this._stackTrace.length; i++) {
    160             var frame = this._stackTrace[i];
    161             if (!frame.url || frame.url === "[native code]")
    162                 continue;
    163             return frame;
    164         }
    165 
    166         return null;
    167146    },
    168147
     
    548527            content.appendChild(messageTextElement);
    549528
    550             if (frame.url && !this._shouldHideURL(frame.url)) {
     529            if (frame.url) {
    551530                var urlElement = this._linkifyCallFrame(frame);
    552531                content.appendChild(urlElement);
Note: See TracChangeset for help on using the changeset viewer.