Repository navigation
[flutter_tools] Use JSON_INPUT COMPILE_EXPRESSION for expression evaluation - #190722
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors DefaultResidentCompiler.compileExpression to send expression compilation requests as JSON-encoded payloads under the JSON_INPUT protocol instead of multi-line plain text. It also updates and adds corresponding unit tests. Feedback suggests closing the newly introduced StreamController instances in tests to prevent resource leaks, and parsing the output JSON in tests rather than comparing raw strings to improve test robustness.
…uation Use the structured JSON_INPUT protocol with the COMPILE_EXPRESSION command type when compiling expressions for the Dart VM in DefaultResidentCompiler. Previously, flutter_tools used the legacy newline-delimited command format (compile-expression <boundaryKey>). Because frontend_server transitions out of the expression-reading state on the first newline, any multi-line expression had only its first line evaluated, with subsequent lines misinterpreted as variable definitions. Using the JSON_INPUT protocol safely preserves newlines and complex expressions across stdin IPC. Fixes flutter#55731
chingjun
left a comment
There was a problem hiding this comment.
I happen to be looking at a compile-expression issue the other day. This would make it so much easier!
I had no idea this was even a legacy format and that we had a JSON-based replacement until I came across this! It's much nicer! 🥳 |
Description
When evaluating expressions in Flutter debug sessions,
DefaultResidentCompiler._compileExpressionwas communicating withfrontend_serverusing the legacy line-delimited protocol (compile-expression <boundaryKey>). Becausefrontend_server's state machine transitions out of expression parsing upon receiving the first newline character, multi-line expressions had only their first line evaluated, with subsequent lines misread as variable definitions.This PR updates
DefaultResidentCompiler._compileExpressioninpackages/flutter_tools/lib/src/compile.dartto use the structuredJSON_INPUTprotocol with'type': 'COMPILE_EXPRESSION'(mirroringCOMPILE_EXPRESSION_JSin_compileExpressionToJs), safely encoding multi-line expressions and scope definitions into a single JSON payload.Fixes
Fixes #55731
Pre-launch Checklist
///).