diff --git a/js/src/jsscript.cpp b/js/src/jsscript.cpp index ec62710c357a..3e89b6da6603 100644 --- a/js/src/jsscript.cpp +++ b/js/src/jsscript.cpp @@ -1884,8 +1884,8 @@ ScriptSource::sourceText(JSContext* cx) return mozilla::Nothing(); } - if (!DecompressString((const unsigned char*) ss.compressedData(), - ss.compressedBytes(), + if (!DecompressString((const unsigned char*) c.raw.chars(), + c.raw.length(), reinterpret_cast(decompressed.get()), lengthWithNull * sizeof(char16_t))) { @@ -2051,6 +2051,8 @@ ScriptSource::setSourceCopy(ExclusiveContext* cx, SourceBufferHolder& srcBuf, SourceCompressionTask::ResultType SourceCompressionTask::work() { + MOZ_ASSERT(ss->data.is()); + // Try to keep the maximum memory usage down by only allocating half the // size of the string, first. size_t inputBytes = ss->length() * sizeof(char16_t); @@ -2059,7 +2061,9 @@ SourceCompressionTask::work() if (!compressed) return OOM; - Compressor comp(reinterpret_cast(ss->uncompressedChars()), inputBytes); + const char16_t* chars = ss->data.as().string.chars(); + Compressor comp(reinterpret_cast(chars), + inputBytes); if (!comp.init()) return OOM; @@ -2127,7 +2131,7 @@ ScriptSource::performXDR(XDRState* xdr) } ReturnType match(Compressed& c) { - return c.nbytes(); + return c.raw.length(); } ReturnType match(Missing&) { diff --git a/js/src/jsscript.h b/js/src/jsscript.h index 76bdc5ba4109..cf7caef48e73 100644 --- a/js/src/jsscript.h +++ b/js/src/jsscript.h @@ -620,14 +620,12 @@ class ScriptSource struct Compressed { SharedImmutableString raw; - size_t length; + size_t uncompressedLength; - Compressed(SharedImmutableString&& raw, size_t length) + Compressed(SharedImmutableString&& raw, size_t uncompressedLength) : raw(mozilla::Move(raw)) - , length(length) + , uncompressedLength(uncompressedLength) { } - - size_t nbytes() const { return raw.length(); } }; using SourceType = mozilla::Variant; @@ -724,7 +722,7 @@ class ScriptSource } ReturnType match(const Compressed& c) { - return c.length; + return c.uncompressedLength; } ReturnType match(const Missing& m) { @@ -751,18 +749,6 @@ class ScriptSource void addSizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf, JS::ScriptSourceInfo* info) const; - const char16_t* uncompressedChars() const { - return data.as().string.chars(); - } - - const void* compressedData() const { - return static_cast(data.as().raw.chars()); - } - - size_t compressedBytes() const { - return data.as().nbytes(); - } - MOZ_MUST_USE bool setSource(ExclusiveContext* cx, mozilla::UniquePtr&& source, size_t length);