Title: [250655] trunk
Revision
250655
Author
[email protected]
Date
2019-10-03 08:46:30 -0700 (Thu, 03 Oct 2019)

Log Message

Web Inspector: tests under LayoutTests/inspector/debugger are flaky
https://bugs.webkit.org/show_bug.cgi?id=137131
<rdar://problem/18461335>

Patch by Yury Semikhatsky <[email protected]> on 2019-10-03
Reviewed by Devin Rousso.

Source/_javascript_Core:

Changed breakpoint resolution logic to make it consistent across platforms and
better handle the case when there are several DebuggerPausePositions at the same
offset (but with different types).

* bytecode/CodeBlock.cpp:
(JSC::CodeBlock::hasOpDebugForLineAndColumn):
* bytecode/CodeBlock.h:
* debugger/Breakpoint.h: Removed Breakpoint::unspecifiedColumn, Optional<unsigned>
is used instead where needed. It allows to avoid code that relies on (int)UINT_MAX => -1
conversion.

* debugger/Debugger.cpp:
(JSC::Debugger::resolveBreakpoint): clarified that in the map columns are 0-based.
* debugger/DebuggerParseData.cpp:
(JSC::DebuggerPausePositions::breakpointLocationForLineColumn): replaced custom
binary search with std::lower_bound. If there are several pause positions at the
same offset they will be sorted by the type and the algorithm is guaranteed to see
leftmost one first.

(JSC::DebuggerPausePositions::sort): use type as secondary ordering component.
* debugger/DebuggerParseData.h: Rearranged type constants so that Enter < Pause < Leave
this change along with sorting by type should guarantee that in case of several pause
positions at the same line Enter goes before Pause before Leave and the breakpoint
resolution will yield result similar to that when each pause locations has different
position.

* inspector/protocol/Debugger.json: clarified that positions are 0-based.
* parser/ParserTokens.h:
(JSC::JSTextPosition::column const): added helper method for computing column.

Source/WebCore:

Fix debugger tests on GTK. All tests that pause on breakpoint didn't work because
in layout tests InspectorFrontendClientLocal was using Timer to dispatch commands
sent from the local front-end page to the inspected one. When paused inside a script
triggered by the front-end nested timer event would be scheduled but never fired
because in glib implementation of RunLoop::TimerBase uses event source which doesn't
allow recursion (g_source_set_can_recurse is not called on the source), so dispatching
Debugger.resume command didn't work when paused inside another inspector command (e.g.
eval). RunLoop itself uses event source which does allow recursion. So instead of using
a timer for asynchronous command dispatching with delay=0 we now schedule a task in
RunLoop's queue.

* inspector/InspectorFrontendClientLocal.cpp:
(WebCore::InspectorBackendDispatchTask::dispatch):
(WebCore::InspectorBackendDispatchTask::reset):
(WebCore::InspectorBackendDispatchTask::InspectorBackendDispatchTask):
(WebCore::InspectorBackendDispatchTask::scheduleOneShot): ensures that there is one inspector
dispatch task in the queue.
(WebCore::InspectorBackendDispatchTask::dispatchOneMessage): this is mostly the same behavior
as was with timerFired, we should be able to dispatch all accumulated messages from the queue
in one batch but for now I'd like to keep it one per iteration.

LayoutTests:

Enable inspector/debugger tests on GTK.

* inspector/debugger/breakpoints/resolved-dump-all-pause-locations-expected.txt: Rebaselined the test
after changes in the breakpoint resolution code. Now the output on GTK is the same as on Mac.
* platform/gtk/TestExpectations:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (250654 => 250655)


--- trunk/LayoutTests/ChangeLog	2019-10-03 15:07:16 UTC (rev 250654)
+++ trunk/LayoutTests/ChangeLog	2019-10-03 15:46:30 UTC (rev 250655)
@@ -1,3 +1,17 @@
+2019-10-03  Yury Semikhatsky  <[email protected]>
+
+        Web Inspector: tests under LayoutTests/inspector/debugger are flaky
+        https://bugs.webkit.org/show_bug.cgi?id=137131
+        <rdar://problem/18461335>
+
+        Reviewed by Devin Rousso.
+
+        Enable inspector/debugger tests on GTK.
+
+        * inspector/debugger/breakpoints/resolved-dump-all-pause-locations-expected.txt: Rebaselined the test
+        after changes in the breakpoint resolution code. Now the output on GTK is the same as on Mac.
+        * platform/gtk/TestExpectations:
+
 2019-10-03  Joonghun Park  <[email protected]>
 
         CSS ellipse() doesn't accept single <shape-radius>

