Bug 1619953 - P7 - mozJSSubScriptLoader::ReadScript() now attempts reading from input stream even if content length is not already known r=baku
If reading succeeds, it is checked that the length is known from that point on (this check is debug only). Differential Revision: https://phabricator.services.mozilla.com/D81718
This commit is contained in:
@@ -276,7 +276,7 @@ bool mozJSSubScriptLoader::ReadScript(JS::MutableHandle<JSScript*> script,
|
||||
int64_t len = -1;
|
||||
|
||||
rv = chan->GetContentLength(&len);
|
||||
if (NS_FAILED(rv) || len == -1) {
|
||||
if (NS_FAILED(rv)) {
|
||||
ReportError(cx, LOAD_ERROR_NOCONTENT, uri);
|
||||
return false;
|
||||
}
|
||||
@@ -290,6 +290,21 @@ bool mozJSSubScriptLoader::ReadScript(JS::MutableHandle<JSScript*> script,
|
||||
rv = NS_ReadInputStreamToString(instream, buf, len);
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
|
||||
if (len < 0) {
|
||||
len = buf.Length();
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
int64_t currentLength = -1;
|
||||
// if getting content length succeeded above, it should not fail now
|
||||
MOZ_ASSERT(chan->GetContentLength(¤tLength) == NS_OK);
|
||||
// if content length was not known when GetContentLength() was called before,
|
||||
// 'len' would be set to -1 until NS_ReadInputStreamToString() set its correct
|
||||
// value. Every subsequent call to GetContentLength() should return the same
|
||||
// length as that value.
|
||||
MOZ_ASSERT(currentLength == len);
|
||||
#endif
|
||||
|
||||
Maybe<JSAutoRealm> ar;
|
||||
|
||||
// Note that when using the ScriptPreloader cache with loadSubScript, there
|
||||
|
||||
Reference in New Issue
Block a user