Bug 1544882 - Convert ScriptSource::setSource to ScriptSource::setUncompressedSourceHelper as a helper function that more-precise functions can call. r=arai

Differential Revision: https://phabricator.services.mozilla.com/D27775

--HG--
extra : rebase_source : 887832045a4b514064ffa975c405e9ffef5437e7
This commit is contained in:
Jeff Walden 2019-04-15 19:18:05 -07:00
Родитель e8cf026880
Коммит f3eff16926
2 изменённых файлов: 27 добавлений и 8 удалений

Просмотреть файл

@ -2093,9 +2093,8 @@ JSFlatString* ScriptSource::functionBodyString(JSContext* cx) {
}
template <typename Unit>
MOZ_MUST_USE bool ScriptSource::setSource(JSContext* cx,
EntryUnits<Unit>&& source,
size_t length) {
MOZ_MUST_USE bool ScriptSource::setUncompressedSourceHelper(
JSContext* cx, EntryUnits<Unit>&& source, size_t length) {
MOZ_ASSERT(data.is<Missing>());
auto& cache = cx->zone()->runtimeFromAnyThread()->sharedImmutableStrings();
@ -2118,7 +2117,7 @@ MOZ_MUST_USE bool ScriptSource::setRetrievedSource(JSContext* cx,
MOZ_ASSERT(sourceRetrievable_);
MOZ_ASSERT(data.is<Missing>(),
"retrievable source must be indicated as missing");
return setSource(cx, std::move(source), length);
return setUncompressedSourceHelper(cx, std::move(source), length);
}
#if defined(JS_BUILD_BINAST)
@ -2497,6 +2496,13 @@ bool ScriptSource::xdrFinalizeEncoder(JS::TranscodeBuffer& buffer) {
return res.isOk();
}
template <typename Unit>
MOZ_MUST_USE bool ScriptSource::initializeUncompressedSource(
JSContext* cx, EntryUnits<Unit>&& source, size_t length) {
MOZ_ASSERT(data.is<Missing>(), "must be initializing a fresh ScriptSource");
return setUncompressedSourceHelper(cx, std::move(source), length);
}
template <typename Unit>
struct SourceDecoder {
XDRState<XDR_DECODE>* const xdr_;
@ -2519,8 +2525,8 @@ struct SourceDecoder {
MOZ_TRY(xdr_->codeChars(sourceUnits.get(), uncompressedLength_));
if (!scriptSource_->setSource(xdr_->cx(), std::move(sourceUnits),
uncompressedLength_)) {
if (!scriptSource_->initializeUncompressedSource(
xdr_->cx(), std::move(sourceUnits), uncompressedLength_)) {
return xdr_->fail(JS::TranscodeResult_Throw);
}

Просмотреть файл

@ -958,9 +958,22 @@ class ScriptSource {
void addSizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf,
JS::ScriptSourceInfo* info) const;
private:
// Overwrites |data| with the uncompressed data from |source|. (This function
// currently asserts |data.is<Missing>()|, but callers should assert it as
// well, because this function shortly will be used in other cases and the
// assertion will have to be removed.)
template <typename Unit>
MOZ_MUST_USE bool setSource(JSContext* cx, EntryUnits<Unit>&& source,
size_t length);
MOZ_MUST_USE bool setUncompressedSourceHelper(JSContext* cx,
EntryUnits<Unit>&& source,
size_t length);
public:
// Initialize a fresh |ScriptSource| with uncompressed source.
template <typename Unit>
MOZ_MUST_USE bool initializeUncompressedSource(JSContext* cx,
EntryUnits<Unit>&& source,
size_t length);
// Set the retrieved source for a |ScriptSource| whose source was recorded as
// missing but retrievable.