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

Connect REPL mode to the V8 inspector

There already exists a optional boolean flag 'replMode' for the
'Runtime.evaluate' command. This CL ferries the flag from the inspector
to DebugEvaluate::Global.

The existing DebugEvaluate::GlobalREPL is removed in favor of a
the REPLMOde enum to reduce code duplication.

Bug: chromium:1018158
Change-Id: Iafb43a3015b6876a02ac0db6cdfcac2cfa388862
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1881149
Commit-Queue: Simon Zünd <szuend@chromium.org>
Reviewed-by: 's avatarPeter Marshall <petermarshall@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64801}
parent 941afb69
......@@ -9864,14 +9864,16 @@ v8::Local<debug::GeneratorObject> debug::GeneratorObject::Cast(
MaybeLocal<v8::Value> debug::EvaluateGlobal(v8::Isolate* isolate,
v8::Local<v8::String> source,
EvaluateGlobalMode mode) {
EvaluateGlobalMode mode,
bool repl) {
i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
PREPARE_FOR_DEBUG_INTERFACE_EXECUTION_WITH_ISOLATE(internal_isolate, Value);
i::REPLMode repl_mode = repl ? i::REPLMode::kYes : i::REPLMode::kNo;
Local<Value> result;
has_pending_exception =
!ToLocal<Value>(i::DebugEvaluate::Global(
internal_isolate, Utils::OpenHandle(*source), mode),
&result);
has_pending_exception = !ToLocal<Value>(
i::DebugEvaluate::Global(internal_isolate, Utils::OpenHandle(*source),
mode, repl_mode),
&result);
RETURN_ON_FAILED_EXECUTION(Value);
RETURN_ESCAPED(result);
}
......
......@@ -23,7 +23,8 @@ namespace internal {
MaybeHandle<Object> DebugEvaluate::Global(Isolate* isolate,
Handle<String> source,
debug::EvaluateGlobalMode mode) {
debug::EvaluateGlobalMode mode,
REPLMode repl_mode) {
// Disable breaks in side-effect free mode.
DisableBreak disable_break_scope(
isolate->debug(),
......@@ -32,13 +33,14 @@ MaybeHandle<Object> DebugEvaluate::Global(Isolate* isolate,
debug::EvaluateGlobalMode::kDisableBreaksAndThrowOnSideEffect);
Handle<Context> context = isolate->native_context();
Compiler::ScriptDetails script_details(isolate->factory()->empty_string());
script_details.repl_mode = repl_mode;
ScriptOriginOptions origin_options(false, true);
MaybeHandle<SharedFunctionInfo> maybe_function_info =
Compiler::GetSharedFunctionInfoForScript(
isolate, source,
Compiler::ScriptDetails(isolate->factory()->empty_string()),
origin_options, nullptr, nullptr, ScriptCompiler::kNoCompileOptions,
ScriptCompiler::kNoCacheNoReason, NOT_NATIVES_CODE);
isolate, source, script_details, origin_options, nullptr, nullptr,
ScriptCompiler::kNoCompileOptions, ScriptCompiler::kNoCacheNoReason,
NOT_NATIVES_CODE);
Handle<SharedFunctionInfo> shared_info;
if (!maybe_function_info.ToHandle(&shared_info)) return MaybeHandle<Object>();
......@@ -58,30 +60,6 @@ MaybeHandle<Object> DebugEvaluate::Global(Isolate* isolate,
return result;
}
MaybeHandle<Object> DebugEvaluate::GlobalREPL(Isolate* isolate,
Handle<String> source) {
Handle<Context> context = isolate->native_context();
Compiler::ScriptDetails script_details(isolate->factory()->empty_string());
script_details.repl_mode = REPLMode::kYes;
ScriptOriginOptions origin_options(false, true);
MaybeHandle<SharedFunctionInfo> maybe_function_info =
Compiler::GetSharedFunctionInfoForScript(
isolate, source, script_details, origin_options, nullptr, nullptr,
ScriptCompiler::kNoCompileOptions, ScriptCompiler::kNoCacheNoReason,
NOT_NATIVES_CODE);
Handle<SharedFunctionInfo> shared_info;
if (!maybe_function_info.ToHandle(&shared_info)) return MaybeHandle<Object>();
Handle<JSFunction> fun =
isolate->factory()->NewFunctionFromSharedFunctionInfo(shared_info,
context);
MaybeHandle<Object> result = Execution::Call(
isolate, fun, Handle<JSObject>(context->global_proxy(), isolate), 0,
nullptr);
return result;
}
MaybeHandle<Object> DebugEvaluate::Local(Isolate* isolate,
StackFrameId frame_id,
int inlined_jsframe_index,
......
......@@ -24,10 +24,8 @@ class FrameInspector;
class DebugEvaluate : public AllStatic {
public:
static MaybeHandle<Object> Global(Isolate* isolate, Handle<String> source,
debug::EvaluateGlobalMode mode);
static MaybeHandle<Object> GlobalREPL(Isolate* isolate,
Handle<String> source);
debug::EvaluateGlobalMode mode,
REPLMode repl_mode = REPLMode::kNo);
// Evaluate a piece of JavaScript in the context of a stack frame for
// debugging. Things that need special attention are:
......
......@@ -479,8 +479,8 @@ enum class EvaluateGlobalMode {
};
V8_EXPORT_PRIVATE v8::MaybeLocal<v8::Value> EvaluateGlobal(
v8::Isolate* isolate, v8::Local<v8::String> source,
EvaluateGlobalMode mode);
v8::Isolate* isolate, v8::Local<v8::String> source, EvaluateGlobalMode mode,
bool repl_mode = false);
int GetDebuggingId(v8::Local<v8::Function> function);
......
......@@ -280,9 +280,10 @@ void V8RuntimeAgentImpl::evaluate(
} else if (disableBreaks.fromMaybe(false)) {
mode = v8::debug::EvaluateGlobalMode::kDisableBreaks;
}
const v8::Local<v8::String> source =
toV8String(m_inspector->isolate(), expression);
maybeResultValue = v8::debug::EvaluateGlobal(
m_inspector->isolate(), toV8String(m_inspector->isolate(), expression),
mode);
m_inspector->isolate(), source, mode, replMode.fromMaybe(false));
} // Run microtasks before returning result.
// Re-initialize after running client's code, as it could have destroyed
......
......@@ -215,7 +215,10 @@ RUNTIME_FUNCTION(Runtime_RuntimeEvaluateREPL) {
CONVERT_ARG_HANDLE_CHECKED(String, source, 0);
Handle<Object> result;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, result, DebugEvaluate::GlobalREPL(isolate, source));
isolate, result,
DebugEvaluate::Global(isolate, source,
debug::EvaluateGlobalMode::kDefault,
REPLMode::kYes));
return *result;
}
......
Tests that Runtime.evaluate works with REPL mode.
Test 'let' re-declaration
{
id : <messageId>
result : {
result : {
type : undefined
}
}
}
{
id : <messageId>
result : {
result : {
description : 21
type : number
value : 21
}
}
}
{
id : <messageId>
result : {
result : {
type : undefined
}
}
}
{
id : <messageId>
result : {
result : {
description : 42
type : number
value : 42
}
}
}
// Copyright 2019 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 works with REPL mode.");
Protocol.Runtime.enable();
(async function() {
InspectorTest.log("Test 'let' re-declaration");
evaluateRepl('let x = 21;');
evaluateRepl('x;');
evaluateRepl('let x = 42;');
evaluateRepl('x;');
InspectorTest.completeTest();
})();
async function evaluateRepl(expression) {
InspectorTest.logMessage(await Protocol.Runtime.evaluate({
expression: expression,
replMode: true,
}));
}
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