Commit e99d4e77 authored by Simon Zünd's avatar Simon Zünd Committed by Commit Bot

REPL mode must only re-write AST on successful parses

This CL fixes a parser crash in REPL mode. Some SyntaxErrors can cause
the AST to contain NULL nodes, resulting in a crash when we want to
rewrite the AST after parsing.

Instead of re-writing a broken AST we bail early.

R=leszeks@chromium.org

Bug: chromium:1040034, chromium:1045758
Change-Id: I9c559f6de5969c8db17833ccbdb1608627b46311
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2023547Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Simon Zünd <szuend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66008}
parent c51c9f7c
...@@ -735,6 +735,8 @@ void Parser::ParseREPLProgram(ParseInfo* info, ScopedPtrList<Statement>* body, ...@@ -735,6 +735,8 @@ void Parser::ParseREPLProgram(ParseInfo* info, ScopedPtrList<Statement>* body,
block = factory()->NewBlock(true, statements); block = factory()->NewBlock(true, statements);
} }
if (has_error()) return;
base::Optional<VariableProxy*> maybe_result = base::Optional<VariableProxy*> maybe_result =
Rewriter::RewriteBody(info, scope, block->statements()); Rewriter::RewriteBody(info, scope, block->statements());
Expression* result_value = Expression* result_value =
......
Tests that Runtime.evaluate works with REPL mode. Tests that Runtime.evaluate works with REPL mode.
Test 'let' re-declaration Test 'let' re-declaration
SyntaxError in REPL mode does not crash the parser
{ {
id : <messageId> id : <messageId>
result : { result : {
...@@ -36,3 +37,29 @@ Test 'let' re-declaration ...@@ -36,3 +37,29 @@ Test 'let' re-declaration
} }
} }
} }
{
id : <messageId>
result : {
exceptionDetails : {
columnNumber : 10
exception : {
className : SyntaxError
description : SyntaxError: Unexpected token 'const'
objectId : <objectId>
subtype : error
type : object
}
exceptionId : <exceptionId>
lineNumber : 0
scriptId : <scriptId>
text : Uncaught
}
result : {
className : SyntaxError
description : SyntaxError: Unexpected token 'const'
objectId : <objectId>
subtype : error
type : object
}
}
}
...@@ -13,6 +13,10 @@ Protocol.Runtime.enable(); ...@@ -13,6 +13,10 @@ Protocol.Runtime.enable();
evaluateRepl('let x = 42;'); evaluateRepl('let x = 42;');
evaluateRepl('x;'); evaluateRepl('x;');
// Regression test for crbug.com/1040034.
InspectorTest.log("SyntaxError in REPL mode does not crash the parser");
evaluateRepl('if (true) const x');
InspectorTest.completeTest(); InspectorTest.completeTest();
})(); })();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment