Bug 1544882 - Add ScriptSource::setRetrievedSource to clarify the ScriptSource::data state transition when retrieved source is set. r=arai
authorJeff Walden <jwalden@mit.edu>
Mon, 15 Apr 2019 18:37:41 -0700
changeset 530257 d4d8e4bf895f84f9a6a62080b6eebb6100ccd484
parent 530256 7e238465037a8a9f7fedb033e50c9d4e9cb9c5f6
child 530258 d137eb73db95e59bc9647eb9d5d284e92c8ca957
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersarai
bugs1544882
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1544882 - Add ScriptSource::setRetrievedSource to clarify the ScriptSource::data state transition when retrieved source is set. r=arai Differential Revision: https://phabricator.services.mozilla.com/D27772
js/src/vm/JSScript.cpp
js/src/vm/JSScript.h
--- a/js/src/vm/JSScript.cpp
+++ b/js/src/vm/JSScript.cpp
@@ -1696,17 +1696,17 @@ class ScriptSource::LoadSourceMatcher {
       return false;
     }
     if (!src) {
       return true;
     }
 
     // XXX On-demand source is currently only UTF-16.  Perhaps it should be
     //     changed to UTF-8, or UTF-8 be allowed in addition to UTF-16?
-    if (!ss_->setSource(cx_, EntryUnits<char16_t>(src), length)) {
+    if (!ss_->setRetrievedSource(cx_, EntryUnits<char16_t>(src), length)) {
       return false;
     }
 
     *loaded_ = true;
     return true;
   }
 };
 
@@ -2111,16 +2111,26 @@ MOZ_MUST_USE bool ScriptSource::setSourc
     ReportOutOfMemory(cx);
     return false;
   }
 
   setSource<Unit>(std::move(*deduped));
   return true;
 }
 
+template <typename Unit>
+MOZ_MUST_USE bool ScriptSource::setRetrievedSource(JSContext* cx,
+                                                   EntryUnits<Unit>&& source,
+                                                   size_t length) {
+  MOZ_ASSERT(sourceRetrievable_);
+  MOZ_ASSERT(data.is<Missing>(),
+             "retrievable source must be indicated as missing");
+  return setSource(cx, std::move(source), length);
+}
+
 #if defined(JS_BUILD_BINAST)
 
 MOZ_MUST_USE bool ScriptSource::setBinASTSourceCopy(JSContext* cx,
                                                     const uint8_t* buf,
                                                     size_t len) {
   auto& cache = cx->zone()->runtimeFromAnyThread()->sharedImmutableStrings();
   auto deduped = cache.getOrCreate(reinterpret_cast<const char*>(buf), len);
   if (!deduped) {
--- a/js/src/vm/JSScript.h
+++ b/js/src/vm/JSScript.h
@@ -957,16 +957,22 @@ class ScriptSource {
 
   void addSizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf,
                               JS::ScriptSourceInfo* info) const;
 
   template <typename Unit>
   MOZ_MUST_USE bool setSource(JSContext* cx, EntryUnits<Unit>&& source,
                               size_t length);
 
+  // Set the retrieved source for a |ScriptSource| whose source was recorded as
+  // missing but retrievable.
+  template <typename Unit>
+  MOZ_MUST_USE bool setRetrievedSource(JSContext* cx, EntryUnits<Unit>&& source,
+                                       size_t length);
+
   template <typename Unit>
   void setSource(
       typename SourceTypeTraits<Unit>::SharedImmutableString uncompressed);
 
   MOZ_MUST_USE bool tryCompressOffThread(JSContext* cx);
 
   // Convert this ScriptSource from storing uncompressed source of the given
   // type, to storing compressed source.  (Raw compressed source is always