Commit e045b78d authored by vogelheim's avatar vogelheim Committed by Commit bot

Avoid data race when writing Shell::options.script_executed.

The race occurred when Workers were used. Since Workers call
Shell::ExecuteString from a different thread, TSAN (correctly) flags
this as a racy write. Solution would be to either synchronize the writes,
or to 'lift' the write higher up in the call stack and only write the flag
from the main thread. This implements this latter solution.

These methods call Shell::ExecuteString, but do *not* set script_executed:
- ExecuteInThread: Can only occur is JS has already been executed.
- Shell::Load: Callback for JS; so JS has already been executed when
               we get there.
- Shell::RunShell: Interactive shell. We no longer need script_executed once
                   we're here.

BUG=v8:4330
LOG=N

Review URL: https://codereview.chromium.org/1258303004

Cr-Commit-Position: refs/heads/master@{#30003}
parent 56bd11a1
......@@ -1435,6 +1435,7 @@ void SourceGroup::Execute(Isolate* isolate) {
Local<String> source =
String::NewFromUtf8(isolate, argv_[i + 1], NewStringType::kNormal)
.ToLocalChecked();
Shell::options.script_executed = true;
if (!Shell::ExecuteString(isolate, source, file_name, false, true)) {
exception_was_thrown = true;
break;
......@@ -1460,6 +1461,7 @@ void SourceGroup::Execute(Isolate* isolate) {
printf("Error reading '%s'\n", arg);
Shell::Exit(1);
}
Shell::options.script_executed = true;
if (!Shell::ExecuteString(isolate, source, file_name, false, true,
source_type)) {
exception_was_thrown = 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