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

Commit 7dd0d06

Browse files
committed
Bug 1485800 - Rename SourceBufferHolder to SourceText, and add a <typename Unit> template parameter to it so it can hold putative UTF-8 or UTF-16 source text. r=tcampbell, r=fitzgen
--HG-- rename : js/public/SourceBufferHolder.h => js/public/SourceText.h extra : rebase_source : 34df669c2481eaccd6845f53c5ecf656b636f895
1 parent 91a6f80 commit 7dd0d06

46 files changed

Lines changed: 517 additions & 413 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

dom/base/nsFrameMessageManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include "xpcpublic.h"
3232
#include "js/CompilationAndEvaluation.h"
3333
#include "js/JSON.h"
34-
#include "js/SourceBufferHolder.h"
34+
#include "js/SourceText.h"
3535
#include "mozilla/ClearOnShutdown.h"
3636
#include "mozilla/CycleCollectedJSContext.h"
3737
#include "mozilla/Preferences.h"
@@ -1397,7 +1397,7 @@ nsMessageManagerScriptExecutor::TryCacheLoadAndCompileScript(
13971397

13981398
JS::UniqueTwoByteChars srcChars(dataStringBuf);
13991399

1400-
JS::SourceBufferHolder srcBuf;
1400+
JS::SourceText<char16_t> srcBuf;
14011401
if (!srcBuf.init(cx, std::move(srcChars), dataStringLength)) {
14021402
return;
14031403
}

dom/base/nsJSUtils.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "jsfriendapi.h"
1717
#include "js/CompilationAndEvaluation.h"
1818
#include "js/OffThreadScriptCompilation.h"
19-
#include "js/SourceBufferHolder.h"
19+
#include "js/SourceText.h"
2020
#include "nsIScriptContext.h"
2121
#include "nsIScriptElement.h"
2222
#include "nsIScriptGlobalObject.h"
@@ -98,9 +98,9 @@ nsJSUtils::CompileFunction(AutoJSAPI& jsapi,
9898
// Compile.
9999
const nsPromiseFlatString& flatBody = PromiseFlatString(aBody);
100100

101-
JS::SourceBufferHolder source;
101+
JS::SourceText<char16_t> source;
102102
if (!source.init(cx, flatBody.get(), flatBody.Length(),
103-
JS::SourceBufferHolder::NoOwnership))
103+
JS::SourceOwnership::Borrowed))
104104
{
105105
return NS_ERROR_FAILURE;
106106
}
@@ -224,7 +224,7 @@ nsJSUtils::ExecutionContext::JoinAndExec(JS::OffThreadToken** aOffThreadToken,
224224

225225
nsresult
226226
nsJSUtils::ExecutionContext::CompileAndExec(JS::CompileOptions& aCompileOptions,
227-
JS::SourceBufferHolder& aSrcBuf,
227+
JS::SourceText<char16_t>& aSrcBuf,
228228
JS::MutableHandle<JSScript*> aScript)
229229
{
230230
if (mSkip) {
@@ -277,9 +277,9 @@ nsJSUtils::ExecutionContext::CompileAndExec(JS::CompileOptions& aCompileOptions,
277277
}
278278

279279
const nsPromiseFlatString& flatScript = PromiseFlatString(aScript);
280-
JS::SourceBufferHolder srcBuf;
280+
JS::SourceText<char16_t> srcBuf;
281281
if (!srcBuf.init(mCx, flatScript.get(), flatScript.Length(),
282-
JS::SourceBufferHolder::NoOwnership))
282+
JS::SourceOwnership::Borrowed))
283283
{
284284
mSkip = true;
285285
mRv = EvaluationExceptionToNSResult(mCx);
@@ -487,7 +487,7 @@ nsJSUtils::ExecutionContext::ExtractReturnValue(JS::MutableHandle<JS::Value> aRe
487487

488488
nsresult
489489
nsJSUtils::CompileModule(JSContext* aCx,
490-
JS::SourceBufferHolder& aSrcBuf,
490+
JS::SourceText<char16_t>& aSrcBuf,
491491
JS::Handle<JSObject*> aEvaluationGlobal,
492492
JS::CompileOptions &aCompileOptions,
493493
JS::MutableHandle<JSObject*> aModule)

dom/base/nsJSUtils.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "jsapi.h"
2121
#include "jsfriendapi.h"
2222
#include "js/Conversions.h"
23+
#include "js/SourceText.h"
2324
#include "js/StableStringChars.h"
2425
#include "nsString.h"
2526

@@ -157,9 +158,9 @@ class nsJSUtils
157158
MOZ_MUST_USE nsresult JoinAndExec(JS::OffThreadToken** aOffThreadToken,
158159
JS::MutableHandle<JSScript*> aScript);
159160

160-
// Compile a script contained in a SourceBuffer, and execute it.
161+
// Compile a script contained in a SourceText, and execute it.
161162
nsresult CompileAndExec(JS::CompileOptions& aCompileOptions,
162-
JS::SourceBufferHolder& aSrcBuf,
163+
JS::SourceText<char16_t>& aSrcBuf,
163164
JS::MutableHandle<JSScript*> aScript);
164165

165166
// Compile a script contained in a string, and execute it.
@@ -186,7 +187,7 @@ class nsJSUtils
186187
};
187188

188189
static nsresult CompileModule(JSContext* aCx,
189-
JS::SourceBufferHolder& aSrcBuf,
190+
JS::SourceText<char16_t>& aSrcBuf,
190191
JS::Handle<JSObject*> aEvaluationGlobal,
191192
JS::CompileOptions &aCompileOptions,
192193
JS::MutableHandle<JSObject*> aModule);

dom/script/ScriptLoader.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "jsfriendapi.h"
1717
#include "js/CompilationAndEvaluation.h"
1818
#include "js/OffThreadScriptCompilation.h"
19-
#include "js/SourceBufferHolder.h"
19+
#include "js/SourceText.h"
2020
#include "js/Utility.h"
2121
#include "xpcpublic.h"
2222
#include "nsCycleCollectionParticipant.h"
@@ -68,7 +68,7 @@
6868
#include "nsIScriptError.h"
6969
#include "nsIOutputStream.h"
7070

71-
using JS::SourceBufferHolder;
71+
using JS::SourceText;
7272

7373
using mozilla::Telemetry::LABELS_DOM_SCRIPT_PRELOAD_RESULT;
7474

@@ -1933,11 +1933,11 @@ ScriptLoader::CompileOffThreadOrProcessRequest(ScriptLoadRequest* aRequest)
19331933
return ProcessRequest(aRequest);
19341934
}
19351935

1936-
mozilla::Maybe<SourceBufferHolder>
1936+
mozilla::Maybe<SourceText<char16_t>>
19371937
ScriptLoader::GetScriptSource(JSContext* aCx, ScriptLoadRequest* aRequest)
19381938
{
1939-
// Return a SourceBufferHolder object holding the script's source text.
1940-
// Ownership of the buffer is transferred to the resulting SourceBufferHolder.
1939+
// Return a SourceText<char16_t> object holding the script's source text.
1940+
// Ownership of the buffer is transferred to the resulting holder.
19411941

19421942
// If there's no script text, we try to get it from the element
19431943
if (aRequest->mIsInline) {
@@ -1952,12 +1952,12 @@ ScriptLoader::GetScriptSource(JSContext* aCx, ScriptLoadRequest* aRequest)
19521952

19531953
memcpy(chars.get(), inlineData.get(), nbytes);
19541954

1955-
SourceBufferHolder srcBuf;
1955+
SourceText<char16_t> srcBuf;
19561956
if (!srcBuf.init(aCx, std::move(chars), inlineData.Length())) {
19571957
return Nothing();
19581958
}
19591959

1960-
return Some(SourceBufferHolder(std::move(srcBuf)));
1960+
return Some(SourceText<char16_t>(std::move(srcBuf)));
19611961
}
19621962

19631963
size_t length = aRequest->ScriptText().length();
@@ -1967,12 +1967,12 @@ ScriptLoader::GetScriptSource(JSContext* aCx, ScriptLoadRequest* aRequest)
19671967
return Nothing();
19681968
}
19691969

1970-
SourceBufferHolder srcBuf;
1970+
SourceText<char16_t> srcBuf;
19711971
if (!srcBuf.init(aCx, std::move(chars), length)) {
19721972
return Nothing();
19731973
}
19741974

1975-
return Some(SourceBufferHolder(std::move(srcBuf)));
1975+
return Some(SourceText<char16_t>(std::move(srcBuf)));
19761976
}
19771977

