Bug 1557791 - Use isCompressed/isUncompressed rather than direct type-testing of |data|. r=arai
authorJeff Walden <jwalden@mit.edu>
Thu, 06 Jun 2019 13:46:58 -0700
changeset 478269 53f1e230255dd7419fdc6b934d5d15faa276df73
parent 478268 a289b17746ee5e69ed22dca2d54f0f6c1b59d728
child 478270 3048fe4c98f02d2e9ffd6aaf4ec49125b8ab7a1d
push id5
push uservporof@mozilla.com
push dateWed, 12 Jun 2019 10:24:37 +0000
reviewersarai
bugs1557791
milestone69.0a1
Bug 1557791 - Use isCompressed/isUncompressed rather than direct type-testing of |data|. r=arai Differential Revision: https://phabricator.services.mozilla.com/D34200
js/src/vm/JSScript.cpp
--- a/js/src/vm/JSScript.cpp
+++ b/js/src/vm/JSScript.cpp
@@ -1908,33 +1908,33 @@ ScriptSource::PinnedUnits<Unit>::~Pinned
 
 template <typename Unit>
 const Unit* ScriptSource::units(JSContext* cx,
                                 UncompressedSourceCache::AutoHoldEntry& holder,
                                 size_t begin, size_t len) {
   MOZ_ASSERT(begin <= length());
   MOZ_ASSERT(begin + len <= length());
 
-  if (data.is<Uncompressed<Unit>>()) {
+  if (isUncompressed<Unit>()) {
     const Unit* units = data.as<Uncompressed<Unit>>().units();
     if (!units) {
       return nullptr;
     }
     return units + begin;
   }
 
   if (data.is<Missing>()) {
     MOZ_CRASH("ScriptSource::units() on ScriptSource with missing source");
   }
 
   if (data.is<Retrievable<Unit>>()) {
     MOZ_CRASH("ScriptSource::units() on ScriptSource with retrievable source");
   }
 
-  MOZ_ASSERT(data.is<Compressed<Unit>>());
+  MOZ_ASSERT(isCompressed<Unit>());
 
   // Determine first/last chunks, the offset (in bytes) into the first chunk
   // of the requested units, and the number of bytes in the last chunk.
   //
   // Note that first and last chunk sizes are miscomputed and *must not be
   // used* when the first chunk is the last chunk.
   size_t firstChunk, firstChunkOffset, firstChunkSize;
   size_t lastChunk, lastChunkSize;
@@ -2224,17 +2224,17 @@ bool ScriptSource::tryCompressOffThread(
     return false;
   }
   return EnqueueOffThreadCompression(cx, std::move(task));
 }
 
 template <typename Unit>
 void ScriptSource::convertToCompressedSource(SharedImmutableString compressed,
                                              size_t uncompressedLength) {
-  MOZ_ASSERT(data.is<Uncompressed<Unit>>(),
+  MOZ_ASSERT(isUncompressed<Unit>(),
              "should only be converting uncompressed source to compressed "
              "source identically encoded");
   MOZ_ASSERT(length() == uncompressedLength);
 
   if (pinnedUnitsStack_) {
     MOZ_ASSERT(pendingCompressed_.empty());
     pendingCompressed_.construct<CompressedData<Unit>>(std::move(compressed),
                                                        uncompressedLength);
@@ -2330,17 +2330,17 @@ static MOZ_MUST_USE bool reallocUniquePt
   mozilla::Unused << unique.release();
   unique.reset(newPtr);
   return true;
 }
 
 template <typename Unit>
 void SourceCompressionTask::workEncodingSpecific() {
   ScriptSource* source = sourceHolder_.get();
-  MOZ_ASSERT(source->data.is<ScriptSource::Uncompressed<Unit>>());
+  MOZ_ASSERT(source->isUncompressed<Unit>());
 
   // Try to keep the maximum memory usage down by only allocating half the
   // size of the string, first.
   size_t inputBytes = source->length() * sizeof(Unit);
   size_t firstSize = inputBytes / 2;
   UniqueChars compressed(js_pod_malloc<char>(firstSize));
   if (!compressed) {
     return;
@@ -2623,17 +2623,17 @@ template <typename Unit, XDRMode mode>
 XDRResult ScriptSource::codeUncompressedData(XDRState<mode>* const xdr,
                                              ScriptSource* const ss,
                                              bool retrievable) {
   static_assert(std::is_same<Unit, Utf8Unit>::value ||
                     std::is_same<Unit, char16_t>::value,
                 "should handle UTF-8 and UTF-16");
 
   if (mode == XDR_ENCODE) {
-    MOZ_ASSERT(ss->data.is<Uncompressed<Unit>>());
+    MOZ_ASSERT(ss->isUncompressed<Unit>());
   } else {
     MOZ_ASSERT(ss->data.is<Missing>());
   }
 
   MOZ_ASSERT(retrievable == ss->sourceRetrievable());
 
   if (retrievable) {
     // It's unnecessary to code uncompressed data if it can just be retrieved
@@ -2659,17 +2659,17 @@ template <typename Unit, XDRMode mode>
 XDRResult ScriptSource::codeCompressedData(XDRState<mode>* const xdr,
                                            ScriptSource* const ss,
                                            bool retrievable) {
   static_assert(std::is_same<Unit, Utf8Unit>::value ||
                     std::is_same<Unit, char16_t>::value,
                 "should handle UTF-8 and UTF-16");
 
   if (mode == XDR_ENCODE) {
-    MOZ_ASSERT(ss->data.is<Compressed<Unit>>());
+    MOZ_ASSERT(ss->isCompressed<Unit>());
   } else {
     MOZ_ASSERT(ss->data.is<Missing>());
   }
 
   MOZ_ASSERT(retrievable == ss->sourceRetrievable());
 
   if (retrievable) {
     // It's unnecessary to code compressed data if it can just be retrieved