Reviewers: Yang,

Description:
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=4330

Please review this at https://codereview.chromium.org/1258303004/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+2, -1 lines):
  M src/d8.cc


Index: src/d8.cc
diff --git a/src/d8.cc b/src/d8.cc
index 9aeac11bb0a439b59a8933a6b15cdc8f0ac1116f..4a52ca36a343e2cca71471629215603a10a7161e 100644
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -296,7 +296,6 @@ bool Shell::ExecuteString(Isolate* isolate, Local<String> source,
                           bool report_exceptions, SourceType source_type) {
   HandleScope handle_scope(isolate);
   TryCatch try_catch(isolate);
-  options.script_executed = true;

   MaybeLocal<Value> maybe_result;
   {
@@ -1427,6 +1426,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;
@@ -1452,6 +1452,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;


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to