Changeset 246850 in webkit


Ignore:
Timestamp:
Jun 26, 2019 3:25:48 PM (5 years ago)
Author:
Joseph Pecoraro
Message:

Web Inspector: Implement console.countReset
https://bugs.webkit.org/show_bug.cgi?id=199200

Reviewed by Devin Rousso.

Source/JavaScriptCore:

  • inspector/JSGlobalObjectConsoleClient.cpp:

(Inspector::JSGlobalObjectConsoleClient::countReset):

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

(Inspector::InspectorConsoleAgent::getCounterLabel):
(Inspector::InspectorConsoleAgent::count):
(Inspector::InspectorConsoleAgent::countReset):

  • inspector/agents/InspectorConsoleAgent.h:
  • runtime/ConsoleClient.h:
  • runtime/ConsoleObject.cpp:

(JSC::ConsoleObject::finishCreation):
(JSC::consoleProtoFuncCountReset):

Source/WebCore:

Updated existing tests.

  • inspector/InspectorInstrumentation.cpp:

(WebCore::InspectorInstrumentation::consoleCountImpl):
(WebCore::InspectorInstrumentation::consoleCountResetImpl):

  • inspector/InspectorInstrumentation.h:

(WebCore::InspectorInstrumentation::consoleCountReset):

  • page/PageConsoleClient.cpp:

(WebCore::PageConsoleClient::countReset):

  • page/PageConsoleClient.h:
  • workers/WorkerConsoleClient.cpp:

(WebCore::WorkerConsoleClient::countReset):

  • workers/WorkerConsoleClient.h:
  • worklets/WorkletConsoleClient.cpp:

(WebCore::WorkletConsoleClient::countReset):

  • worklets/WorkletConsoleClient.h:

LayoutTests:

  • inspector/console/console-count-expected.txt:
  • inspector/console/console-count.html:
  • js/console-expected.txt:
