From 2e4620b5afe29d845fbc0acaee1282ccbccecf91 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Tue, 4 Mar 2025 20:16:54 +0100 Subject: [PATCH] Issue #2692 - Part 6: Don't #include js/SourceBufferHolder.h in jsapi.h. Instead, require users to do so. This is a minor translation-unit size improvement for anyone who never has to use SourceBufferHolder other than by reference. --- dom/base/nsFrameMessageManager.cpp | 1 + dom/base/nsJSUtils.cpp | 1 + dom/script/ScriptLoader.cpp | 1 + dom/workers/ScriptLoader.cpp | 1 + dom/workers/WorkerPrivate.cpp | 1 + dom/worklet/Worklet.cpp | 1 + dom/xul/XULDocument.cpp | 1 + dom/xul/nsXULElement.cpp | 1 + ipc/testshell/XPCShellEnvironment.cpp | 1 + js/src/NamespaceImports.h | 1 - js/src/builtin/Eval.cpp | 2 ++ js/src/frontend/BytecodeCompiler.cpp | 4 ++++ js/src/frontend/BytecodeCompiler.h | 8 ++++---- js/src/jsapi-tests/testJSEvaluateScript.cpp | 1 + js/src/jsapi-tests/testMutedErrors.cpp | 1 + js/src/jsapi-tests/testScriptObject.cpp | 1 + js/src/jsapi.cpp | 2 ++ js/src/jsapi.h | 1 - js/src/jsfun.cpp | 2 ++ js/src/jsscript.cpp | 3 +++ js/src/shell/js.cpp | 5 +++-- js/src/vm/Debugger.cpp | 2 ++ js/src/vm/HelperThreads.cpp | 3 +++ js/src/vm/HelperThreads.h | 1 + js/src/wasm/AsmJS.cpp | 2 ++ js/xpconnect/loader/mozJSComponentLoader.cpp | 1 + js/xpconnect/loader/mozJSSubScriptLoader.cpp | 1 + js/xpconnect/src/Sandbox.cpp | 1 + 28 files changed, 43 insertions(+), 8 deletions(-) diff --git a/dom/base/nsFrameMessageManager.cpp b/dom/base/nsFrameMessageManager.cpp index 88ec9c911f..ffb5709e46 100644 --- a/dom/base/nsFrameMessageManager.cpp +++ b/dom/base/nsFrameMessageManager.cpp @@ -27,6 +27,7 @@ #include "nsIScriptSecurityManager.h" #include "nsIDOMClassInfo.h" #include "xpcpublic.h" +#include "js/SourceBufferHolder.h" #include "mozilla/CycleCollectedJSContext.h" #include "mozilla/IntentionalCrash.h" #include "mozilla/Preferences.h" diff --git a/dom/base/nsJSUtils.cpp b/dom/base/nsJSUtils.cpp index 5182886256..5a1dfc3028 100644 --- a/dom/base/nsJSUtils.cpp +++ b/dom/base/nsJSUtils.cpp @@ -13,6 +13,7 @@ #include "nsJSUtils.h" #include "jsapi.h" #include "jsfriendapi.h" +#include "js/SourceBufferHolder.h" #include "nsIScriptContext.h" #include "nsIScriptGlobalObject.h" #include "nsIXPConnect.h" diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp index 0780601767..b6462a0cee 100644 --- a/dom/script/ScriptLoader.cpp +++ b/dom/script/ScriptLoader.cpp @@ -11,6 +11,7 @@ #include "prsystem.h" #include "jsapi.h" #include "jsfriendapi.h" +#include "js/SourceBufferHolder.h" #include "xpcpublic.h" #include "nsCycleCollectionParticipant.h" #include "nsIContent.h" diff --git a/dom/workers/ScriptLoader.cpp b/dom/workers/ScriptLoader.cpp index c05309dd0a..f6a4943653 100644 --- a/dom/workers/ScriptLoader.cpp +++ b/dom/workers/ScriptLoader.cpp @@ -24,6 +24,7 @@ #include "jsapi.h" #include "jsfriendapi.h" +#include "js/SourceBufferHolder.h" #include "nsError.h" #include "nsContentPolicyUtils.h" #include "nsContentUtils.h" diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index a0206ec776..bb745ba491 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -37,6 +37,7 @@ #include "ImageContainer.h" #include "jsfriendapi.h" #include "js/MemoryMetrics.h" +#include "js/SourceBufferHolder.h" #include "mozilla/Assertions.h" #include "mozilla/Attributes.h" #include "mozilla/ContentEvents.h" diff --git a/dom/worklet/Worklet.cpp b/dom/worklet/Worklet.cpp index 5bfdc9c176..9d3f2f5436 100644 --- a/dom/worklet/Worklet.cpp +++ b/dom/worklet/Worklet.cpp @@ -13,6 +13,7 @@ #include "mozilla/dom/Response.h" #include "mozilla/dom/ScriptLoader.h" #include "mozilla/dom/ScriptSettings.h" +#include "js/SourceBufferHolder.h" #include "nsIInputStreamPump.h" #include "nsIThreadRetargetableRequest.h" #include "nsNetUtil.h" diff --git a/dom/xul/XULDocument.cpp b/dom/xul/XULDocument.cpp index 72a62b6e0f..1c07d144b0 100644 --- a/dom/xul/XULDocument.cpp +++ b/dom/xul/XULDocument.cpp @@ -88,6 +88,7 @@ #include "mozilla/Preferences.h" #include "nsTextNode.h" #include "nsJSUtils.h" +#include "js/SourceBufferHolder.h" #include "mozilla/dom/URL.h" #include "nsIContentPolicy.h" #include "mozAutoDocUpdate.h" diff --git a/dom/xul/nsXULElement.cpp b/dom/xul/nsXULElement.cpp index 961de20ee3..08df34436c 100644 --- a/dom/xul/nsXULElement.cpp +++ b/dom/xul/nsXULElement.cpp @@ -26,6 +26,7 @@ #include "mozilla/EventListenerManager.h" #include "mozilla/EventStateManager.h" #include "mozilla/EventStates.h" +#include "js/SourceBufferHolder.h" #include "nsFocusManager.h" #include "nsHTMLStyleSheet.h" #include "nsNameSpaceManager.h" diff --git a/ipc/testshell/XPCShellEnvironment.cpp b/ipc/testshell/XPCShellEnvironment.cpp index c97be68a52..7a1e03fd90 100644 --- a/ipc/testshell/XPCShellEnvironment.cpp +++ b/ipc/testshell/XPCShellEnvironment.cpp @@ -15,6 +15,7 @@ #include "base/basictypes.h" #include "jsapi.h" +#include "js/SourceBufferHolder.h" #include "xpcpublic.h" diff --git a/js/src/NamespaceImports.h b/js/src/NamespaceImports.h index dd940dc808..ed02054622 100644 --- a/js/src/NamespaceImports.h +++ b/js/src/NamespaceImports.h @@ -113,7 +113,6 @@ using JS::IsAcceptableThis; using JS::NativeImpl; using JS::OwningCompileOptions; using JS::ReadOnlyCompileOptions; -using JS::SourceBufferHolder; using JS::TransitiveCompileOptions; using JS::Rooted; diff --git a/js/src/builtin/Eval.cpp b/js/src/builtin/Eval.cpp index b60330b516..7be704d9bc 100644 --- a/js/src/builtin/Eval.cpp +++ b/js/src/builtin/Eval.cpp @@ -12,6 +12,7 @@ #include "jshashutil.h" #include "frontend/BytecodeCompiler.h" +#include "js/SourceBufferHolder.h" #include "vm/Debugger.h" #include "vm/GlobalObject.h" #include "vm/JSONParser.h" @@ -25,6 +26,7 @@ using mozilla::HashString; using mozilla::RangedPtr; using JS::AutoCheckCannotGC; +using JS::SourceBufferHolder; // We should be able to assert this for *any* fp->environmentChain(). static void diff --git a/js/src/frontend/BytecodeCompiler.cpp b/js/src/frontend/BytecodeCompiler.cpp index cdb386f249..2a2c8e0597 100644 --- a/js/src/frontend/BytecodeCompiler.cpp +++ b/js/src/frontend/BytecodeCompiler.cpp @@ -16,6 +16,7 @@ #include "frontend/FoldConstants.h" #include "frontend/NameFunctions.h" #include "frontend/Parser.h" +#include "js/SourceBufferHolder.h" #include "vm/GlobalObject.h" #include "vm/TraceLogging.h" #include "wasm/AsmJS.h" @@ -27,9 +28,12 @@ using namespace js; using namespace js::frontend; + using mozilla::Maybe; using mozilla::Nothing; +using JS::SourceBufferHolder; + class MOZ_STACK_CLASS AutoCompilationTraceLogger { public: diff --git a/js/src/frontend/BytecodeCompiler.h b/js/src/frontend/BytecodeCompiler.h index 471e9e36d9..f87e260b1a 100644 --- a/js/src/frontend/BytecodeCompiler.h +++ b/js/src/frontend/BytecodeCompiler.h @@ -28,7 +28,7 @@ namespace frontend { JSScript* CompileGlobalScript(ExclusiveContext* cx, LifoAlloc& alloc, ScopeKind scopeKind, const ReadOnlyCompileOptions& options, - SourceBufferHolder& srcBuf, + JS::SourceBufferHolder& srcBuf, SourceCompressionTask* extraSct = nullptr, ScriptSourceObject** sourceObjectOut = nullptr); @@ -36,17 +36,17 @@ JSScript* CompileEvalScript(ExclusiveContext* cx, LifoAlloc& alloc, HandleObject scopeChain, HandleScope enclosingScope, const ReadOnlyCompileOptions& options, - SourceBufferHolder& srcBuf, + JS::SourceBufferHolder& srcBuf, SourceCompressionTask* extraSct = nullptr, ScriptSourceObject** sourceObjectOut = nullptr); ModuleObject* CompileModule(JSContext* cx, const ReadOnlyCompileOptions& options, - SourceBufferHolder& srcBuf); + JS::SourceBufferHolder& srcBuf); ModuleObject* CompileModule(ExclusiveContext* cx, const ReadOnlyCompileOptions& options, - SourceBufferHolder& srcBuf, LifoAlloc& alloc, + JS::SourceBufferHolder& srcBuf, LifoAlloc& alloc, ScriptSourceObject** sourceObjectOut = nullptr); MOZ_MUST_USE bool diff --git a/js/src/jsapi-tests/testJSEvaluateScript.cpp b/js/src/jsapi-tests/testJSEvaluateScript.cpp index 579503a829..e546b38785 100644 --- a/js/src/jsapi-tests/testJSEvaluateScript.cpp +++ b/js/src/jsapi-tests/testJSEvaluateScript.cpp @@ -1,6 +1,7 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +#include "js/SourceBufferHolder.h" #include "jsapi-tests/tests.h" using mozilla::ArrayLength; diff --git a/js/src/jsapi-tests/testMutedErrors.cpp b/js/src/jsapi-tests/testMutedErrors.cpp index da91afb2af..ad49e30c02 100644 --- a/js/src/jsapi-tests/testMutedErrors.cpp +++ b/js/src/jsapi-tests/testMutedErrors.cpp @@ -3,6 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "jsfriendapi.h" +#include "js/SourceBufferHolder.h" #include "jsapi-tests/tests.h" BEGIN_TEST(testMutedErrors) diff --git a/js/src/jsapi-tests/testScriptObject.cpp b/js/src/jsapi-tests/testScriptObject.cpp index 9c865dae11..501268073e 100644 --- a/js/src/jsapi-tests/testScriptObject.cpp +++ b/js/src/jsapi-tests/testScriptObject.cpp @@ -4,6 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "js/SourceBufferHolder.h" #include "jsapi-tests/tests.h" struct ScriptObjectFixture : public JSAPITest { diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index 74d54aae64..2bea8b8be7 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -63,6 +63,7 @@ #include "js/Initialization.h" #include "js/Proxy.h" #include "js/SliceBudget.h" +#include "js/SourceBufferHolder.h" #include "js/StructuredClone.h" #include "js/Utility.h" #include "vm/AsyncFunction.h" @@ -106,6 +107,7 @@ using mozilla::PodZero; using mozilla::Some; using JS::AutoGCRooter; +using JS::SourceBufferHolder; using JS::ToInt32; using JS::ToInteger; using JS::ToUint32; diff --git a/js/src/jsapi.h b/js/src/jsapi.h index ac7610f5f8..cae2297ae4 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -38,7 +38,6 @@ #include "js/Principals.h" #include "js/Realm.h" #include "js/RootingAPI.h" -#include "js/SourceBufferHolder.h" #include "js/Stream.h" #include "js/TracingAPI.h" #include "js/Transcoding.h" diff --git a/js/src/jsfun.cpp b/js/src/jsfun.cpp index ad2e1fcd95..9d2a819ca6 100644 --- a/js/src/jsfun.cpp +++ b/js/src/jsfun.cpp @@ -39,6 +39,7 @@ #include "jit/JitFrameIterator.h" #include "js/CallNonGenericMethod.h" #include "js/Proxy.h" +#include "js/SourceBufferHolder.h" #include "vm/AsyncFunction.h" #include "vm/AsyncIteration.h" #include "vm/Debugger.h" @@ -67,6 +68,7 @@ using mozilla::PodCopy; using mozilla::RangedPtr; using mozilla::Some; +using JS::SourceBufferHolder; static bool fun_enumerate(JSContext* cx, HandleObject obj) { diff --git a/js/src/jsscript.cpp b/js/src/jsscript.cpp index a438f051c9..0fcdb57eb8 100644 --- a/js/src/jsscript.cpp +++ b/js/src/jsscript.cpp @@ -41,6 +41,7 @@ #include "jit/Ion.h" #include "jit/IonCode.h" #include "js/MemoryMetrics.h" +#include "js/SourceBufferHolder.h" #include "js/Utility.h" #include "vm/ArgumentsObject.h" #include "vm/Compression.h" @@ -68,6 +69,8 @@ using mozilla::PodCopy; using mozilla::PodZero; using mozilla::RotateLeft; +using JS::SourceBufferHolder; + template bool js::XDRScriptConst(XDRState* xdr, MutableHandleValue vp) diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index f844913e4d..d4e0a5065e 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -74,6 +74,7 @@ #include "js/Equality.h" // JS::SameValue #include "js/GCAPI.h" #include "js/Initialization.h" +#include "js/SourceBufferHolder.h" #include "js/StructuredClone.h" #include "js/TrackedOptimizationInfo.h" #include "perf/jsperf.h" @@ -4062,8 +4063,8 @@ ParseModule(JSContext* cx, unsigned argc, Value* vp) return false; const char16_t* chars = stableChars.twoByteRange().begin().get(); - SourceBufferHolder srcBuf(chars, scriptContents->length(), - SourceBufferHolder::NoOwnership); + JS::SourceBufferHolder srcBuf(chars, scriptContents->length(), + SourceBufferHolder::NoOwnership); RootedObject module(cx, frontend::CompileModule(cx, options, srcBuf)); if (!module) diff --git a/js/src/vm/Debugger.cpp b/js/src/vm/Debugger.cpp index 574dd1ba5e..e1416a8908 100644 --- a/js/src/vm/Debugger.cpp +++ b/js/src/vm/Debugger.cpp @@ -27,6 +27,7 @@ #include "jit/BaselineJIT.h" #include "js/Date.h" #include "js/GCAPI.h" +#include "js/SourceBufferHolder.h" #include "js/UbiNodeBreadthFirst.h" #include "js/Vector.h" #include "proxy/ScriptedProxyHandler.h" @@ -51,6 +52,7 @@ using namespace js; using JS::dbg::AutoEntryMonitor; using JS::dbg::Builder; using js::frontend::IsIdentifier; +using JS::SourceBufferHolder; using mozilla::ArrayLength; using mozilla::DebugOnly; using mozilla::MakeScopeExit; diff --git a/js/src/vm/HelperThreads.cpp b/js/src/vm/HelperThreads.cpp index 4ce8728ace..488522c987 100644 --- a/js/src/vm/HelperThreads.cpp +++ b/js/src/vm/HelperThreads.cpp @@ -10,6 +10,7 @@ #include "jsnativestack.h" #include "jsnum.h" // For FIX_FPU() +#include "js/SourceBufferHolder.h" #include "builtin/Promise.h" #include "frontend/BytecodeCompiler.h" @@ -33,6 +34,8 @@ using mozilla::DebugOnly; using mozilla::Unused; using mozilla::TimeDuration; +using JS::SourceBufferHolder; + namespace js { GlobalHelperThreadState* gHelperThreadState = nullptr; diff --git a/js/src/vm/HelperThreads.h b/js/src/vm/HelperThreads.h index 51a18a8060..48c638e34e 100644 --- a/js/src/vm/HelperThreads.h +++ b/js/src/vm/HelperThreads.h @@ -21,6 +21,7 @@ #include "frontend/TokenStream.h" #include "jit/Ion.h" +#include "js/SourceBufferHolder.h" #include "threading/ConditionVariable.h" #include "vm/MutexIDs.h" diff --git a/js/src/wasm/AsmJS.cpp b/js/src/wasm/AsmJS.cpp index 69788a852b..e7c956d972 100644 --- a/js/src/wasm/AsmJS.cpp +++ b/js/src/wasm/AsmJS.cpp @@ -33,6 +33,7 @@ #include "frontend/Parser.h" #include "gc/Policy.h" #include "js/MemoryMetrics.h" +#include "js/SourceBufferHolder.h" #include "vm/SelfHosting.h" #include "vm/StringBuffer.h" #include "vm/Time.h" @@ -67,6 +68,7 @@ using mozilla::PodZero; using mozilla::PositiveInfinity; using JS::AsmJSOption; using JS::GenericNaN; +using JS::SourceBufferHolder; /*****************************************************************************/ diff --git a/js/xpconnect/loader/mozJSComponentLoader.cpp b/js/xpconnect/loader/mozJSComponentLoader.cpp index 5b9e09a0a1..ddb7491466 100644 --- a/js/xpconnect/loader/mozJSComponentLoader.cpp +++ b/js/xpconnect/loader/mozJSComponentLoader.cpp @@ -17,6 +17,7 @@ #endif #include "jsapi.h" +#include "js/SourceBufferHolder.h" #include "nsCOMPtr.h" #include "nsAutoPtr.h" #include "nsIComponentManager.h" diff --git a/js/xpconnect/loader/mozJSSubScriptLoader.cpp b/js/xpconnect/loader/mozJSSubScriptLoader.cpp index 8844a1d929..fc3b496f73 100644 --- a/js/xpconnect/loader/mozJSSubScriptLoader.cpp +++ b/js/xpconnect/loader/mozJSSubScriptLoader.cpp @@ -19,6 +19,7 @@ #include "jsapi.h" #include "jsfriendapi.h" +#include "js/SourceBufferHolder.h" #include "nsJSPrincipals.h" #include "xpcprivate.h" // For xpc::OptionsBase #include "jswrapper.h" diff --git a/js/xpconnect/src/Sandbox.cpp b/js/xpconnect/src/Sandbox.cpp index 6ce1104179..6808e655a5 100644 --- a/js/xpconnect/src/Sandbox.cpp +++ b/js/xpconnect/src/Sandbox.cpp @@ -10,6 +10,7 @@ #include "AccessCheck.h" #include "jsfriendapi.h" #include "js/Proxy.h" +#include "js/SourceBufferHolder.h" #include "js/StructuredClone.h" #include "nsContentUtils.h" #include "nsGlobalWindow.h"