From e3a13e809a111ab7fb3c9bea9544a85ea8762428 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Thu, 13 Feb 2014 17:06:21 -0500 Subject: [PATCH] Bug 967936 - Reorder condition to avoid (benign) race with compression thread. r=jorendorff --- js/src/jsscript.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/js/src/jsscript.h b/js/src/jsscript.h index 2ffa3db20edd..73a1cba72746 100644 --- a/js/src/jsscript.h +++ b/js/src/jsscript.h @@ -361,6 +361,15 @@ class ScriptSource { friend class SourceCompressionTask; + // A note on concurrency: + // + // The source may be compressed by a worker thread during parsing. (See + // SourceCompressionTask.) When compression is running in the background, + // ready() returns false. The compression thread touches the |data| union + // and |compressedLength_|. Therefore, it is not safe to read these members + // unless ready() is true. With that said, users of the public ScriptSource + // API should be fine. + union { // Before setSourceCopy or setSource are successfully called, this union // has a nullptr pointer. When the script source is ready, @@ -451,7 +460,7 @@ class ScriptSource bool ready() const { return ready_; } void setSourceRetrievable() { sourceRetrievable_ = true; } bool sourceRetrievable() const { return sourceRetrievable_; } - bool hasSourceData() const { return !!data.source || !ready(); } + bool hasSourceData() const { return !ready() || !!data.source; } uint32_t length() const { JS_ASSERT(hasSourceData()); return length_;