Skip to content

Commit

Permalink
Use V8 IsInReplayCode API
Browse files Browse the repository at this point in the history
  • Loading branch information
bhackett1024 committed Aug 12, 2023
1 parent 105089b commit 580a82e
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ vars = {
# Three lines of non-changing comments so that
# the commit queue can handle CLs rolling V8
# and whatever else without interference from each other.
'v8_revision': 'c86e580010c0337d25390d70e3ed9d251364b5a9',
'v8_revision': '3ffb178192079d96695d5e2010c432dfd062dff4',
# Three lines of non-changing comments so that
# the commit queue can handle CLs rolling swarming_client
# and whatever else without interference from each other.
Expand Down
17 changes: 12 additions & 5 deletions base/record_replay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace recordreplay {
Macro(V8RecordReplayHasDisabledFeatures, (), (), bool, false) \
Macro(V8RecordReplayAreAssertsDisabled, (), (), bool, false) \
Macro(V8IsMainThread, (), (), bool, false) \
Macro(V8RecordReplayIsInReplayCode, (), (), bool, false) \
Macro(V8RecordReplayHadMismatch, (), (), bool, false)

#define ForEachV8APIVoid(Macro) \
Expand Down Expand Up @@ -111,7 +112,9 @@ namespace recordreplay {
Macro(V8RecordReplayMaybeTerminate, \
(void (*callback)(void*), void* data), (callback, data)) \
Macro(V8RecordReplayGetCurrentJSStack, \
(std::string* stackTrace), (stackTrace))
(std::string* stackTrace), (stackTrace)) \
Macro(V8RecordReplayEnterReplayCode, (), ()) \
Macro(V8RecordReplayExitReplayCode, (), ())

#if BUILDFLAG(IS_WIN)

Expand Down Expand Up @@ -493,12 +496,16 @@ int NewIdAnyThread(const char* name) {
}

bool IsInReplayCode() {
// Events are disallowed when running Replay's own scripts.
// FIXME Add to Recording API.
// https://linear.app/replay/issue/RUN-1502
return IsReplaying() && AreEventsDisallowed();
return V8RecordReplayIsInReplayCode();
}

AutoMarkReplayCode::AutoMarkReplayCode() {
V8RecordReplayEnterReplayCode();
}

AutoMarkReplayCode::~AutoMarkReplayCode() {
V8RecordReplayExitReplayCode();
}

void RecordReplayString(const char* why, std::string& str) {
size_t length = RecordReplayValue(why, str.length());
Expand Down
7 changes: 7 additions & 0 deletions base/record_replay.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,15 @@ void OnNavigationEvent(const char* kind, const char* url);
int NewIdMainThread(const char* name);
int NewIdAnyThread(const char* name);

// Return whether record/replay specific scripts are executing.
bool IsInReplayCode();

// Mark a region where record/replay specific scripts are executing.
struct AutoMarkReplayCode {
AutoMarkReplayCode();
~AutoMarkReplayCode();
};

// stl comparator that uses pointer IDs to compare elements when recording/replaying,
// giving a deterministic sort order.
struct CompareByPointerId {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,6 @@ const gSourceMapData = new Map();
try {
// Save these before page code potentially overwrites them.
const JSON_stringify = JSON.stringify;
const JSON_parse = JSON.parse;
Expand Down Expand Up @@ -4901,6 +4891,7 @@ void SetupRecordReplayCommands(v8::Isolate* isolate, LocalFrame* localFrame) {

if (recordreplay::FeatureEnabled("collect-source-maps") &&
!TestEnv("RECORD_REPLAY_DISABLE_SOURCEMAP_COLLECTION")) {
recordreplay::AutoMarkReplayCode amrc;
RunScript(isolate, context, gSourceMapScript, InternalScriptURL);
}

Expand All @@ -4911,14 +4902,16 @@ void SetupRecordReplayCommands(v8::Isolate* isolate, LocalFrame* localFrame) {
}

if (recordreplay::IsReplaying()) {
recordreplay::AutoMarkReplayCode amrc;
recordreplay::AutoDisallowEvents disallow("SetupRecordReplayCommands");
RunScript(isolate, context, gReplayScript, InternalScriptURL);
}
}

void OnNewRootFrame(v8::Isolate* isolate, LocalFrame* localFrame) {
recordreplay::AutoMarkReplayCode amrc;
v8::Local<v8::Context> context = isolate->GetCurrentContext();

// 1. Register navigation event.
if (localFrame->GetDocument()->Url().ProtocolIsInHTTPFamily()) {
recordreplay::OnNavigationEvent(
Expand All @@ -4941,6 +4934,7 @@ void OnNewRootFrame(v8::Isolate* isolate, LocalFrame* localFrame) {
}

void OnNewWindow2(v8::Isolate* isolate, LocalFrame* localFrame) {
recordreplay::AutoMarkReplayCode amrc;
v8::Local<v8::Context> context = isolate->GetCurrentContext();
RunScript(isolate, context, gOnNewWindowScript,
"record-replay-devtools-OnNewWindow");
Expand Down
2 changes: 2 additions & 0 deletions third_party/blink/renderer/core/frame/dom_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ String DOMWindow::SanitizedCrossDomainAccessErrorMessage(
if (accessing_window_url.IsNull())
return String();

recordreplay::Trace("[RUN-1990] DOMWindow::SanitizedCrossDomainAccessErrorMessage");

const SecurityOrigin* active_origin = accessing_window->GetSecurityOrigin();
String message;
if (cross_document_access == CrossDocumentAccessPolicy::kDisallowed) {
Expand Down
6 changes: 1 addition & 5 deletions third_party/blink/renderer/modules/storage/storage_area.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,7 @@ bool StorageArea::Contains(const String& key,
void StorageArea::NamedPropertyEnumerator(Vector<String>& names,
ExceptionState& exception_state) {
if (!cached_area_->memory_used() && // This means either empty or not loaded
v8::recordreplay::IsReplaying() &&
v8::recordreplay::AreEventsDisallowed()) {
// TODO: Use `IsReplayCode` instead -
// https://linear.app/replay/issue/RUN-1502

recordreplay::IsInReplayCode()) {
// This ignores crash-inducing side effects observed during interceptor key collection
// when handling commands.
// See: https://linear.app/replay/issue/RUN-1315#comment-26f96699
Expand Down

0 comments on commit 580a82e

Please sign in to comment.