Modified: trunk/LayoutTests/inspector/debugger/breakpoints/resolved-dump-all-pause-locations-expected.txt (250654 => 250655)


--- trunk/LayoutTests/inspector/debugger/breakpoints/resolved-dump-all-pause-locations-expected.txt	2019-10-03 15:07:16 UTC (rev 250654)
+++ trunk/LayoutTests/inspector/debugger/breakpoints/resolved-dump-all-pause-locations-expected.txt	2019-10-03 15:46:30 UTC (rev 250655)
@@ -2166,7 +2166,7 @@
      92        x
 
 INSERTING AT: 89:8
-PAUSES AT: 94:0
+PAUSES AT: 98:0
      86    
      87    x => x;
      88    () => 1;
@@ -2175,10 +2175,14 @@
      91    (x) => {
      92        x
      93    };
- =>  94    |() => {
+     94    () => {
      95        var x;
      96    };
      97    
+ =>  98    |var fObj = {
+     99        f1: function() {
+    100            var x;
+    101        },
 
 INSERTING AT: 90:0
 PAUSES AT: 90:0
@@ -2242,6 +2246,16 @@
      95        var x;
      96    };
 
+INSERTING AT: 94:0
+PAUSES AT: 94:0
+     91    (x) => {
+     92        x
+     93    };
+-=>  94    |() => {
+     95        var x;
+     96    };
+     97    
+
 INSERTING AT: 94:1
 PAUSES AT: 95:4
      91    (x) => {
@@ -2264,18 +2278,6 @@
      98    var fObj = {
      99        f1: function() {
 
-INSERTING AT: 96:1
-PAUSES AT: 98:0
-     93    };
-     94    () => {
-     95        var x;
- ->  96    }#;
-     97    
- =>  98    |var fObj = {
-     99        f1: function() {
-    100            var x;
-    101        },
-
 INSERTING AT: 99:0
 PAUSES AT: 100:8
      96    };

Modified: trunk/LayoutTests/platform/gtk/TestExpectations (250654 => 250655)


--- trunk/LayoutTests/platform/gtk/TestExpectations	2019-10-03 15:07:16 UTC (rev 250654)
+++ trunk/LayoutTests/platform/gtk/TestExpectations	2019-10-03 15:46:30 UTC (rev 250655)
@@ -2320,21 +2320,8 @@
 
 webkit.org/b/120682 inspector/page/archive.html [ Timeout ]
 
+webkit.org/b/147518 inspector/debugger/nested-inspectors.html [ Timeout ]
 webkit.org/b/122571 http/tests/inspector/dom/cross-domain-inspected-node-access.html [ Timeout Pass ]
-webkit.org/b/122571 inspector/debugger/setBreakpoint.html [ Timeout Pass ]
-webkit.org/b/122571 inspector/debugger/call-frame-function-name.html [ Timeout Pass ]
-webkit.org/b/122571 inspector/debugger/setBreakpoint-options-exception.html [ Timeout Pass ]
-webkit.org/b/122571 inspector/debugger/setPauseOnExceptions-all.html [ Timeout Pass ]
-webkit.org/b/122571 inspector/debugger/setPauseOnExceptions-none.html [ Timeout Pass ]
-webkit.org/b/122571 inspector/debugger/call-frame-this-host.html [ Timeout Pass Crash ]
-webkit.org/b/122571 inspector/debugger/setBreakpoint-autoContinue.html [ Timeout Pass ]
-webkit.org/b/122571 inspector/debugger/setPauseOnExceptions-uncaught.html [ Timeout Pass ]
-webkit.org/b/122571 inspector/debugger/setBreakpoint-actions.html [ Failure Timeout Pass ]
-webkit.org/b/122571 inspector/debugger/call-frame-this-nonstrict.html [ Timeout Pass ]
-webkit.org/b/122571 inspector/debugger/setBreakpoint-column.html [ Timeout Pass ]
-webkit.org/b/122571 inspector/debugger/setBreakpoint-condition.html [ Timeout Pass ]
-webkit.org/b/122571 inspector/debugger/removeBreakpoint.html [ Timeout Pass ]
-webkit.org/b/122571 inspector/debugger/call-frame-this-strict.html [ Timeout Pass ]
 webkit.org/b/122571 inspector/dom/request-child-nodes-depth.html [ Timeout Pass ]
 webkit.org/b/122571 inspector/dom/focus.html [ Failure Timeout Pass ]
 webkit.org/b/122571 inspector/runtime/getProperties.html [ Timeout Pass Crash ]
@@ -2379,7 +2366,6 @@
 
 webkit.org/b/137698 media/video-controls-drag.html [ Timeout ]
 
-webkit.org/b/137131 inspector/debugger [ Skip ]
 webkit.org/b/147518 inspector/dom [ Skip ]
 webkit.org/b/147518 inspector/model [ Skip ]
 webkit.org/b/147518 inspector/timeline [ Skip ]

Modified: trunk/Source/_javascript_Core/ChangeLog (250654 => 250655)


--- trunk/Source/_javascript_Core/ChangeLog	2019-10-03 15:07:16 UTC (rev 250654)
+++ trunk/Source/_javascript_Core/ChangeLog	2019-10-03 15:46:30 UTC (rev 250655)
@@ -1,3 +1,41 @@
+2019-10-03  Yury Semikhatsky  <[email protected]>
+
+        Web Inspector: tests under LayoutTests/inspector/debugger are flaky
+        https://bugs.webkit.org/show_bug.cgi?id=137131
+        <rdar://problem/18461335>
+
+        Reviewed by Devin Rousso.
+
+        Changed breakpoint resolution logic to make it consistent across platforms and
+        better handle the case when there are several DebuggerPausePositions at the same
+        offset (but with different types).
+
+        * bytecode/CodeBlock.cpp:
+        (JSC::CodeBlock::hasOpDebugForLineAndColumn):
+        * bytecode/CodeBlock.h:
+        * debugger/Breakpoint.h: Removed Breakpoint::unspecifiedColumn, Optional<unsigned>
+        is used instead where needed. It allows to avoid code that relies on (int)UINT_MAX => -1
+        conversion.
+
+        * debugger/Debugger.cpp:
+        (JSC::Debugger::resolveBreakpoint): clarified that in the map columns are 0-based.
+        * debugger/DebuggerParseData.cpp:
+        (JSC::DebuggerPausePositions::breakpointLocationForLineColumn): replaced custom
+        binary search with std::lower_bound. If there are several pause positions at the
+        same offset they will be sorted by the type and the algorithm is guaranteed to see
+        leftmost one first.
+
+        (JSC::DebuggerPausePositions::sort): use type as secondary ordering component.
+        * debugger/DebuggerParseData.h: Rearranged type constants so that Enter < Pause < Leave
+        this change along with sorting by type should guarantee that in case of several pause
+        positions at the same line Enter goes before Pause before Leave and the breakpoint
+        resolution will yield result similar to that when each pause locations has different
+        position.
+
+        * inspector/protocol/Debugger.json: clarified that positions are 0-based.
+        * parser/ParserTokens.h:
+        (JSC::JSTextPosition::column const): added helper method for computing column.
+
 2019-10-03  Keith Miller  <[email protected]>
 
         Fix assembler on ARM64E

Modified: trunk/Source/_javascript_Core/bytecode/CodeBlock.cpp (250654 => 250655)


--- trunk/Source/_javascript_Core/bytecode/CodeBlock.cpp	2019-10-03 15:07:16 UTC (rev 250654)
+++ trunk/Source/_javascript_Core/bytecode/CodeBlock.cpp	2019-10-03 15:46:30 UTC (rev 250655)
@@ -1869,7 +1869,7 @@
     line += ownerExecutable()->firstLine();
 }
 
-bool CodeBlock::hasOpDebugForLineAndColumn(unsigned line, unsigned column)
+bool CodeBlock::hasOpDebugForLineAndColumn(unsigned line, Optional<unsigned> column)
 {
     const InstructionStream& instructionStream = instructions();
     for (const auto& it : instructionStream) {
@@ -1878,7 +1878,7 @@
             unsigned opDebugLine;
             unsigned opDebugColumn;
             expressionRangeForBytecodeOffset(it.offset(), unused, unused, unused, opDebugLine, opDebugColumn);
-            if (line == opDebugLine && (column == Breakpoint::unspecifiedColumn || column == opDebugColumn))
+            if (line == opDebugLine && (!column || column == opDebugColumn))
                 return true;
         }
     }

Modified: trunk/Source/_javascript_Core/bytecode/CodeBlock.h (250654 => 250655)


--- trunk/Source/_javascript_Core/bytecode/CodeBlock.h	2019-10-03 15:07:16 UTC (rev 250654)
+++ trunk/Source/_javascript_Core/bytecode/CodeBlock.h	2019-10-03 15:46:30 UTC (rev 250655)
@@ -787,7 +787,7 @@
     unsigned frameRegisterCount();
     int stackPointerOffset();
 
-    bool hasOpDebugForLineAndColumn(unsigned line, unsigned column);
+    bool hasOpDebugForLineAndColumn(unsigned line, Optional<unsigned> column);
 
     bool hasDebuggerRequests() const { return m_debuggerRequests; }
     void* debuggerRequestsAddress() { return &m_debuggerRequests; }

Modified: trunk/Source/_javascript_Core/debugger/Breakpoint.h (250654 => 250655)


--- trunk/Source/_javascript_Core/debugger/Breakpoint.h	2019-10-03 15:07:16 UTC (rev 250654)
+++ trunk/Source/_javascript_Core/debugger/Breakpoint.h	2019-10-03 15:46:30 UTC (rev 250655)
@@ -57,8 +57,6 @@
     unsigned hitCount { 0 };
     bool resolved { false };
 
-    static constexpr unsigned unspecifiedColumn = UINT_MAX;
-
 private:
     Breakpoint* m_prev;
     Breakpoint* m_next;

Modified: trunk/Source/_javascript_Core/debugger/Debugger.cpp (250654 => 250655)


--- trunk/Source/_javascript_Core/debugger/Debugger.cpp	2019-10-03 15:07:16 UTC (rev 250654)
+++ trunk/Source/_javascript_Core/debugger/Debugger.cpp	2019-10-03 15:46:30 UTC (rev 250655)
@@ -268,9 +268,6 @@
     if (breakpoint.sourceID != sourceID)
         return;
 
-    unsigned line = breakpoint.line;
-    unsigned column = breakpoint.column;
-
     unsigned startLine = executable->firstLine();
     unsigned startColumn = executable->startColumn();
     unsigned endLine = executable->lastLine();
@@ -278,12 +275,14 @@
 
     // Inspector breakpoint line and column values are zero-based but the executable
     // and CodeBlock line and column values are one-based.
-    line += 1;
-    column = column ? column + 1 : Breakpoint::unspecifiedColumn;
+    unsigned line = breakpoint.line + 1;
+    Optional<unsigned> column;
+    if (breakpoint.column)
+        column = breakpoint.column + 1;
 
     if (line < startLine || line > endLine)
         return;
-    if (column != Breakpoint::unspecifiedColumn) {
+    if (column) {
         if (line == startLine && column < startColumn)
             return;
         if (line == endLine && column > endColumn)
@@ -359,14 +358,14 @@
 
     // FIXME: <https://webkit.org/b/162771> Web Inspector: Adopt TextPosition in Inspector to avoid oneBasedInt/zeroBasedInt ambiguity
     // Inspector breakpoint line and column values are zero-based but the executable
-    // and CodeBlock line and column values are one-based.
-    unsigned line = breakpoint.line + 1;
-    unsigned column = breakpoint.column ? breakpoint.column : Breakpoint::unspecifiedColumn;
+    // and CodeBlock line values are one-based while column is zero-based.
+    int line = breakpoint.line + 1;
+    int column = breakpoint.column;
 
     // Account for a <script>'s start position on the first line only.
-    unsigned providerStartLine = sourceProvider->startPosition().m_line.oneBasedInt(); // One based to match the already adjusted line.
-    unsigned providerStartColumn = sourceProvider->startPosition().m_column.zeroBasedInt(); // Zero based so column zero is zero.
-    if (line == providerStartLine && column != Breakpoint::unspecifiedColumn) {
+    int providerStartLine = sourceProvider->startPosition().m_line.oneBasedInt(); // One based to match the already adjusted line.
+    int providerStartColumn = sourceProvider->startPosition().m_column.zeroBasedInt(); // Zero based so column zero is zero.
+    if (line == providerStartLine && breakpoint.column) {
         ASSERT(providerStartColumn <= column);
         if (providerStartColumn)
             column -= providerStartColumn;
@@ -373,21 +372,21 @@
     }
 
     DebuggerParseData& parseData = debuggerParseData(breakpoint.sourceID, sourceProvider);
-    Optional<JSTextPosition> resolvedPosition = parseData.pausePositions.breakpointLocationForLineColumn((int)line, (int)column);
+    Optional<JSTextPosition> resolvedPosition = parseData.pausePositions.breakpointLocationForLineColumn(line, column);
     if (!resolvedPosition)
         return;
 
-    unsigned resolvedLine = resolvedPosition->line;
-    unsigned resolvedColumn = resolvedPosition->offset - resolvedPosition->lineStartOffset + 1;
+    int resolvedLine = resolvedPosition->line;
+    int resolvedColumn = resolvedPosition->column();
 
     // Re-account for a <script>'s start position on the first line only.
-    if (resolvedLine == providerStartLine && column != Breakpoint::unspecifiedColumn) {
+    if (resolvedLine == providerStartLine && breakpoint.column) {
         if (providerStartColumn)
             resolvedColumn += providerStartColumn;
     }
 
     breakpoint.line = resolvedLine - 1;
-    breakpoint.column = resolvedColumn - 1;
+    breakpoint.column = resolvedColumn;
     breakpoint.resolved = true;
 }
 

Modified: trunk/Source/_javascript_Core/debugger/DebuggerParseData.cpp (250654 => 250655)


--- trunk/Source/_javascript_Core/debugger/DebuggerParseData.cpp	2019-10-03 15:07:16 UTC (rev 250654)
+++ trunk/Source/_javascript_Core/debugger/DebuggerParseData.cpp	2019-10-03 15:46:30 UTC (rev 250655)
@@ -33,43 +33,23 @@
 
 Optional<JSTextPosition> DebuggerPausePositions::breakpointLocationForLineColumn(int line, int column)
 {
-    unsigned start = 0;
-    unsigned end = m_positions.size();
-    while (start != end) {
-        unsigned middle = start + ((end - start) / 2);
-        DebuggerPausePosition& pausePosition = m_positions[middle];
-        int pauseLine = pausePosition.position.line;
-        int pauseColumn = pausePosition.position.offset - pausePosition.position.lineStartOffset;
+    DebuggerPausePosition position = { DebuggerPausePositionType::Invalid, JSTextPosition(line, column, 0) };
+    auto it = std::lower_bound(m_positions.begin(), m_positions.end(), position, [] (const DebuggerPausePosition& a, const DebuggerPausePosition& b) {
+        if (a.position.line == b.position.line)
+            return a.position.column() < b.position.column();
+        return a.position.line < b.position.line;
+    });
+    if (it == m_positions.end())
+        return WTF::nullopt;
 
-        if (line < pauseLine) {
-            end = middle;
-            continue;
-        }
-        if (line > pauseLine) {
-            start = middle + 1;
-            continue;
-        }
-
-        if (column == pauseColumn) {
-            // Found an exact position match. Roll forward if this was a function Entry.
-            // We are guarenteed to have a Leave for an Entry so we don't need to bounds check.
-            while (true) {
-                if (pausePosition.type != DebuggerPausePositionType::Enter)
-                    return Optional<JSTextPosition>(pausePosition.position);
-                pausePosition = m_positions[middle++];
-            }
-        }
-
-        if (column < pauseColumn)
-            end = middle;
-        else
-            start = middle + 1;
+    if (line == it->position.line && column == it->position.column()) {
+        // Found an exact position match. Roll forward if this was a function Entry.
+        // We are guaranteed to have a Leave for an Entry so we don't need to bounds check.
+        while (it->type == DebuggerPausePositionType::Enter)
+            ++it;
+        return it->position;
     }
 
-    // Past the end, no possible pause locations.
-    if (start >= m_positions.size())
-        return WTF::nullopt;
-
     // If the next location is a function Entry we will need to decide if we should go into
     // the function or go past the function. We decide to go into the function if the
     // input is on the same line as the function entry. For example:
@@ -86,7 +66,7 @@
     // If the input was line 3, go into the function to pause on line 4.
 
     // Valid pause location. Use it.
-    DebuggerPausePosition& firstSlidePosition = m_positions[start];
+    auto& firstSlidePosition = *it;
     if (firstSlidePosition.type != DebuggerPausePositionType::Enter)
         return Optional<JSTextPosition>(firstSlidePosition.position);
 
@@ -94,8 +74,9 @@
     // If entryStackSize is > 0 we are skipping functions.
     bool shouldEnterFunction = firstSlidePosition.position.line == line;
     int entryStackSize = shouldEnterFunction ? 0 : 1;
-    for (unsigned i = start + 1; i < m_positions.size(); ++i) {
-        DebuggerPausePosition& slidePosition = m_positions[i];
+    ++it;
+    for (; it != m_positions.end(); ++it) {
+        auto& slidePosition = *it;
         ASSERT(entryStackSize >= 0);
 
         // Already skipping functions.
@@ -124,6 +105,8 @@
 void DebuggerPausePositions::sort()
 {
     std::sort(m_positions.begin(), m_positions.end(), [] (const DebuggerPausePosition& a, const DebuggerPausePosition& b) {
+        if (a.position.offset == b.position.offset)
+            return a.type < b.type;
         return a.position.offset < b.position.offset;
     });
 }

Modified: trunk/Source/_javascript_Core/debugger/DebuggerParseData.h (250654 => 250655)


--- trunk/Source/_javascript_Core/debugger/DebuggerParseData.h	2019-10-03 15:07:16 UTC (rev 250654)
+++ trunk/Source/_javascript_Core/debugger/DebuggerParseData.h	2019-10-03 15:46:30 UTC (rev 250655)
@@ -33,9 +33,11 @@
 class SourceProvider;
 class VM;
 
-enum class DebuggerPausePositionType { Enter, Leave, Pause };
+// The order of the constants here matters as it is used for
+// sorting pause positions that have same offset.
+enum class DebuggerPausePositionType { Invalid, Enter, Pause, Leave };
 struct DebuggerPausePosition {
-    DebuggerPausePositionType type;
+    DebuggerPausePositionType type { DebuggerPausePositionType::Invalid };
     JSTextPosition position;
 };
 

Modified: trunk/Source/_javascript_Core/inspector/protocol/Debugger.json (250654 => 250655)


--- trunk/Source/_javascript_Core/inspector/protocol/Debugger.json	2019-10-03 15:07:16 UTC (rev 250654)
+++ trunk/Source/_javascript_Core/inspector/protocol/Debugger.json	2019-10-03 15:46:30 UTC (rev 250655)
@@ -28,8 +28,8 @@
             "description": "Location in the source code.",
             "properties": [
                 { "name": "scriptId", "$ref": "ScriptId", "description": "Script identifier as reported in the <code>Debugger.scriptParsed</code>." },
-                { "name": "lineNumber", "type": "integer", "description": "Line number in the script." },
-                { "name": "columnNumber", "type": "integer", "optional": true, "description": "Column number in the script." }
+                { "name": "lineNumber", "type": "integer", "description": "Line number in the script (0-based)." },
+                { "name": "columnNumber", "type": "integer", "optional": true, "description": "Column number in the script (0-based)." }
             ]
         },
         {

Modified: trunk/Source/_javascript_Core/parser/ParserTokens.h (250654 => 250655)


--- trunk/Source/_javascript_Core/parser/ParserTokens.h	2019-10-03 15:07:16 UTC (rev 250654)
+++ trunk/Source/_javascript_Core/parser/ParserTokens.h	2019-10-03 15:46:30 UTC (rev 250655)
@@ -217,6 +217,8 @@
         return !(*this == other);
     }
 
+    int column() const { return offset - lineStartOffset; }
+
     int line { 0 };
     int offset { 0 };
     int lineStartOffset { 0 };

Modified: trunk/Source/WebCore/ChangeLog (250654 => 250655)


--- trunk/Source/WebCore/ChangeLog	2019-10-03 15:07:16 UTC (rev 250654)
+++ trunk/Source/WebCore/ChangeLog	2019-10-03 15:46:30 UTC (rev 250655)
@@ -1,3 +1,32 @@
+2019-10-03  Yury Semikhatsky  <[email protected]>
+
+        Web Inspector: tests under LayoutTests/inspector/debugger are flaky
+        https://bugs.webkit.org/show_bug.cgi?id=137131
+        <rdar://problem/18461335>
+
+        Reviewed by Devin Rousso.
+
+        Fix debugger tests on GTK. All tests that pause on breakpoint didn't work because
+        in layout tests InspectorFrontendClientLocal was using Timer to dispatch commands
+        sent from the local front-end page to the inspected one. When paused inside a script
+        triggered by the front-end nested timer event would be scheduled but never fired
+        because in glib implementation of RunLoop::TimerBase uses event source which doesn't
+        allow recursion (g_source_set_can_recurse is not called on the source), so dispatching
+        Debugger.resume command didn't work when paused inside another inspector command (e.g.
+        eval). RunLoop itself uses event source which does allow recursion. So instead of using
+        a timer for asynchronous command dispatching with delay=0 we now schedule a task in
+        RunLoop's queue.
+
+        * inspector/InspectorFrontendClientLocal.cpp:
+        (WebCore::InspectorBackendDispatchTask::dispatch):
+        (WebCore::InspectorBackendDispatchTask::reset):
+        (WebCore::InspectorBackendDispatchTask::InspectorBackendDispatchTask):
+        (WebCore::InspectorBackendDispatchTask::scheduleOneShot): ensures that there is one inspector
+        dispatch task in the queue.
+        (WebCore::InspectorBackendDispatchTask::dispatchOneMessage): this is mostly the same behavior
+        as was with timerFired, we should be able to dispatch all accumulated messages from the queue
+        in one batch but for now I'd like to keep it one per iteration.
+
 2019-10-03  Joonghun Park  <[email protected]>
 
         CSS ellipse() doesn't accept single <shape-radius>

Modified: trunk/Source/WebCore/inspector/InspectorFrontendClientLocal.cpp (250654 => 250655)


--- trunk/Source/WebCore/inspector/InspectorFrontendClientLocal.cpp	2019-10-03 15:07:16 UTC (rev 250654)
+++ trunk/Source/WebCore/inspector/InspectorFrontendClientLocal.cpp	2019-10-03 15:46:30 UTC (rev 250655)
@@ -81,43 +81,54 @@
         ASSERT_ARG(message, !message.isEmpty());
 
         m_messages.append(message);
-        if (!m_timer.isActive())
-            m_timer.startOneShot(0_s);
+        scheduleOneShot();
     }
 
     void reset()
     {
         m_messages.clear();
-        m_timer.stop();
         m_inspectedPageController = nullptr;
     }
 
-    void timerFired()
+private:
+    InspectorBackendDispatchTask(InspectorController* inspectedPageController)
+        : m_inspectedPageController(inspectedPageController)
     {
-        ASSERT(m_inspectedPageController);
+        ASSERT_ARG(inspectedPageController, inspectedPageController);
+    }
 
-        // Dispatching a message can possibly close the frontend and destroy
-        // the owning frontend client, so keep a protector reference here.
-        Ref<InspectorBackendDispatchTask> protectedThis(*this);
+    void scheduleOneShot()
+    {
+        if (m_hasScheduledTask)
+            return;
+        m_hasScheduledTask = true;
 
+        // The frontend can be closed and destroy the owning frontend client before or in the
+        // process of dispatching the task, so keep a protector reference here.
+        RunLoop::current().dispatch([this, protectedThis = makeRef(*this)] {
+            m_hasScheduledTask = false;
+            dispatchOneMessage();
+        });
+    }
+
+    void dispatchOneMessage()
+    {
+        // Owning frontend client may have been destroyed after the task was scheduled.
+        if (!m_inspectedPageController) {
+            ASSERT(m_messages.isEmpty());
+            return;
+        }
+
         if (!m_messages.isEmpty())
             m_inspectedPageController->dispatchMessageFromFrontend(m_messages.takeFirst());
 
         if (!m_messages.isEmpty() && m_inspectedPageController)
-            m_timer.startOneShot(0_s);
+            scheduleOneShot();
     }
 
-private:
-    InspectorBackendDispatchTask(InspectorController* inspectedPageController)
-        : m_inspectedPageController(inspectedPageController)
-        , m_timer(*this, &InspectorBackendDispatchTask::timerFired)
-    {
-        ASSERT_ARG(inspectedPageController, inspectedPageController);
-    }
-
     InspectorController* m_inspectedPageController { nullptr };
-    Timer m_timer;
     Deque<String> m_messages;
+    bool m_hasScheduledTask { false };
 };
 
 String InspectorFrontendClientLocal::Settings::getProperty(const String&)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to