Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit ad89a11

Browse files
committed
Backed out 7 changesets (bug 1475228) for causing Spidermonkey rust failures on Linux x64 debug
Backed out changeset e91802969fb7 (bug 1475228) Backed out changeset 623af73419eb (bug 1475228) Backed out changeset bf96bd78dc11 (bug 1475228) Backed out changeset 104817d51d1b (bug 1475228) Backed out changeset d3829c85f650 (bug 1475228) Backed out changeset 74d10b32b3ea (bug 1475228) Backed out changeset dde64fbe2f0d (bug 1475228)
1 parent b25dbdc commit ad89a11

23 files changed

Lines changed: 256 additions & 225 deletions

dom/base/nsJSUtils.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,11 @@ nsJSUtils::CompileFunction(AutoJSAPI& jsapi,
9494

9595
// Compile.
9696
JS::Rooted<JSFunction*> fun(cx);
97-
JS::SourceBufferHolder source(PromiseFlatString(aBody).get(), aBody.Length(),
98-
JS::SourceBufferHolder::NoOwnership);
9997
if (!JS::CompileFunction(cx, aScopeChain, aOptions,
10098
PromiseFlatCString(aName).get(),
10199
aArgCount, aArgArray,
102-
source, &fun))
100+
PromiseFlatString(aBody).get(),
101+
aBody.Length(), &fun))
103102
{
104103
return NS_ERROR_FAILURE;
105104
}

dom/script/ScriptLoadRequest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ ScriptLoadRequest::SetTextSource()
166166
{
167167
MOZ_ASSERT(IsUnknownDataType());
168168
mDataType = DataType::eTextSource;
169-
mScriptData.emplace(VariantType<ScriptTextBuffer>());
169+
mScriptData.emplace(VariantType<Vector<char16_t>>());
170170
}
171171

172172
void
@@ -175,7 +175,7 @@ ScriptLoadRequest::SetBinASTSource()
175175
#ifdef JS_BUILD_BINAST
176176
MOZ_ASSERT(IsUnknownDataType());
177177
mDataType = DataType::eBinASTSource;
178-
mScriptData.emplace(VariantType<BinASTSourceBuffer>());
178+
mScriptData.emplace(VariantType<Vector<uint8_t>>());
179179
#else
180180
MOZ_CRASH("BinAST not supported");
181181
#endif

dom/script/ScriptLoadRequest.h

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -171,28 +171,21 @@ class ScriptLoadRequest : public nsISupports,
171171
void SetBinASTSource();
172172
void SetBytecode();
173173

