Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 6eceba5825819069e719f9b9a560ca6c1a64b3e8
      
https://github.com/WebKit/WebKit/commit/6eceba5825819069e719f9b9a560ca6c1a64b3e8
  Author: Devin Rousso <h...@devinrousso.com>
  Date:   2025-04-12 (Sat, 12 Apr 2025)

  Changed paths:
    A LayoutTests/inspector/debugger/resources/stepping-async.js
    A LayoutTests/inspector/debugger/stepping/stepInto-await-expected.txt
    A LayoutTests/inspector/debugger/stepping/stepInto-await.html
    A LayoutTests/inspector/debugger/stepping/stepNext-await-expected.txt
    A LayoutTests/inspector/debugger/stepping/stepNext-await.html
    A LayoutTests/inspector/debugger/stepping/stepOut-await-expected.txt
    A LayoutTests/inspector/debugger/stepping/stepOut-await.html
    A LayoutTests/inspector/debugger/stepping/stepOver-await-expected.txt
    A LayoutTests/inspector/debugger/stepping/stepOver-await.html
    M Source/JavaScriptCore/bytecode/BytecodeList.rb
    M Source/JavaScriptCore/bytecode/BytecodeUseDef.cpp
    M Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.cpp
    M Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp
    M Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h
    M Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
    M Source/JavaScriptCore/debugger/Debugger.cpp
    M Source/JavaScriptCore/debugger/Debugger.h
    M Source/JavaScriptCore/interpreter/Interpreter.cpp
    M Source/JavaScriptCore/interpreter/Interpreter.h
    M Source/JavaScriptCore/jit/JITOpcodes.cpp
    M Source/JavaScriptCore/jit/JITOperations.cpp
    M Source/JavaScriptCore/jit/JITOperations.h
    M Source/JavaScriptCore/llint/LLIntSlowPaths.cpp
    M Source/WebKitLegacy/mac/WebView/WebScriptDebugger.h
    M Source/WebKitLegacy/mac/WebView/WebScriptDebugger.mm

  Log Message:
  -----------
  Web Inspector: Debugger: add a way to step over `await` as though it was sync 
code
https://bugs.webkit.org/show_bug.cgi?id=291309

Reviewed by Yusuke Suzuki.

When debugging async code with `await` it's often more desirable to follow 
what's written in code (i.e. as if the `await` didnt exist) instead of the 
literal execution flow, especially since it's possible for execution to stop 
after the `await` if it's the end of sync code.

For example, if the developer is trying to step through code similar to the 
following
```js
/* 1 */ async function wrap(callback, state) {
/* 2 */     console.log(state, "before");
/* 3 */     await callback();
/* 4 */     console.log(state, "after");
/* 5 */ }
/* 6 */
/* 7 */ wrap(foo, 1);
/* 8 */ debugger;
/* 9 */ wrap(foo, 2);
```
execution should never pause in the flow where `state === 1`, meaning that the 
debugger will "skip" (i.e. resume and then pause again) between "2 before" and 
"1 after".

Without this, the developer has to manually create breakpoints after each 
`await` to ensure that execution pauses after, but even then there's no 
guarantee that will be in the right flow if the same function is invoked 
multiple times (i.e. one resolves before the other).

* Source/JavaScriptCore/bytecode/BytecodeList.rb:
* Source/JavaScriptCore/bytecode/BytecodeUseDef.cpp:
(JSC::computeUsesForBytecodeIndexImpl):
* Source/JavaScriptCore/jit/JITOpcodes.cpp:
(JSC::JIT::emit_op_debug):
* Source/JavaScriptCore/jit/JITOperations.h:
* Source/JavaScriptCore/jit/JITOperations.cpp:
(JSC::operationDebug):
* Source/JavaScriptCore/llint/LLIntSlowPaths.cpp:
(JSC::LLInt::slow_path_debug):
Modify `OpDebug` to allow for additional data to be set alongside the 
`DebugHookType`.
Currently this is only used to pass along the `JSGenerator` instance as a way 
to link execution from before the `await` to after the `await`.
Drive-by: Remove the unused `hasBreakpoint` member variable.

* Source/JavaScriptCore/interpreter/Interpreter.h:
* Source/JavaScriptCore/interpreter/Interpreter.cpp:
(JSC::Interpreter::debug):
(WTF::printInternal):
* Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.cpp:
(JSC::dumpExpressionInfoDetails):
* Source/JavaScriptCore/debugger/Debugger.h:
* Source/JavaScriptCore/debugger/Debugger.cpp:
(JSC::Debugger::detach):
(JSC::Debugger::pauseIfNeeded):
(JSC::Debugger::handlePause):
(JSC::Debugger::willAwait): Added.
(JSC::Debugger::didAwait): Added.
(JSC::Debugger::resetAsyncPauseState): Added.
Introduce new `WillAwait` and `DidAwait` debug hooks for the `Debugger` to 
determine what `await` to pause on.
When performing a "Step over" or "Step next", if an `await` is encountered then 
save the `JSGenerator` instance (which is the additional data set alongside the 
`DebugHookType`).
Once the `await` is done, if the `JSGenerator` matches what was saved then 
pause at the next opportunity.

* Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h:
* Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp:
(JSC::BytecodeGenerator::emitDebugHook):
(JSC::BytecodeGenerator::emitWillLeaveCallFrameDebugHook):
(JSC::BytecodeGenerator::emitAwait):
(JSC::BytecodeGenerator::emitIteratorGenericNext):
(JSC::BytecodeGenerator::emitIteratorGenericClose):
(JSC::BytecodeGenerator::emitDelegateYield):
* Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp:
(JSC::ReturnNode::emitBytecode):
(JSC::emitProgramNodeBytecode):
(JSC::EvalNode::emitBytecode):
(JSC::FunctionNode::emitBytecode):
(JSC::AwaitExprNode::emitBytecode):
Drive-by: remove unnecessary overrides to make debug hook logic simpler.

* Source/WebKitLegacy/mac/WebView/WebScriptDebugger.h:
* Source/WebKitLegacy/mac/WebView/WebScriptDebugger.mm:
(WebScriptDebugger::handlePause):
Drive-by: no need to pass the `ReasonForPause` since it's already exposed via 
`Debugger::reasonForPause`.

* LayoutTests/inspector/debugger/resources/stepping-async.js: Added.
* LayoutTests/inspector/debugger/stepping/stepInto-await.html:
* LayoutTests/inspector/debugger/stepping/stepInto-await-expected.txt:
* LayoutTests/inspector/debugger/stepping/stepNext-await.html:
* LayoutTests/inspector/debugger/stepping/stepNext-await-expected.txt:
* LayoutTests/inspector/debugger/stepping/stepOut-await.html:
* LayoutTests/inspector/debugger/stepping/stepOut-await-expected.txt:
* LayoutTests/inspector/debugger/stepping/stepOver-await.html:
* LayoutTests/inspector/debugger/stepping/stepOver-await-expected.txt:

Canonical link: https://commits.webkit.org/293628@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to