Commit 0447ba44 authored by Benedikt Meurer's avatar Benedikt Meurer Committed by V8 LUCI CQ

[debug] Mark debug-evaluate script as shared-cross-origin.

Following up on https://crrev.com/c/3540145, this also changes local
debug evaluate scripts to be marked as shared-cross-origin.

Drive-by-fix: This also updates the test for global debug evaluate to
use the official (debug) API instead of peaking into the V8 internals
unnecessarily.

Bug: chromium:1295750
Change-Id: Ief0bc76a4333671f8db761d1f6a5fb740aae698e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3541780Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79568}
parent d423178d
......@@ -288,12 +288,21 @@ struct ScopedTimer {
namespace {
ScriptOriginOptions OriginOptionsForEval(Object script) {
if (!script.IsScript()) return ScriptOriginOptions();
const auto outer_origin_options = Script::cast(script).origin_options();
return ScriptOriginOptions(outer_origin_options.IsSharedCrossOrigin(),
outer_origin_options.IsOpaque());
ScriptOriginOptions OriginOptionsForEval(
Object script, ParsingWhileDebugging parsing_while_debugging) {
bool is_shared_cross_origin =
parsing_while_debugging == ParsingWhileDebugging::kYes;
bool is_opaque = false;
if (script.IsScript()) {
auto script_origin_options = Script::cast(script).origin_options();
if (script_origin_options.IsSharedCrossOrigin()) {
is_shared_cross_origin = true;
}
if (script_origin_options.IsOpaque()) {
is_opaque = true;
}
}
return ScriptOriginOptions(is_shared_cross_origin, is_opaque);
}
} // namespace
......@@ -2289,9 +2298,9 @@ MaybeHandle<JSFunction> Compiler::GetFunctionFromEval(
if (!context->IsNativeContext()) {
maybe_outer_scope_info = handle(context->scope_info(), isolate);
}
script =
parse_info.CreateScript(isolate, source, kNullMaybeHandle,
OriginOptionsForEval(outer_info->script()));
script = parse_info.CreateScript(
isolate, source, kNullMaybeHandle,
OriginOptionsForEval(outer_info->script(), parsing_while_debugging));
script->set_eval_from_shared(*outer_info);
if (eval_position == kNoSourcePosition) {
// If the position is missing, attempt to get the code offset by
......@@ -2302,7 +2311,8 @@ MaybeHandle<JSFunction> Compiler::GetFunctionFromEval(
FrameSummary summary = it.GetTopValidFrame();
script->set_eval_from_shared(
summary.AsJavaScript().function()->shared());
script->set_origin_options(OriginOptionsForEval(*summary.script()));
script->set_origin_options(
OriginOptionsForEval(*summary.script(), parsing_while_debugging));
eval_position = -summary.code_offset();
} else {
eval_position = 0;
......
......@@ -40,10 +40,11 @@ class DebugEvaluate : public AllStatic {
// The stack frame can be either a JavaScript stack frame or a Wasm
// stack frame. In the latter case, a special Debug Proxy API is
// provided to peek into the Wasm state.
static MaybeHandle<Object> Local(Isolate* isolate, StackFrameId frame_id,
int inlined_jsframe_index,
Handle<String> source,
bool throw_on_side_effect);
static V8_EXPORT_PRIVATE MaybeHandle<Object> Local(Isolate* isolate,
StackFrameId frame_id,
int inlined_jsframe_index,
Handle<String> source,
bool throw_on_side_effect);
// This is used for break-at-entry for builtins and API functions.
// Evaluate a piece of JavaScript in the native context, but with the
......
......@@ -34,7 +34,6 @@
#include "src/api/api-inl.h"
#include "src/base/strings.h"
#include "src/codegen/compilation-cache.h"
#include "src/debug/debug-evaluate.h"
#include "src/debug/debug-interface.h"
#include "src/debug/debug.h"
#include "src/deoptimizer/deoptimizer.h"
......@@ -4566,21 +4565,48 @@ TEST(DebugEvaluateNoSideEffect) {
DisableDebugger(env->GetIsolate());
}
TEST(DebugEvaluateSharedCrossOrigin) {
TEST(DebugEvaluateGlobalSharedCrossOrigin) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
i::Isolate* isolate = CcTest::i_isolate();
v8::TryCatch tryCatch(env->GetIsolate());
v8::Isolate* isolate = env->GetIsolate();
v8::HandleScope scope(isolate);
v8::TryCatch tryCatch(isolate);
tryCatch.SetCaptureMessage(true);
i::MaybeHandle<i::Object> result = i::DebugEvaluate::Global(
isolate,
isolate->factory()->NewStringFromStaticChars("throw new Error()"),
v8::debug::EvaluateGlobalMode::kDefault);
CHECK(result.is_null());
v8::MaybeLocal<v8::Value> result =
v8::debug::EvaluateGlobal(isolate, v8_str(isolate, "throw new Error()"),
v8::debug::EvaluateGlobalMode::kDefault);
CHECK(result.IsEmpty());
CHECK(tryCatch.HasCaught());
CHECK(tryCatch.Message()->IsSharedCrossOrigin());
}
TEST(DebugEvaluateLocalSharedCrossOrigin) {
struct BreakProgramDelegate : public v8::debug::DebugDelegate {
void BreakProgramRequested(v8::Local<v8::Context> context,
std::vector<v8::debug::BreakpointId> const&,
v8::debug::BreakReasons) final {
v8::Isolate* isolate = context->GetIsolate();
v8::TryCatch tryCatch(isolate);
tryCatch.SetCaptureMessage(true);
std::unique_ptr<v8::debug::StackTraceIterator> it =
v8::debug::StackTraceIterator::Create(isolate);
v8::MaybeLocal<v8::Value> result =
it->Evaluate(v8_str(isolate, "throw new Error()"), false);
CHECK(result.IsEmpty());
CHECK(tryCatch.HasCaught());
CHECK(tryCatch.Message()->IsSharedCrossOrigin());
}
} delegate;
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
v8::HandleScope scope(isolate);
v8::debug::SetDebugDelegate(isolate, &delegate);
v8::Script::Compile(env.local(), v8_str(isolate, "debugger;"))
.ToLocalChecked()
->Run(env.local())
.ToLocalChecked();
v8::debug::SetDebugDelegate(isolate, nullptr);
}
namespace {
i::MaybeHandle<i::Script> FindScript(
i::Isolate* isolate, const std::vector<i::Handle<i::Script>>& scripts,
......
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