19781978
nsresult

dom/script/ScriptLoader.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
class nsIURI;
3333

3434
namespace JS {
35-
class SourceBufferHolder;
35+
36+
template<typename UnitT> class SourceText;
37+
3638
} // namespace JS
3739

3840
namespace mozilla {
@@ -507,8 +509,8 @@ class ScriptLoader final : public nsISupports
507509

508510
void MaybeMoveToLoadedList(ScriptLoadRequest* aRequest);
509511

510-
mozilla::Maybe<JS::SourceBufferHolder> GetScriptSource(JSContext* aCx,
511-
ScriptLoadRequest* aRequest);
512+
mozilla::Maybe<JS::SourceText<char16_t>>
513+
GetScriptSource(JSContext* aCx, ScriptLoadRequest* aRequest);
512514

513515
void SetModuleFetchStarted(ModuleLoadRequest *aRequest);
514516
void SetModuleFetchFinishedAndResumeWaitingRequests(ModuleLoadRequest* aRequest,

dom/workers/ScriptLoader.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include "jsapi.h"
2929
#include "jsfriendapi.h"
3030
#include "js/CompilationAndEvaluation.h"
31-
#include "js/SourceBufferHolder.h"
31+
#include "js/SourceText.h"
3232
#include "nsError.h"
3333
#include "nsContentPolicyUtils.h"
3434
#include "nsContentUtils.h"
@@ -2134,7 +2134,7 @@ ScriptExecutorRunnable::WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate)
21342134
std::swap(dataLength, loadInfo.mScriptTextLength);
21352135
std::swap(data, loadInfo.mScriptTextBuf);
21362136

2137-
JS::SourceBufferHolder srcBuf;
2137+
JS::SourceText<char16_t> srcBuf;
21382138
if (!srcBuf.init(aCx, JS::UniqueTwoByteChars(data), dataLength)) {
21392139
mScriptLoader.mRv.StealExceptionFromJSContext(aCx);
21402140
return true;

dom/workers/WorkerPrivate.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "js/CompilationAndEvaluation.h"
1010
#include "js/LocaleSensitive.h"
1111
#include "js/MemoryMetrics.h"
12-
#include "js/SourceBufferHolder.h"
12+
#include "js/SourceText.h"
1313
#include "MessageEventRunnable.h"
1414
#include "mozilla/ScopeExit.h"
1515
#include "mozilla/StaticPrefs.h"
@@ -4902,9 +4902,9 @@ WorkerPrivate::RunExpiredTimeouts(JSContext* aCx)
49024902

49034903
JS::Rooted<JS::Value> unused(aes.cx());
49044904

4905-
JS::SourceBufferHolder srcBuf;
4905+
JS::SourceText<char16_t> srcBuf;
49064906
if (!srcBuf.init(aes.cx(), script.BeginReading(), script.Length(),
4907-
JS::SourceBufferHolder::NoOwnership) ||
4907+
JS::SourceOwnership::Borrowed) ||
49084908
!JS::Evaluate(aes.cx(), options, srcBuf, &unused))
49094909
{
49104910
if (!JS_IsExceptionPending(aCx)) {

dom/worklet/Worklet.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include "mozilla/dom/ScriptLoader.h"
1818
#include "mozilla/dom/WorkletImpl.h"
1919
#include "js/CompilationAndEvaluation.h"
20-
#include "js/SourceBufferHolder.h"
20+
#include "js/SourceText.h"
2121
#include "nsIInputStreamPump.h"
2222
#include "nsIThreadRetargetableRequest.h"
2323
#include "nsNetUtil.h"
@@ -402,7 +402,7 @@ ExecutionRunnable::RunOnWorkletThread()
402402
JSAutoRealm ar(cx, globalObj);
403403

404404
JS::Rooted<JS::Value> unused(cx);
405-
JS::SourceBufferHolder buffer;
405+
JS::SourceText<char16_t> buffer;
406406
if (!buffer.init(cx, std::move(mScriptBuffer), mScriptLength) ||
407407
!JS::Evaluate(cx, compileOptions, buffer, &unused)) {
408408
ErrorResult error;

dom/xul/XULDocument.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
#include "nsTextNode.h"
9292
#include "nsJSUtils.h"
9393
#include "js/CompilationAndEvaluation.h"
94-
#include "js/SourceBufferHolder.h"
94+
#include "js/SourceText.h"
9595
#include "mozilla/dom/URL.h"
9696
#include "nsIContentPolicy.h"
9797
#include "mozAutoDocUpdate.h"
@@ -1295,7 +1295,7 @@ XULDocument::OnStreamComplete(nsIStreamLoader* aLoader,
12951295
std::swap(unitsLength, mOffThreadCompileStringLength);
12961296

12971297
rv = mCurrentScriptProto->Compile(units, unitsLength,
1298-
JS::SourceBufferHolder::GiveOwnership,
1298+
JS::SourceOwnership::TakeOwnership,
12991299
uri, 1, this, this);
13001300
if (NS_SUCCEEDED(rv) && !mCurrentScriptProto->HasScriptObject()) {
13011301
mOffThreadCompiling = true;

dom/xul/nsXULContentSink.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ XULContentSinkImpl::HandleEndElement(const char16_t *aName)
507507
script->mOutOfLine = false;
508508
if (doc) {
509509
script->Compile(mText, mTextLength,
510-
JS::SourceBufferHolder::NoOwnership, mDocumentURL,
510+
JS::SourceOwnership::Borrowed, mDocumentURL,
511511
script->mLineNo, doc);
512512
}
513513
}

0 commit comments

Comments
 (0)