Location:
trunk
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r246846 r246850  
     12019-06-26  Joseph Pecoraro  <pecoraro@apple.com>
     2
     3        Web Inspector: Implement console.countReset
     4        https://bugs.webkit.org/show_bug.cgi?id=199200
     5
     6        Reviewed by Devin Rousso.
     7
     8        * inspector/console/console-count-expected.txt:
     9        * inspector/console/console-count.html:
     10        * js/console-expected.txt:
     11
    1122019-06-26  Myles C. Maxfield  <mmaxfield@apple.com>
    213
  • trunk/LayoutTests/inspector/console/console-count-expected.txt

    r200535 r246850  
    1 Tests for the console.count API.
     1Tests for the console.count and console.countReset APIs.
    22
    33
    44== Running test suite: console.count
    5 -- Running test case: NoArguments
     5-- Running test case: console.count.NoArguments
    66Global: 1
    77Global: 2
     
    2121Global: 16
    2222
    23 -- Running test case: WithLabel
     23-- Running test case: console.count.WithLabel
    2424alpha: 1
    2525alpha: 2
     
    4343alpha: 15
    4444
     45-- Running test case: console.countReset.NoCounter
     46PASS: Should produce a warning console message.
     47Counter "missing-label-1" does not exist
     48PASS: Should produce a warning console message.
     49Counter "missing-label-2" does not exist
     50
     51-- Running test case: console.countReset.Basic
     52reset-label: 1
     53reset-label: 2
     54reset-label: 3
     55reset-label: 4
     56reset-label: 5
     57reset-label: 6
     58reset-label: 1
     59reset-label: 2
     60reset-label: 1
     61reset-label: 2
     62
  • trunk/LayoutTests/inspector/console/console-count.html

    r236766 r246850  
    2222}
    2323
     24function triggerConsoleResetWarnings() {
     25    console.countReset("missing-label-1");
     26    console.countReset("missing-label-2");
     27}
     28
     29function triggerConsoleResetBasic() {
     30    for (let i = 1; i <= 10; ++i) {
     31        console.count("reset-label");
     32        if (i === 6 || i === 8)
     33            console.countReset("reset-label");
     34    }
     35}
     36
    2437function test()
    2538{
     
    2740
    2841    suite.addTestCase({
    29         name: "NoArguments",
     42        name: "console.count.NoArguments",
    3043        description: "No arguments increments a shared global counter.",
    3144        test(resolve, reject) {
     
    4255            }
    4356
    44             InspectorTest.evaluateInPage("triggerCountNoArguments()"); // 15
    45             InspectorTest.evaluateInPage("console.count()"); // 1
     57            InspectorTest.evaluateInPage(`triggerCountNoArguments()`); // 15
     58            InspectorTest.evaluateInPage(`console.count()`); // 1
    4659        }
    4760    });
    4861
    4962    suite.addTestCase({
    50         name: "WithLabel",
     63        name: "console.count.WithLabel",
    5164        description: "Labeled counters increment the label.",
    5265        test(resolve, reject) {
     
    6376            }
    6477
    65             InspectorTest.evaluateInPage("triggerLabeledCounters()");
     78            InspectorTest.evaluateInPage(`triggerLabeledCounters()`);
     79        }
     80    });
     81
     82    suite.addTestCase({
     83        name: "console.countReset.NoCounter",
     84        description: "A reset of a non-existing counter should warn.",
     85        test(resolve, reject) {
     86            let seen = 0;
     87            const expected = 2;
     88            WI.consoleManager.addEventListener(WI.ConsoleManager.Event.MessageAdded, handler);
     89            function handler(event) {
     90                let message = event.data.message;
     91                InspectorTest.expectEqual(message.level, WI.ConsoleMessage.MessageLevel.Warning, "Should produce a warning console message.");
     92                InspectorTest.log(message.messageText);
     93                if (++seen === expected) {
     94                    WI.consoleManager.removeEventListener(WI.ConsoleManager.Event.MessageAdded, handler);
     95                    resolve();
     96                }
     97            }
     98
     99            InspectorTest.evaluateInPage(`triggerConsoleResetWarnings()`);
     100        }
     101    });
     102
     103    suite.addTestCase({
     104        name: "console.countReset.Basic",
     105        description: "A reset of a non-existing counter should warn.",
     106        test(resolve, reject) {
     107            let seen = 0;
     108            const expected = 10;
     109            WI.consoleManager.addEventListener(WI.ConsoleManager.Event.MessageAdded, handler);
     110            function handler(event) {
     111                let message = event.data.message;
     112                InspectorTest.log(message.messageText);
     113                if (++seen === expected) {
     114                    WI.consoleManager.removeEventListener(WI.ConsoleManager.Event.MessageAdded, handler);
     115                    resolve();
     116                }
     117            }
     118
     119            InspectorTest.evaluateInPage(`triggerConsoleResetBasic()`);
    66120        }
    67121    });
     
    72126</head>
    73127<body onload="runTest()">
    74 <p>Tests for the console.count API.</p>
     128<p>Tests for the console.count and console.countReset APIs.</p>
    75129</body>
    76130</html>
  • trunk/LayoutTests/js/console-expected.txt

    r246798 r246850  
    101101PASS descriptor.enumerable is true
    102102
     103console.countReset
     104PASS typeof console.countReset is "function"
     105PASS console.countReset.length is 0
     106PASS descriptor.configurable is true
     107PASS descriptor.writable is true
     108PASS descriptor.enumerable is true
     109
    103110console.profile
    104111PASS typeof console.profile is "function"
  • trunk/Source/JavaScriptCore/ChangeLog

    r246837 r246850  
     12019-06-26  Joseph Pecoraro  <pecoraro@apple.com>
     2
     3        Web Inspector: Implement console.countReset
     4        https://bugs.webkit.org/show_bug.cgi?id=199200
     5
     6        Reviewed by Devin Rousso.
     7
     8        * inspector/JSGlobalObjectConsoleClient.cpp:
     9        (Inspector::JSGlobalObjectConsoleClient::countReset):
     10        * inspector/JSGlobalObjectConsoleClient.h:
     11        * inspector/agents/InspectorConsoleAgent.cpp:
     12        (Inspector::InspectorConsoleAgent::getCounterLabel):
     13        (Inspector::InspectorConsoleAgent::count):
     14        (Inspector::InspectorConsoleAgent::countReset):
     15        * inspector/agents/InspectorConsoleAgent.h:
     16        * runtime/ConsoleClient.h:
     17        * runtime/ConsoleObject.cpp:
     18        (JSC::ConsoleObject::finishCreation):
     19        (JSC::consoleProtoFuncCountReset):
     20
    1212019-06-26  Keith Miller  <keith_miller@apple.com>
    222
  • trunk/Source/JavaScriptCore/inspector/JSGlobalObjectConsoleClient.cpp

    r246798 r246850  
    7474{
    7575    m_consoleAgent->count(exec, WTFMove(arguments));
     76}
     77
     78void JSGlobalObjectConsoleClient::countReset(ExecState* exec, Ref<ScriptArguments>&& arguments)
     79{
     80    m_consoleAgent->countReset(exec, WTFMove(arguments));
    7681}
    7782
  • trunk/Source/JavaScriptCore/inspector/JSGlobalObjectConsoleClient.h

    r246798 r246850  
    5151    void messageWithTypeAndLevel(MessageType, MessageLevel, JSC::ExecState*, Ref<ScriptArguments>&&) override;
    5252    void count(JSC::ExecState*, Ref<ScriptArguments>&&) override;
     53    void countReset(JSC::ExecState*, Ref<ScriptArguments>&&) override;
    5354    void profile(JSC::ExecState*, const String& title) override;
    5455    void profileEnd(JSC::ExecState*, const String& title) override;
  • trunk/Source/JavaScriptCore/inspector/agents/InspectorConsoleAgent.cpp

    r246798 r246850  
    209209}
    210210
    211 void InspectorConsoleAgent::count(JSC::ExecState* state, Ref<ScriptArguments>&& arguments)
    212 {
    213     if (!m_injectedScriptManager.inspectorEnvironment().developerExtrasEnabled())
    214         return;
    215 
    216     Ref<ScriptCallStack> callStack = createScriptCallStackForConsole(state);
    217 
    218     String title;
    219     String identifier;
     211void InspectorConsoleAgent::getCounterLabel(Ref<ScriptArguments>&& arguments, String& title, String& identifier)
     212{
    220213    if (!arguments->argumentCount()) {
    221214        // '@' prefix for engine generated labels.
     
    227220        identifier = makeString('#', title);
    228221    }
     222}
     223
     224void InspectorConsoleAgent::count(JSC::ExecState* state, Ref<ScriptArguments>&& arguments)
     225{
     226    if (!m_injectedScriptManager.inspectorEnvironment().developerExtrasEnabled())
     227        return;
     228
     229    String title;
     230    String identifier;
     231    getCounterLabel(WTFMove(arguments), title, identifier);
    229232
    230233    auto result = m_counts.add(identifier, 1);
     
    235238
    236239    String message = makeString(title, ": ", result.iterator->value);
     240    Ref<ScriptCallStack> callStack = createScriptCallStackForConsole(state);
    237241    addMessageToConsole(std::make_unique<ConsoleMessage>(MessageSource::ConsoleAPI, MessageType::Log, MessageLevel::Debug, message, WTFMove(callStack)));
     242}
     243
     244void InspectorConsoleAgent::countReset(JSC::ExecState*, Ref<ScriptArguments>&& arguments)
     245{
     246    if (!m_injectedScriptManager.inspectorEnvironment().developerExtrasEnabled())
     247        return;
     248
     249    String title;
     250    String identifier;
     251    getCounterLabel(WTFMove(arguments), title, identifier);
     252
     253    auto it = m_counts.find(identifier);
     254    if (it == m_counts.end()) {
     255        // FIXME: Send an enum to the frontend for localization?
     256        String warning = makeString("Counter \"", title, "\" does not exist");
     257        addMessageToConsole(std::make_unique<ConsoleMessage>(MessageSource::ConsoleAPI, MessageType::Log, MessageLevel::Warning, warning));
     258        return;
     259    }
     260
     261    it->value = 0;
     262
     263    // FIXME: Web Inspector should have a better UI for counters, but for now we just log an updated counter value.
    238264}
    239265
  • trunk/Source/JavaScriptCore/inspector/agents/InspectorConsoleAgent.h

    r246798 r246850  
    7676    void takeHeapSnapshot(const String& title);
    7777    void count(JSC::ExecState*, Ref<ScriptArguments>&&);
     78    void countReset(JSC::ExecState*, Ref<ScriptArguments>&&);
    7879
    7980    void getLoggingChannels(ErrorString&, RefPtr<JSON::ArrayOf<Protocol::Console::Channel>>&) override;
     
    8182
    8283protected:
     84    void getCounterLabel(Ref<ScriptArguments>&&, String& title, String& identifier);
    8385    void addConsoleMessage(std::unique_ptr<ConsoleMessage>);
    8486
  • trunk/Source/JavaScriptCore/runtime/ConsoleClient.h

    r246798 r246850  
    5757    virtual void messageWithTypeAndLevel(MessageType, MessageLevel, JSC::ExecState*, Ref<Inspector::ScriptArguments>&&) = 0;
    5858    virtual void count(ExecState*, Ref<Inspector::ScriptArguments>&&) = 0;
     59    virtual void countReset(ExecState*, Ref<Inspector::ScriptArguments>&&) = 0;
    5960    virtual void profile(ExecState*, const String& title) = 0;
    6061    virtual void profileEnd(ExecState*, const String& title) = 0;
  • trunk/Source/JavaScriptCore/runtime/ConsoleObject.cpp

    r246798 r246850  
    4949static EncodedJSValue JSC_HOST_CALL consoleProtoFuncAssert(ExecState*);
    5050static EncodedJSValue JSC_HOST_CALL consoleProtoFuncCount(ExecState*);
     51static EncodedJSValue JSC_HOST_CALL consoleProtoFuncCountReset(ExecState*);
    5152static EncodedJSValue JSC_HOST_CALL consoleProtoFuncProfile(ExecState*);
    5253static EncodedJSValue JSC_HOST_CALL consoleProtoFuncProfileEnd(ExecState*);
     
    9192    JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("assert", consoleProtoFuncAssert, static_cast<unsigned>(PropertyAttribute::None), 0);
    9293    JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->count, consoleProtoFuncCount, static_cast<unsigned>(PropertyAttribute::None), 0);
     94    JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("countReset", consoleProtoFuncCountReset, static_cast<unsigned>(PropertyAttribute::None), 0);
    9395    JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("profile", consoleProtoFuncProfile, static_cast<unsigned>(PropertyAttribute::None), 0);
    9496    JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("profileEnd", consoleProtoFuncProfileEnd, static_cast<unsigned>(PropertyAttribute::None), 0);
     
    226228}
    227229
     230static EncodedJSValue JSC_HOST_CALL consoleProtoFuncCountReset(ExecState* exec)
     231{
     232    ConsoleClient* client = exec->lexicalGlobalObject()->consoleClient();
     233    if (!client)
     234        return JSValue::encode(jsUndefined());
     235
     236    client->countReset(exec, Inspector::createScriptArguments(exec, 0));
     237    return JSValue::encode(jsUndefined());
     238}
     239
    228240static EncodedJSValue JSC_HOST_CALL consoleProtoFuncProfile(ExecState* exec)
    229241{
  • trunk/Source/WebCore/ChangeLog

    r246849 r246850  
     12019-06-26  Joseph Pecoraro  <pecoraro@apple.com>
     2
     3        Web Inspector: Implement console.countReset
     4        https://bugs.webkit.org/show_bug.cgi?id=199200
     5
     6        Reviewed by Devin Rousso.
     7
     8        Updated existing tests.
     9
     10        * inspector/InspectorInstrumentation.cpp:
     11        (WebCore::InspectorInstrumentation::consoleCountImpl):
     12        (WebCore::InspectorInstrumentation::consoleCountResetImpl):
     13        * inspector/InspectorInstrumentation.h:
     14        (WebCore::InspectorInstrumentation::consoleCountReset):
     15        * page/PageConsoleClient.cpp:
     16        (WebCore::PageConsoleClient::countReset):
     17        * page/PageConsoleClient.h:
     18        * workers/WorkerConsoleClient.cpp:
     19        (WebCore::WorkerConsoleClient::countReset):
     20        * workers/WorkerConsoleClient.h:
     21        * worklets/WorkletConsoleClient.cpp:
     22        (WebCore::WorkletConsoleClient::countReset):
     23        * worklets/WorkletConsoleClient.h:
     24
    1252019-06-26  Antoine Quint  <graouts@apple.com>
    226
  • trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp

    r246798 r246850  
    854854void InspectorInstrumentation::consoleCountImpl(InstrumentingAgents& instrumentingAgents, JSC::ExecState* state, Ref<ScriptArguments>&& arguments)
    855855{
    856     if (!instrumentingAgents.inspectorEnvironment().developerExtrasEnabled())
    857         return;
    858 
    859856    if (WebConsoleAgent* consoleAgent = instrumentingAgents.webConsoleAgent())
    860857        consoleAgent->count(state, WTFMove(arguments));
     858}
     859
     860void InspectorInstrumentation::consoleCountResetImpl(InstrumentingAgents& instrumentingAgents, JSC::ExecState* state, Ref<ScriptArguments>&& arguments)
     861{
     862    if (WebConsoleAgent* consoleAgent = instrumentingAgents.webConsoleAgent())
     863        consoleAgent->countReset(state, WTFMove(arguments));
    861864}
    862865
  • trunk/Source/WebCore/inspector/InspectorInstrumentation.h

    r246798 r246850  
    224224    static void consoleCount(Page&, JSC::ExecState*, Ref<Inspector::ScriptArguments>&&);
    225225    static void consoleCount(WorkerGlobalScope&, JSC::ExecState*, Ref<Inspector::ScriptArguments>&&);
     226    static void consoleCountReset(Page&, JSC::ExecState*, Ref<Inspector::ScriptArguments>&&);
     227    static void consoleCountReset(WorkerGlobalScope&, JSC::ExecState*, Ref<Inspector::ScriptArguments>&&);
     228
    226229    static void takeHeapSnapshot(Frame&, const String& title);
    227230    static void startConsoleTiming(Frame&, const String& title);
     
    404407
    405408    static void consoleCountImpl(InstrumentingAgents&, JSC::ExecState*, Ref<Inspector::ScriptArguments>&&);
     409    static void consoleCountResetImpl(InstrumentingAgents&, JSC::ExecState*, Ref<Inspector::ScriptArguments>&&);
    406410    static void takeHeapSnapshotImpl(InstrumentingAgents&, const String& title);
    407411    static void startConsoleTimingImpl(InstrumentingAgents&, Frame&, const String& title);
     
    13941398}
    13951399
     1400inline void InspectorInstrumentation::consoleCountReset(Page& page, JSC::ExecState* state, Ref<Inspector::ScriptArguments>&& arguments)
     1401{
     1402    consoleCountResetImpl(instrumentingAgentsForPage(page), state, WTFMove(arguments));
     1403}
     1404
     1405inline void InspectorInstrumentation::consoleCountReset(WorkerGlobalScope& workerGlobalScope, JSC::ExecState* state, Ref<Inspector::ScriptArguments>&& arguments)
     1406{
     1407    consoleCountResetImpl(instrumentingAgentsForWorkerGlobalScope(workerGlobalScope), state, WTFMove(arguments));
     1408}
     1409
    13961410inline void InspectorInstrumentation::takeHeapSnapshot(Frame& frame, const String& title)
    13971411{
  • trunk/Source/WebCore/page/PageConsoleClient.cpp

    r246798 r246850  
    176176}
    177177
     178void PageConsoleClient::countReset(JSC::ExecState* exec, Ref<ScriptArguments>&& arguments)
     179{
     180    InspectorInstrumentation::consoleCountReset(m_page, exec, WTFMove(arguments));
     181}
     182
    178183void PageConsoleClient::profile(JSC::ExecState* exec, const String& title)
    179184{
  • trunk/Source/WebCore/page/PageConsoleClient.h

    r246798 r246850  
    6969    void messageWithTypeAndLevel(MessageType, MessageLevel, JSC::ExecState*, Ref<Inspector::ScriptArguments>&&) override;
    7070    void count(JSC::ExecState*, Ref<Inspector::ScriptArguments>&&) override;
     71    void countReset(JSC::ExecState*, Ref<Inspector::ScriptArguments>&&) override;
    7172    void profile(JSC::ExecState*, const String& title) override;
    7273    void profileEnd(JSC::ExecState*, const String& title) override;
  • trunk/Source/WebCore/workers/WorkerConsoleClient.cpp

    r246798 r246850  
    5656}
    5757
     58void WorkerConsoleClient::countReset(JSC::ExecState* exec, Ref<ScriptArguments>&& arguments)
     59{
     60    InspectorInstrumentation::consoleCountReset(m_workerGlobalScope, exec, WTFMove(arguments));
     61}
     62
    5863void WorkerConsoleClient::time(JSC::ExecState*, const String& title)
    5964{
  • trunk/Source/WebCore/workers/WorkerConsoleClient.h

    r246798 r246850  
    4545    void messageWithTypeAndLevel(MessageType, MessageLevel, JSC::ExecState*, Ref<Inspector::ScriptArguments>&&) override;
    4646    void count(JSC::ExecState*, Ref<Inspector::ScriptArguments>&&) override;
     47    void countReset(JSC::ExecState*, Ref<Inspector::ScriptArguments>&&) override;
    4748    void profile(JSC::ExecState*, const String& title) override;
    4849    void profileEnd(JSC::ExecState*, const String& title) override;
  • trunk/Source/WebCore/worklets/WorkletConsoleClient.cpp

    r246798 r246850  
    5454
    5555void WorkletConsoleClient::count(JSC::ExecState*, Ref<ScriptArguments>&&) { }
     56void WorkletConsoleClient::countReset(JSC::ExecState*, Ref<ScriptArguments>&&) { }
    5657
    5758void WorkletConsoleClient::time(JSC::ExecState*, const String&) { }
  • trunk/Source/WebCore/worklets/WorkletConsoleClient.h

    r246798 r246850  
    4747    void messageWithTypeAndLevel(MessageType, MessageLevel, JSC::ExecState*, Ref<Inspector::ScriptArguments>&&) final;
    4848    void count(JSC::ExecState*, Ref<Inspector::ScriptArguments>&&) final;
     49    void countReset(JSC::ExecState*, Ref<Inspector::ScriptArguments>&&) final;
    4950    void profile(JSC::ExecState*, const String& title) final;
    5051    void profileEnd(JSC::ExecState*, const String& title) final;
Note: See TracChangeset for help on using the changeset viewer.