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

Don't use the isolate compilation cache for REPL mode scripts

The compilation cache doesn't know about REPL mode. This means that
non-REPL mode compiled scripts are successfully found for their
REPL mode equivalent and vice versa.

This CL disables the compilation cache for REPL mode scripts.
Performance is not really a concern as DevTools console inputs
are usually very small.

R=leszeks@chromium.org

Bug: chromium:1108021
Change-Id: If396c7aa004188730762e4f6bd01dae2fc141181
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2434333
Commit-Queue: Simon Zünd <szuend@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70160}
parent 1e80ad69
......@@ -2604,10 +2604,13 @@ MaybeHandle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForScript(
LanguageMode language_mode = construct_language_mode(FLAG_use_strict);
CompilationCache* compilation_cache = isolate->compilation_cache();
// Do a lookup in the compilation cache but not for extensions.
// For extensions or REPL mode scripts neither do a compilation cache lookup,
// nor put the compilation result back into the cache.
const bool use_compilation_cache =
extension == nullptr && script_details.repl_mode == REPLMode::kNo;
MaybeHandle<SharedFunctionInfo> maybe_result;
IsCompiledScope is_compiled_scope;
if (extension == nullptr) {
if (use_compilation_cache) {
bool can_consume_code_cache =
compile_options == ScriptCompiler::kConsumeCodeCache;
if (can_consume_code_cache) {
......@@ -2673,7 +2676,7 @@ MaybeHandle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForScript(
// Add the result to the isolate cache.
Handle<SharedFunctionInfo> result;
if (extension == nullptr && maybe_result.ToHandle(&result)) {
if (use_compilation_cache && maybe_result.ToHandle(&result)) {
DCHECK(is_compiled_scope.is_compiled());
compilation_cache->PutScript(source, isolate->native_context(),
language_mode, result);
......
Tests that Runtime.evaluate's REPL mode correctly interacts with the compliation cache (crbug.com/1108021)
Prefill the cache with non-REPL mode script
{
id : <messageId>
result : {
result : {
description : 8
type : number
value : 8
}
}
}
REPL mode scripts always return a Promise.
The first script only returns "8" instead. When the inspector doesn't find a promise (due to a cache hit), it would respond with "undefined".
{
id : <messageId>
result : {
result : {
description : 8
type : number
value : 8
}
}
}
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
let {Protocol} = InspectorTest.start(
"Tests that Runtime.evaluate's REPL mode correctly interacts with the compliation cache (crbug.com/1108021)");
(async function() {
InspectorTest.log('Prefill the cache with non-REPL mode script');
InspectorTest.logMessage(await Protocol.Runtime.evaluate({
expression: '5 + 3',
replMode: false,
}));
InspectorTest.log('REPL mode scripts always return a Promise.')
InspectorTest.log('The first script only returns "8" instead. When the inspector doesn\'t find a promise (due to a cache hit), it would respond with "undefined".');
InspectorTest.logMessage(await Protocol.Runtime.evaluate({
expression: '5 + 3',
replMode: true,
}));
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