174-
using ScriptTextBuffer = Vector<char16_t, 0, JSMallocAllocPolicy>;
175-
using BinASTSourceBuffer = Vector<uint8_t>;
176-
177-
const ScriptTextBuffer& ScriptText() const
178-
{
174+
const Vector<char16_t>& ScriptText() const {
179175
MOZ_ASSERT(IsTextSource());
180-
return mScriptData->as<ScriptTextBuffer>();
176+
return mScriptData->as<Vector<char16_t>>();
181177
}
182-
ScriptTextBuffer& ScriptText()
183-
{
178+
Vector<char16_t>& ScriptText() {
184179
MOZ_ASSERT(IsTextSource());
185-
return mScriptData->as<ScriptTextBuffer>();
180+
return mScriptData->as<Vector<char16_t>>();
186181
}
187-
const BinASTSourceBuffer& ScriptBinASTData() const
188-
{
182+
const Vector<uint8_t>& ScriptBinASTData() const {
189183
MOZ_ASSERT(IsBinASTSource());
190-
return mScriptData->as<BinASTSourceBuffer>();
184+
return mScriptData->as<Vector<uint8_t>>();
191185
}
192-
BinASTSourceBuffer& ScriptBinASTData()
193-
{
186+
Vector<uint8_t>& ScriptBinASTData() {
194187
MOZ_ASSERT(IsBinASTSource());
195-
return mScriptData->as<BinASTSourceBuffer>();
188+
return mScriptData->as<Vector<uint8_t>>();
196189
}
197190

198191
enum class ScriptMode : uint8_t {
@@ -259,7 +252,7 @@ class ScriptLoadRequest : public nsISupports,
259252
// Holds script source data for non-inline scripts. Don't use nsString so we
260253
// can give ownership to jsapi. Holds either char16_t source text characters
261254
// or BinAST encoded bytes depending on mSourceEncoding.
262-
Maybe<Variant<ScriptTextBuffer, BinASTSourceBuffer>> mScriptData;
255+
Maybe<Variant<Vector<char16_t>, Vector<uint8_t>>> mScriptData;
263256

264257
// Holds the SRI serialized hash and the script bytecode for non-inline
265258
// scripts.

dom/script/ScriptLoader.cpp

Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,8 @@ ScriptLoader::CreateModuleScript(ModuleLoadRequest* aRequest)
491491
rv = FillCompileOptionsForRequest(aes, aRequest, global, &options);
492492

493493
if (NS_SUCCEEDED(rv)) {
494-
SourceBufferHolder srcBuf = GetScriptSource(cx, aRequest);
494+
nsAutoString inlineData;
495+
SourceBufferHolder srcBuf = GetScriptSource(aRequest, inlineData);
495496
rv = nsJSUtils::CompileModule(cx, srcBuf, global, options, &module);
496497
}
497498
}
@@ -1769,16 +1770,14 @@ OffThreadScriptLoaderCallback(JS::OffThreadToken* aToken, void* aCallbackData)
17691770
}
17701771

17711772
nsresult
1772-
ScriptLoader::AttemptAsyncScriptCompile(ScriptLoadRequest* aRequest,
1773-
bool* aCouldCompileOut)
1773+
ScriptLoader::AttemptAsyncScriptCompile(ScriptLoadRequest* aRequest)
17741774
{
17751775
MOZ_ASSERT_IF(!aRequest->IsModuleRequest(), aRequest->IsReadyToRun());
17761776
MOZ_ASSERT(!aRequest->mWasCompiledOMT);
1777-
MOZ_ASSERT(aCouldCompileOut && !*aCouldCompileOut);
17781777

17791778
// Don't off-thread compile inline scripts.
17801779
if (aRequest->mIsInline) {
1781-
return NS_OK;
1780+
return NS_ERROR_FAILURE;
17821781
}
17831782

17841783
nsCOMPtr<nsIScriptGlobalObject> globalObject = GetScriptGlobalObject();
@@ -1802,19 +1801,19 @@ ScriptLoader::AttemptAsyncScriptCompile(ScriptLoadRequest* aRequest,
18021801

18031802
if (aRequest->IsTextSource()) {
18041803
if (!JS::CanCompileOffThread(cx, options, aRequest->ScriptText().length())) {
1805-
return NS_OK;
1804+
return NS_ERROR_FAILURE;
18061805
}
18071806
#ifdef JS_BUILD_BINAST
18081807
} else if (aRequest->IsBinASTSource()) {
18091808
if (!JS::CanDecodeBinASTOffThread(cx, options, aRequest->ScriptBinASTData().length())) {
1810-
return NS_OK;
1809+
return NS_ERROR_FAILURE;
18111810
}
18121811
#endif
18131812
} else {
18141813
MOZ_ASSERT(aRequest->IsBytecode());
18151814
size_t length = aRequest->mScriptBytecode.length() - aRequest->mBytecodeOffset;
18161815
if (!JS::CanDecodeOffThread(cx, options, length)) {
1817-
return NS_OK;
1816+
return NS_ERROR_FAILURE;
18181817
}
18191818
}
18201819

@@ -1823,9 +1822,9 @@ ScriptLoader::AttemptAsyncScriptCompile(ScriptLoadRequest* aRequest,
18231822

18241823
if (aRequest->IsModuleRequest()) {
18251824
MOZ_ASSERT(aRequest->IsTextSource());
1826-
SourceBufferHolder srcBuf = GetScriptSource(cx, aRequest);
18271825
if (!JS::CompileOffThreadModule(cx, options,
1828-
srcBuf,
1826+
aRequest->ScriptText().begin(),
1827+
aRequest->ScriptText().length(),
18291828
OffThreadScriptLoaderCallback,
18301829
static_cast<void*>(runnable))) {
18311830
return NS_ERROR_OUT_OF_MEMORY;
@@ -1851,9 +1850,9 @@ ScriptLoader::AttemptAsyncScriptCompile(ScriptLoadRequest* aRequest,
18511850
#endif
18521851
} else {
18531852
MOZ_ASSERT(aRequest->IsTextSource());
1854-
SourceBufferHolder srcBuf = GetScriptSource(cx, aRequest);
18551853
if (!JS::CompileOffThread(cx, options,
1856-
srcBuf,
1854+
aRequest->ScriptText().begin(),
1855+
aRequest->ScriptText().length(),
18571856
OffThreadScriptLoaderCallback,
18581857
static_cast<void*>(runnable))) {
18591858
return NS_ERROR_OUT_OF_MEMORY;
@@ -1866,7 +1865,6 @@ ScriptLoader::AttemptAsyncScriptCompile(ScriptLoadRequest* aRequest,
18661865
// to call ScriptLoader::ProcessOffThreadRequest with the same request.
18671866
aRequest->mProgress = ScriptLoadRequest::Progress::eCompiling;
18681867

1869-
*aCouldCompileOut = true;
18701868
Unused << runnable.forget();
18711869
return NS_OK;
18721870
}
@@ -1881,42 +1879,33 @@ ScriptLoader::CompileOffThreadOrProcessRequest(ScriptLoadRequest* aRequest)
18811879
NS_ASSERTION(!aRequest->InCompilingStage(),
18821880
"Candidate for off-thread compile is already in compiling stage.");
18831881

1884-
bool couldCompile = false;
1885-
nsresult rv = AttemptAsyncScriptCompile(aRequest, &couldCompile);
1886-
if (NS_FAILED(rv)) {
1887-
HandleLoadError(aRequest, rv);
1882+
nsresult rv = AttemptAsyncScriptCompile(aRequest);
1883+
if (NS_SUCCEEDED(rv)) {
18881884
return rv;
18891885
}
18901886

1891-
if (couldCompile) {
1892-
return NS_OK;
1893-
}
1894-
18951887
return ProcessRequest(aRequest);
18961888
}
18971889

18981890
SourceBufferHolder
1899-
ScriptLoader::GetScriptSource(JSContext* aCx, ScriptLoadRequest* aRequest)
1891+
ScriptLoader::GetScriptSource(ScriptLoadRequest* aRequest, nsAutoString& inlineData)
19001892
{
19011893
// Return a SourceBufferHolder object holding the script's source text.
1902-
// Ownership of the buffer is transferred to the resulting SourceBufferHolder.
1894+
// |inlineData| is used to hold the text for inline objects.
19031895

19041896
// If there's no script text, we try to get it from the element
19051897
if (aRequest->mIsInline) {
1906-
nsAutoString inlineData;
1898+
// XXX This is inefficient - GetText makes multiple
1899+
// copies.
19071900
aRequest->mElement->GetScriptText(inlineData);
1908-
1909-
size_t nbytes = inlineData.Length() * sizeof(char16_t);
1910-
JS::UniqueTwoByteChars chars(static_cast<char16_t*>(JS_malloc(aCx, nbytes)));
1911-
MOZ_RELEASE_ASSERT(chars);
1912-
memcpy(chars.get(), inlineData.get(), nbytes);
1913-
return SourceBufferHolder(std::move(chars), inlineData.Length());
1901+
return SourceBufferHolder(inlineData.get(),
1902+
inlineData.Length(),
1903+
SourceBufferHolder::NoOwnership);
19141904
}
19151905

1916-
size_t length = aRequest->ScriptText().length();
1917-
return SourceBufferHolder(aRequest->ScriptText().extractOrCopyRawBuffer(),
1918-
length,
1919-
SourceBufferHolder::GiveOwnership);
1906+
return SourceBufferHolder(aRequest->ScriptText().begin(),
1907+
aRequest->ScriptText().length(),
1908+
SourceBufferHolder::NoOwnership);
19201909
}
19211910

19221911
nsresult
@@ -2361,7 +2350,8 @@ ScriptLoader::EvaluateScript(ScriptLoadRequest* aRequest)
23612350
&script);
23622351
} else {
23632352
MOZ_ASSERT(aRequest->IsTextSource());
2364-
SourceBufferHolder srcBuf = GetScriptSource(cx, aRequest);
2353+
nsAutoString inlineData;
2354+
SourceBufferHolder srcBuf = GetScriptSource(aRequest, inlineData);
23652355
rv = exec.CompileAndExec(options, srcBuf, &script);
23662356
}
23672357
}
@@ -3190,12 +3180,11 @@ ScriptLoader::PrepareLoadedRequest(ScriptLoadRequest* aRequest,
31903180
channel->GetURI(getter_AddRefs(request->mBaseURL));
31913181
}
31923182

3183+
31933184
// Attempt to compile off main thread.
3194-
bool couldCompile = false;
3195-
rv = AttemptAsyncScriptCompile(request, &couldCompile);
3196-
NS_ENSURE_SUCCESS(rv, rv);
3197-
if (couldCompile) {
3198-
return NS_OK;
3185+
rv = AttemptAsyncScriptCompile(request);
3186+
if (NS_SUCCEEDED(rv)) {
3187+
return rv;
31993188
}
32003189

32013190
// Otherwise compile it right away and start fetching descendents.
@@ -3208,15 +3197,18 @@ ScriptLoader::PrepareLoadedRequest(ScriptLoadRequest* aRequest,
32083197
// If this is currently blocking the parser, attempt to compile it off-main-thread.
32093198
if (aRequest == mParserBlockingRequest && NumberOfProcessors() > 1) {
32103199
MOZ_ASSERT(!aRequest->IsModuleRequest());
3211-
bool couldCompile = false;
3212-
nsresult rv = AttemptAsyncScriptCompile(aRequest, &couldCompile);
3213-
NS_ENSURE_SUCCESS(rv, rv);
3214-
if (couldCompile) {
3200+
nsresult rv = AttemptAsyncScriptCompile(aRequest);
3201+
if (rv == NS_OK) {
32153202
MOZ_ASSERT(aRequest->mProgress == ScriptLoadRequest::Progress::eCompiling,
32163203
"Request should be off-thread compiling now.");
32173204
return NS_OK;
32183205
}
32193206

3207+
// If off-thread compile errored, return the error.
3208+
if (rv != NS_ERROR_FAILURE) {
3209+
return rv;
3210+
}
3211+
32203212
// If off-thread compile was rejected, continue with regular processing.
32213213
}
32223214

dom/script/ScriptLoader.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,7 @@ class ScriptLoader final : public nsISupports
454454

455455
void ReportErrorToConsole(ScriptLoadRequest *aRequest, nsresult aResult) const;
456456

457-
nsresult AttemptAsyncScriptCompile(ScriptLoadRequest* aRequest,
458-
bool* aCouldCompileOut);
457+
nsresult AttemptAsyncScriptCompile(ScriptLoadRequest* aRequest);
459458
nsresult ProcessRequest(ScriptLoadRequest* aRequest);
460459
nsresult CompileOffThreadOrProcessRequest(ScriptLoadRequest* aRequest);
461460
void FireScriptAvailable(nsresult aResult,
@@ -505,8 +504,8 @@ class ScriptLoader final : public nsISupports
505504

506505
void MaybeMoveToLoadedList(ScriptLoadRequest* aRequest);
507506

508-
JS::SourceBufferHolder GetScriptSource(JSContext* aCx,
509-
ScriptLoadRequest* aRequest);
507+
JS::SourceBufferHolder GetScriptSource(ScriptLoadRequest* aRequest,
508+
nsAutoString& inlineData);
510509

511510
void SetModuleFetchStarted(ModuleLoadRequest *aRequest);
512511
void SetModuleFetchFinishedAndResumeWaitingRequests(ModuleLoadRequest* aRequest,

dom/workers/WorkerPrivate.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4941,9 +4941,8 @@ WorkerPrivate::RunExpiredTimeouts(JSContext* aCx)
49414941

49424942
JS::Rooted<JS::Value> unused(aes.cx());
49434943

4944-
JS::SourceBufferHolder srcBuf(script.BeginReading(), script.Length(),
4945-
JS::SourceBufferHolder::NoOwnership);
4946-
if (!JS::Evaluate(aes.cx(), options, srcBuf, &unused) &&
4944+
if (!JS::Evaluate(aes.cx(), options, script.BeginReading(),
4945+
script.Length(), &unused) &&
49474946
!JS_IsExceptionPending(aCx)) {
49484947
retval = false;
49494948
break;

dom/xul/XULDocument.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2376,10 +2376,15 @@ XULDocument::OnStreamComplete(nsIStreamLoader* aLoader,
23762376
rv = mCurrentScriptProto->Compile(srcBuf, uri, 1, this, this);
23772377
if (NS_SUCCEEDED(rv) && !mCurrentScriptProto->HasScriptObject()) {
23782378
// We will be notified via OnOffThreadCompileComplete when the
2379-
// compile finishes. The JS engine has taken ownership of the
2380-
// source buffer.
2381-
MOZ_RELEASE_ASSERT(!srcBuf.ownsChars());
2379+
// compile finishes. Keep the contents of the compiled script
2380+
// alive until the compilation finishes.
23822381
mOffThreadCompiling = true;
2382+
// If the JS engine did not take the source buffer, then take
2383+
// it back here to ensure it remains alive.
2384+
mOffThreadCompileStringBuf = srcBuf.take();
2385+
if (mOffThreadCompileStringBuf) {
2386+
mOffThreadCompileStringLength = srcBuf.length();
2387+
}
23832388
BlockOnload();
23842389
return NS_OK;
23852390
}

dom/xul/nsXULElement.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2417,7 +2417,7 @@ nsXULPrototypeScript::Compile(JS::SourceBufferHolder& aSrcBuf,
24172417

24182418
if (aOffThreadReceiver && JS::CanCompileOffThread(cx, options, aSrcBuf.length())) {
24192419
if (!JS::CompileOffThread(cx, options,
2420-
aSrcBuf,
2420+
aSrcBuf.get(), aSrcBuf.length(),
24212421
OffThreadScriptReceiverCallback,
24222422
static_cast<void*>(aOffThreadReceiver))) {
24232423
return NS_ERROR_OUT_OF_MEMORY;

ipc/testshell/XPCShellEnvironment.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,8 @@ XPCShellEnvironment::EvaluateString(const nsString& aString,
487487
JS::CompileOptions options(cx);
488488
options.setFileAndLine("typein", 0);
489489
JS::Rooted<JSScript*> script(cx);
490-
JS::SourceBufferHolder srcBuf(aString.get(), aString.Length(),
491-
JS::SourceBufferHolder::NoOwnership);
492-
if (!JS_CompileUCScript(cx, srcBuf, options, &script))
490+
if (!JS_CompileUCScript(cx, aString.get(), aString.Length(), options,
491+
&script))
493492
{
494493
return false;
495494
}

0 commit comments

Comments
 (0)