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}
This commit is contained in:
vogelheim 2015-08-04 07:31:41 -07:00 committed by Commit bot
parent 56bd11a11a
commit e045b78d8e

View File

@ -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;