Title: [287327] trunk/Source/WebCore
Revision
287327
Author
da...@apple.com
Date
2021-12-21 13:56:30 -0800 (Tue, 21 Dec 2021)

Log Message

ScriptState.h/cpp is a remnant of _javascript_ engine abstraction that can be removed
https://bugs.webkit.org/show_bug.cgi?id=234548

Reviewed by Yusuke Suzuki.

ScriptState.h/cpp is file left over from when we had a layer to abstract
_javascript_ binding and usage in WebCore so it could work with both _javascript_Core
and Google's V8 engine. We haven't needed that for years, and stripping away some
of the layers might help us make code more readable and perhaps even notice ways
to make it more efficient. For now, this patch removes the functions from
ScriptState.h/cpp and moves them to more suitable places, simplifying in the process.

Also begin to just call global objects "global object", and not "script state".

* Headers.cmake: Removed ScriptState.h.

* Modules/indexeddb/IDBObjectStore.cpp: Removed include of ScriptState.h.
* Modules/indexeddb/IDBTransaction.cpp: Ditto.

* Sources.txt: Removed ScriptState.cpp.
* WebCore.xcodeproj/project.pbxproj: Removed ScriptState.h and .cpp.
Also allowed the script to sort the file.

* bindings/js/JSDOMWindowCustom.cpp:
(WebCore::mainWorldGlobalObject): Renamed the mainWorldExecState function and
moved it here from ScriptState.cpp.
* bindings/js/JSDOMWindowCustom.h: Tweaked formatting of the header. Added the
mainWorldGlobalObject function.

* bindings/js/JSExecState.cpp: Removed include of ScriptState.h.
(WebCore::JSExecState::didLeaveScriptContext): Call scriptExecutionContext.
(WebCore::executionContext): Renamed the scriptExecutionContextFromExecState
function and moved it here from ScriptState.cpp.
* bindings/js/JSExecState.h: Added the executionContext function.

* bindings/js/JSNodeCustom.cpp: Removed include of ScriptState.h, added include
of JSDOMWindowCustom.h.
(WebCore::willCreatePossiblyOrphanedTreeByRemovalSlowCase): Call mainWorldGlobalObject.

* bindings/js/JSNodeCustom.h: Changed willCreatePossiblyOrphanedTreeByRemoval
functions to take a Node& instead of a never-null Node*.

* bindings/js/JSWindowProxy.h: Tweaked formatting a bit.

* bindings/js/ScriptState.cpp: Removed.
* bindings/js/ScriptState.h: Removed.

* bindings/js/SerializedScriptValue.cpp: Removed include of ScriptState.h.
(WebCore::wrapCryptoKey): Update for name change of executionContext function.
(WebCore::unwrapCryptoKey): Ditto.
(WebCore::CloneDeserializer::readFile): Ditto.
(WebCore::CloneDeserializer::readOffscreenCanvas): Ditto.
(WebCore::CloneDeserializer::readRTCDataChannel): Ditto.
(WebCore::CloneDeserializer::readImageBitmap): Ditto.
(WebCore::CloneDeserializer::readTerminal): Ditto.

* dom/ContainerNode.cpp:
(WebCore::ContainerNode::removeAllChildrenWithScriptAssertion):
Pass reference to willCreatePossiblyOrphanedTreeByRemoval.
(WebCore::ContainerNode::removeNodeWithScriptAssertion): Ditto.

* dom/Document.cpp: Removed include of ScriptState.h, added include
of JSDOMWindowCustom.h.
(WebCore::Document::didLogMessage): Use mainWorldGlobalObject.

* dom/ScriptExecutionContext.cpp: Removed include of ScriptState.h.
(WebCore::ScriptExecutionContext::globalObject): Use the
ScriptController directly instead of through helper functions.

* inspector/InspectorFrontendAPIDispatcher.cpp: Removed include of ScriptState.h.
* inspector/InspectorFrontendClientLocal.cpp: Ditto.

* inspector/InspectorFrontendHost.cpp: Removed include of ScriptState.h.
(WebCore::InspectorFrontendHost::addSelfToGlobalObjectInWorld):
Use the ScriptController directly instead of through a helper function.
(WebCore::InspectorFrontendHost::showContextMenu): Ditto.

* inspector/InspectorInstrumentation.cpp:
(WebCore::InspectorInstrumentation::frameWindowDiscardedImpl): Do
the null check here instead of in frameWindowDiscarded.

* inspector/WebInjectedScriptManager.cpp: Removed include of ScriptState.h.
(WebCore::WebInjectedScriptManager::discardInjectedScriptsFor):
Reworked logic to use executionContext instead of domWindowFromExecState.

* inspector/agents/InspectorCanvasAgent.cpp: Removed include of ScriptState.h.

* inspector/agents/InspectorDOMAgent.cpp: Removed include of ScriptState.h.
(WebCore::InspectorDOMAgent::focusNode): Use std::exchange here in the
idiomatic "take and null a value" case here. Use mainWorldGlobalObject.
(WebCore::InspectorDOMAgent::buildObjectForEventListener): Use
ScriptController directly instead of through a helper function.
(WebCore::InspectorDOMAgent::resolveNode): Use mainWorldGlobalObject.

* inspector/agents/InspectorIndexedDBAgent.cpp: Removed include of
ScriptState.h and added include of JSDOMWindowCustom.h.
(WebCore::InspectorIndexedDBAgent::requestData): Use mainWorldGlobalObject.

* inspector/agents/InspectorNetworkAgent.cpp: Removed include of
ScriptState.h and added include of JSDOMWindowCustom.h.
(WebCore::InspectorNetworkAgent::resolveWebSocket): Use mainWorldGlobalObject.

* inspector/agents/InspectorTimelineAgent.cpp: Removed include of ScriptState.h.
(WebCore::frame): Added. Helper function to get from a global object to a frame.
Calls executionContext and gets to the frame from there.
(WebCore::InspectorTimelineAgent::startFromConsole): Use frame.
(WebCore::InspectorTimelineAgent::breakpointActionProbe): Ditto.

* inspector/agents/WebConsoleAgent.cpp: Removed include of ScriptState.h.
(WebCore::WebConsoleAgent::frameWindowDiscarded): Take a reference instead of
a pointer that must not be null. Use executionContext instead of
domWindowFromExecState.

* inspector/agents/WebConsoleAgent.h: Removed unneeded includes. Removed
unneeded WTF_MAKE_NONCOPYABLE (base class is already not copyable) and
WTF_MAKE_FAST_ALLOCATED (class is an abstract base class and never allocated).
Made constructor protected. Changed the DOMWindow argument to
frameWindowDiscarded to a reference instead of a pointer that must not be null.

* inspector/agents/page/PageAuditAgent.cpp: Removed include of
ScriptState.h and added include of JSDOMWindowCustom.h.
(WebCore::PageAuditAgent::injectedScriptForEval): Use mainWorldGlobalObject.

* inspector/agents/page/PageDebuggerAgent.cpp: Removed include of
ScriptState.h and added include of JSDOMWindowCustom.h.
(WebCore::PageDebuggerAgent::injectedScriptForEval): Use mainWorldGlobalObject.

* inspector/agents/page/PageNetworkAgent.cpp: Removed include of ScriptState.h.

* inspector/agents/page/PageRuntimeAgent.cpp: Removed include of
ScriptState.h and added include of JSDOMWindowCustom.h.
(WebCore::PageRuntimeAgent::frameNavigated): Use mainWorldGlobalObject.
(WebCore::PageRuntimeAgent::injectedScriptForEval): Ditto.
(WebCore::PageRuntimeAgent::reportExecutionContextCreation): Ditto.
Also use Page::forEachFrame instead of a hand-written loop.

* inspector/agents/worker/WorkerAuditAgent.cpp: Removed include of ScriptState.h.
(WebCore::WorkerAuditAgent::injectedScriptForEval): Use ScriptController directly
instead of through a helper function.

* inspector/agents/worker/WorkerDebuggerAgent.cpp: Removed include of ScriptState.h.
(WebCore::WorkerDebuggerAgent::injectedScriptForEval): Use ScriptController directly
instead of through a helper function.

* inspector/agents/worker/WorkerRuntimeAgent.cpp: Removed include of ScriptState.h.
(WebCore::WorkerRuntimeAgent::injectedScriptForEval): Use ScriptController directly
instead of through a helper function.

Modified Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (287326 => 287327)


--- trunk/Source/WebCore/ChangeLog	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/ChangeLog	2021-12-21 21:56:30 UTC (rev 287327)
@@ -1,3 +1,153 @@
+2021-12-21  Darin Adler  <da...@apple.com>
+
+        ScriptState.h/cpp is a remnant of _javascript_ engine abstraction that can be removed
+        https://bugs.webkit.org/show_bug.cgi?id=234548
+
+        Reviewed by Yusuke Suzuki.
+
+        ScriptState.h/cpp is file left over from when we had a layer to abstract
+        _javascript_ binding and usage in WebCore so it could work with both _javascript_Core
+        and Google's V8 engine. We haven't needed that for years, and stripping away some
+        of the layers might help us make code more readable and perhaps even notice ways
+        to make it more efficient. For now, this patch removes the functions from
+        ScriptState.h/cpp and moves them to more suitable places, simplifying in the process.
+
+        Also begin to just call global objects "global object", and not "script state".
+
+        * Headers.cmake: Removed ScriptState.h.
+
+        * Modules/indexeddb/IDBObjectStore.cpp: Removed include of ScriptState.h.
+        * Modules/indexeddb/IDBTransaction.cpp: Ditto.
+
+        * Sources.txt: Removed ScriptState.cpp.
+        * WebCore.xcodeproj/project.pbxproj: Removed ScriptState.h and .cpp.
+        Also allowed the script to sort the file.
+
+        * bindings/js/JSDOMWindowCustom.cpp:
+        (WebCore::mainWorldGlobalObject): Renamed the mainWorldExecState function and
+        moved it here from ScriptState.cpp.
+        * bindings/js/JSDOMWindowCustom.h: Tweaked formatting of the header. Added the
+        mainWorldGlobalObject function.
+
+        * bindings/js/JSExecState.cpp: Removed include of ScriptState.h.
+        (WebCore::JSExecState::didLeaveScriptContext): Call scriptExecutionContext.
+        (WebCore::executionContext): Renamed the scriptExecutionContextFromExecState
+        function and moved it here from ScriptState.cpp.
+        * bindings/js/JSExecState.h: Added the executionContext function.
+
+        * bindings/js/JSNodeCustom.cpp: Removed include of ScriptState.h, added include
+        of JSDOMWindowCustom.h.
+        (WebCore::willCreatePossiblyOrphanedTreeByRemovalSlowCase): Call mainWorldGlobalObject.
+
+        * bindings/js/JSNodeCustom.h: Changed willCreatePossiblyOrphanedTreeByRemoval
+        functions to take a Node& instead of a never-null Node*.
+
+        * bindings/js/JSWindowProxy.h: Tweaked formatting a bit.
+
+        * bindings/js/ScriptState.cpp: Removed.
+        * bindings/js/ScriptState.h: Removed.
+
+        * bindings/js/SerializedScriptValue.cpp: Removed include of ScriptState.h.
+        (WebCore::wrapCryptoKey): Update for name change of executionContext function.
+        (WebCore::unwrapCryptoKey): Ditto.
+        (WebCore::CloneDeserializer::readFile): Ditto.
+        (WebCore::CloneDeserializer::readOffscreenCanvas): Ditto.
+        (WebCore::CloneDeserializer::readRTCDataChannel): Ditto.
+        (WebCore::CloneDeserializer::readImageBitmap): Ditto.
+        (WebCore::CloneDeserializer::readTerminal): Ditto.
+
+        * dom/ContainerNode.cpp:
+        (WebCore::ContainerNode::removeAllChildrenWithScriptAssertion):
+        Pass reference to willCreatePossiblyOrphanedTreeByRemoval.
+        (WebCore::ContainerNode::removeNodeWithScriptAssertion): Ditto.
+
+        * dom/Document.cpp: Removed include of ScriptState.h, added include
+        of JSDOMWindowCustom.h.
+        (WebCore::Document::didLogMessage): Use mainWorldGlobalObject.
+
+        * dom/ScriptExecutionContext.cpp: Removed include of ScriptState.h.
+        (WebCore::ScriptExecutionContext::globalObject): Use the
+        ScriptController directly instead of through helper functions.
+
+        * inspector/InspectorFrontendAPIDispatcher.cpp: Removed include of ScriptState.h.
+        * inspector/InspectorFrontendClientLocal.cpp: Ditto.
+
+        * inspector/InspectorFrontendHost.cpp: Removed include of ScriptState.h.
+        (WebCore::InspectorFrontendHost::addSelfToGlobalObjectInWorld):
+        Use the ScriptController directly instead of through a helper function.
+        (WebCore::InspectorFrontendHost::showContextMenu): Ditto.
+
+        * inspector/InspectorInstrumentation.cpp:
+        (WebCore::InspectorInstrumentation::frameWindowDiscardedImpl): Do
+        the null check here instead of in frameWindowDiscarded.
+
+        * inspector/WebInjectedScriptManager.cpp: Removed include of ScriptState.h.
+        (WebCore::WebInjectedScriptManager::discardInjectedScriptsFor):
+        Reworked logic to use executionContext instead of domWindowFromExecState.
+
+        * inspector/agents/InspectorCanvasAgent.cpp: Removed include of ScriptState.h.
+
+        * inspector/agents/InspectorDOMAgent.cpp: Removed include of ScriptState.h.
+        (WebCore::InspectorDOMAgent::focusNode): Use std::exchange here in the
+        idiomatic "take and null a value" case here. Use mainWorldGlobalObject.
+        (WebCore::InspectorDOMAgent::buildObjectForEventListener): Use
+        ScriptController directly instead of through a helper function.
+        (WebCore::InspectorDOMAgent::resolveNode): Use mainWorldGlobalObject.
+
+        * inspector/agents/InspectorIndexedDBAgent.cpp: Removed include of
+        ScriptState.h and added include of JSDOMWindowCustom.h.
+        (WebCore::InspectorIndexedDBAgent::requestData): Use mainWorldGlobalObject.
+
+        * inspector/agents/InspectorNetworkAgent.cpp: Removed include of
+        ScriptState.h and added include of JSDOMWindowCustom.h.
+        (WebCore::InspectorNetworkAgent::resolveWebSocket): Use mainWorldGlobalObject.
+
+        * inspector/agents/InspectorTimelineAgent.cpp: Removed include of ScriptState.h.
+        (WebCore::frame): Added. Helper function to get from a global object to a frame.
+        Calls executionContext and gets to the frame from there.
+        (WebCore::InspectorTimelineAgent::startFromConsole): Use frame.
+        (WebCore::InspectorTimelineAgent::breakpointActionProbe): Ditto.
+
+        * inspector/agents/WebConsoleAgent.cpp: Removed include of ScriptState.h.
+        (WebCore::WebConsoleAgent::frameWindowDiscarded): Take a reference instead of
+        a pointer that must not be null. Use executionContext instead of
+        domWindowFromExecState.
+
+        * inspector/agents/WebConsoleAgent.h: Removed unneeded includes. Removed
+        unneeded WTF_MAKE_NONCOPYABLE (base class is already not copyable) and
+        WTF_MAKE_FAST_ALLOCATED (class is an abstract base class and never allocated).
+        Made constructor protected. Changed the DOMWindow argument to
+        frameWindowDiscarded to a reference instead of a pointer that must not be null.
+
+        * inspector/agents/page/PageAuditAgent.cpp: Removed include of
+        ScriptState.h and added include of JSDOMWindowCustom.h.
+        (WebCore::PageAuditAgent::injectedScriptForEval): Use mainWorldGlobalObject.
+
+        * inspector/agents/page/PageDebuggerAgent.cpp: Removed include of
+        ScriptState.h and added include of JSDOMWindowCustom.h.
+        (WebCore::PageDebuggerAgent::injectedScriptForEval): Use mainWorldGlobalObject.
+
+        * inspector/agents/page/PageNetworkAgent.cpp: Removed include of ScriptState.h.
+
+        * inspector/agents/page/PageRuntimeAgent.cpp: Removed include of
+        ScriptState.h and added include of JSDOMWindowCustom.h.
+        (WebCore::PageRuntimeAgent::frameNavigated): Use mainWorldGlobalObject.
+        (WebCore::PageRuntimeAgent::injectedScriptForEval): Ditto.
+        (WebCore::PageRuntimeAgent::reportExecutionContextCreation): Ditto.
+        Also use Page::forEachFrame instead of a hand-written loop.
+
+        * inspector/agents/worker/WorkerAuditAgent.cpp: Removed include of ScriptState.h.
+        (WebCore::WorkerAuditAgent::injectedScriptForEval): Use ScriptController directly
+        instead of through a helper function.
+
+        * inspector/agents/worker/WorkerDebuggerAgent.cpp: Removed include of ScriptState.h.
+        (WebCore::WorkerDebuggerAgent::injectedScriptForEval): Use ScriptController directly
+        instead of through a helper function.
+
+        * inspector/agents/worker/WorkerRuntimeAgent.cpp: Removed include of ScriptState.h.
+        (WebCore::WorkerRuntimeAgent::injectedScriptForEval): Use ScriptController directly
+        instead of through a helper function.
+
 2021-12-21  Michael Saboff  <msab...@apple.com>
 
         Fix symlinks for alternate root framework locations

Modified: trunk/Source/WebCore/Headers.cmake (287326 => 287327)


--- trunk/Source/WebCore/Headers.cmake	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/Headers.cmake	2021-12-21 21:56:30 UTC (rev 287327)
@@ -465,7 +465,6 @@
     bindings/js/RunJavaScriptParameters.h
     bindings/js/ScriptCachedFrameData.h
     bindings/js/ScriptController.h
-    bindings/js/ScriptState.h
     bindings/js/ScriptWrappable.h
     bindings/js/ScriptWrappableInlines.h
     bindings/js/SerializedScriptValue.h

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBObjectStore.cpp (287326 => 287327)


--- trunk/Source/WebCore/Modules/indexeddb/IDBObjectStore.cpp	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBObjectStore.cpp	2021-12-21 21:56:30 UTC (rev 287327)
@@ -42,7 +42,6 @@
 #include "Logging.h"
 #include "Page.h"
 #include "ScriptExecutionContext.h"
-#include "ScriptState.h"
 #include "SerializedScriptValue.h"
 #include <_javascript_Core/CatchScope.h>
 #include <_javascript_Core/HeapInlines.h>

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.cpp (287326 => 287327)


--- trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.cpp	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.cpp	2021-12-21 21:56:30 UTC (rev 287327)
@@ -50,7 +50,6 @@
 #include "JSDOMWindowBase.h"
 #include "Logging.h"
 #include "ScriptExecutionContext.h"
-#include "ScriptState.h"
 #include "SerializedScriptValue.h"
 #include "TransactionOperation.h"
 #include <wtf/CompletionHandler.h>

Modified: trunk/Source/WebCore/Sources.txt (287326 => 287327)


--- trunk/Source/WebCore/Sources.txt	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/Sources.txt	2021-12-21 21:56:30 UTC (rev 287327)
@@ -632,7 +632,6 @@
 bindings/js/ScriptCachedFrameData.cpp
 bindings/js/ScriptController.cpp
 bindings/js/ScriptModuleLoader.cpp
-bindings/js/ScriptState.cpp
 bindings/js/ScriptWrappable.cpp
 bindings/js/SerializedScriptValue.cpp
 bindings/js/StructuredClone.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (287326 => 287327)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-12-21 21:56:30 UTC (rev 287327)
@@ -1200,7 +1200,6 @@
 		41C14BC926DF79D700685BF5 /* MDNSRegisterError.h in Headers */ = {isa = PBXBuildFile; fileRef = 41C14BC826DF79D600685BF5 /* MDNSRegisterError.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		41C3B8A12649B1E0004ED4DE /* AudioMediaStreamTrackRendererInternalUnit.h in Headers */ = {isa = PBXBuildFile; fileRef = 41C3B89F2649B1B7004ED4DE /* AudioMediaStreamTrackRendererInternalUnit.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		41C3B8A22649B1E5004ED4DE /* AudioMediaStreamTrackRendererUnit.h in Headers */ = {isa = PBXBuildFile; fileRef = 41C3B89B2649B1B6004ED4DE /* AudioMediaStreamTrackRendererUnit.h */; settings = {ATTRIBUTES = (Private, ); }; };
-		41C760B10EDE03D300C1655F /* ScriptState.h in Headers */ = {isa = PBXBuildFile; fileRef = 41C760B00EDE03D300C1655F /* ScriptState.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		41CB840125CAB7B30010E2B1 /* RealtimeIncomingVideoSourceCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = 41CB840025CAB7B00010E2B1 /* RealtimeIncomingVideoSourceCocoa.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		41CB840225CAB81E0010E2B1 /* RealtimeIncomingVideoSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CDD833A1E4324BB00621E92 /* RealtimeIncomingVideoSource.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		41D015CA0F4B5C71004A662F /* ContentType.h in Headers */ = {isa = PBXBuildFile; fileRef = 41D015C80F4B5C71004A662F /* ContentType.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -8525,7 +8524,6 @@
 		41209E94216EA69A00A73A12 /* RTCCertificate.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RTCCertificate.cpp; sourceTree = "<group>"; };
 		41209E95216EC34E00A73A12 /* LibWebRTCCertificateGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LibWebRTCCertificateGenerator.h; path = libwebrtc/LibWebRTCCertificateGenerator.h; sourceTree = "<group>"; };
 		41209E96216EC34F00A73A12 /* LibWebRTCCertificateGenerator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LibWebRTCCertificateGenerator.cpp; path = libwebrtc/LibWebRTCCertificateGenerator.cpp; sourceTree = "<group>"; };
-		4127D5360F8AAB1D00E424F5 /* ScriptState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScriptState.cpp; sourceTree = "<group>"; };
 		4129C9801F5861C7009D7403 /* ReadableStreamSink.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReadableStreamSink.h; sourceTree = "<group>"; };
 		4129C9811F5861C7009D7403 /* ReadableStreamSink.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ReadableStreamSink.idl; sourceTree = "<group>"; };
 		4129C9871F58662D009D7403 /* ReadableStreamSink.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ReadableStreamSink.cpp; sourceTree = "<group>"; };
@@ -8853,7 +8851,6 @@
 		41C3B89E2649B1B7004ED4DE /* AudioMediaStreamTrackRendererInternalUnit.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = AudioMediaStreamTrackRendererInternalUnit.cpp; sourceTree = "<group>"; };
 		41C3B89F2649B1B7004ED4DE /* AudioMediaStreamTrackRendererInternalUnit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AudioMediaStreamTrackRendererInternalUnit.h; sourceTree = "<group>"; };
 		41C3B8A02649B1B7004ED4DE /* AudioMediaStreamTrackRendererUnit.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = AudioMediaStreamTrackRendererUnit.cpp; sourceTree = "<group>"; };
-		41C760B00EDE03D300C1655F /* ScriptState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptState.h; sourceTree = "<group>"; };
 		41C7E1051E6A54360027B4DE /* CanvasCaptureMediaStreamTrack.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CanvasCaptureMediaStreamTrack.cpp; sourceTree = "<group>"; };
 		41C7E1061E6A54360027B4DE /* CanvasCaptureMediaStreamTrack.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CanvasCaptureMediaStreamTrack.h; sourceTree = "<group>"; };
 		41C7E1081E6AA37C0027B4DE /* CanvasCaptureMediaStreamTrack.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CanvasCaptureMediaStreamTrack.idl; sourceTree = "<group>"; };
@@ -29215,8 +29212,6 @@
 				E38838941BAD145F00D62EE3 /* ScriptModuleLoader.cpp */,
 				E38838951BAD145F00D62EE3 /* ScriptModuleLoader.h */,
 				934CC1090EDB223900A658F2 /* ScriptSourceCode.h */,
-				4127D5360F8AAB1D00E424F5 /* ScriptState.cpp */,
-				41C760B00EDE03D300C1655F /* ScriptState.h */,
 				228C284410D82500009D0D0E /* ScriptWrappable.h */,
 				1400D7A717136EA70077CE05 /* ScriptWrappableInlines.h */,
 				A75E497510752ACB00C9B896 /* SerializedScriptValue.cpp */,
@@ -36919,7 +36914,6 @@
 				FD31603612B0267600C1A359 /* ScriptProcessorNode.h in Headers */,
 				8A413AE01207BBA50082016E /* ScriptRunner.h in Headers */,
 				934CC10A0EDB223900A658F2 /* ScriptSourceCode.h in Headers */,
-				41C760B10EDE03D300C1655F /* ScriptState.h in Headers */,
 				228C284510D82500009D0D0E /* ScriptWrappable.h in Headers */,
 				1400D7A817136EA70077CE05 /* ScriptWrappableInlines.h in Headers */,
 				BC8AE34F12EA096A00EB3AE6 /* ScrollableArea.h in Headers */,

Modified: trunk/Source/WebCore/bindings/js/JSDOMWindowCustom.cpp (287326 => 287327)


--- trunk/Source/WebCore/bindings/js/JSDOMWindowCustom.cpp	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/bindings/js/JSDOMWindowCustom.cpp	2021-12-21 21:56:30 UTC (rev 287327)
@@ -637,4 +637,12 @@
     createDataProperty(&lexicalGlobalObject, Identifier::fromString(lexicalGlobalObject.vm(), "openDatabase"), value, shouldThrow);
 }
 
+JSDOMWindow& mainWorldGlobalObject(Frame& frame)
+{
+    // FIXME: What guarantees the result of jsWindowProxy() is non-null?
+    // FIXME: What guarantees the result of window() is non-null?
+    // FIXME: What guarantees the result of window() a JSDOMWindow?
+    return *jsCast<JSDOMWindow*>(frame.windowProxy().jsWindowProxy(mainThreadNormalWorld())->window());
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/bindings/js/JSDOMWindowCustom.h (287326 => 287327)


--- trunk/Source/WebCore/bindings/js/JSDOMWindowCustom.h	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/bindings/js/JSDOMWindowCustom.h	2021-12-21 21:56:30 UTC (rev 287327)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (C) 2008, 2009 Apple Inc. All rights reseved.
+ *  Copyright (C) 2008-2021 Apple Inc. All rights reseved.
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Lesser General Public
@@ -25,6 +25,20 @@
 class AbstractDOMWindow;
 class AbstractFrame;
 
+JSDOMWindow* asJSDOMWindow(JSC::JSGlobalObject*);
+const JSDOMWindow* asJSDOMWindow(const JSC::JSGlobalObject*);
+
+enum class DOMWindowType : bool { Local, Remote };
+template<DOMWindowType> bool jsDOMWindowGetOwnPropertySlotRestrictedAccess(JSDOMGlobalObject*, AbstractDOMWindow&, JSC::JSGlobalObject&, JSC::PropertyName, JSC::PropertySlot&, const String&);
+
+enum class CrossOriginObject : bool { Window, Location };
+template<CrossOriginObject> void addCrossOriginOwnPropertyNames(JSC::JSGlobalObject&, JSC::PropertyNameArray&);
+
+bool handleCommonCrossOriginProperties(JSC::JSObject* thisObject, JSC::VM&, JSC::PropertyName, JSC::PropertySlot&);
+
+JSDOMWindow& mainWorldGlobalObject(Frame&);
+JSDOMWindow* mainWorldGlobalObject(Frame*);
+
 inline JSDOMWindow* asJSDOMWindow(JSC::JSGlobalObject* globalObject)
 {
     return JSC::jsCast<JSDOMWindow*>(globalObject);
@@ -35,15 +49,9 @@
     return static_cast<const JSDOMWindow*>(globalObject);
 }
 
-enum class DOMWindowType { Local, Remote };
+inline JSDOMWindow* mainWorldGlobalObject(Frame* frame)
+{
+    return frame ? &mainWorldGlobalObject(*frame) : nullptr;
+}
 
-template <DOMWindowType windowType>
-bool jsDOMWindowGetOwnPropertySlotRestrictedAccess(JSDOMGlobalObject*, AbstractDOMWindow&, JSC::JSGlobalObject&, JSC::PropertyName, JSC::PropertySlot&, const String&);
-
-enum class CrossOriginObject { Window, Location };
-
-template <CrossOriginObject objectType>
-void addCrossOriginOwnPropertyNames(JSC::JSGlobalObject&, JSC::PropertyNameArray&);
-bool handleCommonCrossOriginProperties(JSC::JSObject* thisObject, JSC::VM&, JSC::PropertyName, JSC::PropertySlot&);
-
 } // namespace WebCore

Modified: trunk/Source/WebCore/bindings/js/JSExecState.cpp (287326 => 287327)


--- trunk/Source/WebCore/bindings/js/JSExecState.cpp	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/bindings/js/JSExecState.cpp	2021-12-21 21:56:30 UTC (rev 287327)
@@ -29,7 +29,6 @@
 #include "EventLoop.h"
 #include "RejectedPromiseTracker.h"
 #include "ScriptExecutionContext.h"
-#include "ScriptState.h"
 #include "WorkerGlobalScope.h"
 
 namespace WebCore {
@@ -36,7 +35,7 @@
 
 void JSExecState::didLeaveScriptContext(JSC::JSGlobalObject* lexicalGlobalObject)
 {
-    ScriptExecutionContext* context = scriptExecutionContextFromExecState(lexicalGlobalObject);
+    auto context = executionContext(lexicalGlobalObject);
     if (!context)
         return;
     context->eventLoop().performMicrotaskCheckpoint();
@@ -53,4 +52,11 @@
     return JSExecState::evaluate(lexicalGlobalObject, source, thisValue, returnedException);
 }
 
+ScriptExecutionContext* executionContext(JSC::JSGlobalObject* globalObject)
+{
+    if (!globalObject || !globalObject->inherits<JSDOMGlobalObject>(globalObject->vm()))
+        return nullptr;
+    return jsCast<JSDOMGlobalObject*>(globalObject)->scriptExecutionContext();
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/bindings/js/JSExecState.h (287326 => 287327)


--- trunk/Source/WebCore/bindings/js/JSExecState.h	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/bindings/js/JSExecState.h	2021-12-21 21:56:30 UTC (rev 287327)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2010 Google Inc. All rights reserved.
- * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2016-2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -47,25 +47,25 @@
     static JSC::JSGlobalObject* currentState()
     {
         return threadGlobalData().currentState();
-    };
+    }
     
     static JSC::JSValue call(JSC::JSGlobalObject* lexicalGlobalObject, JSC::JSValue functionObject, const JSC::CallData& callData, JSC::JSValue thisValue, const JSC::ArgList& args, NakedPtr<JSC::Exception>& returnedException)
     {
         JSExecState currentState(lexicalGlobalObject);
         return JSC::call(lexicalGlobalObject, functionObject, callData, thisValue, args, returnedException);
-    };
+    }
 
     static JSC::JSValue evaluate(JSC::JSGlobalObject* lexicalGlobalObject, const JSC::SourceCode& source, JSC::JSValue thisValue, NakedPtr<JSC::Exception>& returnedException)
     {
         JSExecState currentState(lexicalGlobalObject);
         return JSC::evaluate(lexicalGlobalObject, source, thisValue, returnedException);
-    };
+    }
 
     static JSC::JSValue evaluate(JSC::JSGlobalObject* lexicalGlobalObject, const JSC::SourceCode& source, JSC::JSValue thisValue = JSC::JSValue())
     {
         NakedPtr<JSC::Exception> unused;
         return evaluate(lexicalGlobalObject, source, thisValue, unused);
-    };
+    }
 
     static JSC::JSValue profiledCall(JSC::JSGlobalObject* lexicalGlobalObject, JSC::ProfilingReason reason, JSC::JSValue functionObject, const JSC::CallData& callData, JSC::JSValue thisValue, const JSC::ArgList& args, NakedPtr<JSC::Exception>& returnedException)
     {
@@ -185,4 +185,6 @@
 JSC::JSValue functionCallHandlerFromAnyThread(JSC::JSGlobalObject*, JSC::JSValue functionObject, const JSC::CallData&, JSC::JSValue thisValue, const JSC::ArgList& args, NakedPtr<JSC::Exception>& returnedException);
 JSC::JSValue evaluateHandlerFromAnyThread(JSC::JSGlobalObject*, const JSC::SourceCode&, JSC::JSValue thisValue, NakedPtr<JSC::Exception>& returnedException);
 
+ScriptExecutionContext* executionContext(JSC::JSGlobalObject*);
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/bindings/js/JSNodeCustom.cpp (287326 => 287327)


--- trunk/Source/WebCore/bindings/js/JSNodeCustom.cpp	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/bindings/js/JSNodeCustom.cpp	2021-12-21 21:56:30 UTC (rev 287327)
@@ -45,6 +45,7 @@
 #include "JSCDATASection.h"
 #include "JSComment.h"
 #include "JSDOMBinding.h"
+#include "JSDOMWindowCustom.h"
 #include "JSDocument.h"
 #include "JSDocumentFragment.h"
 #include "JSDocumentType.h"
@@ -61,7 +62,6 @@
 #include "ProcessingInstruction.h"
 #include "RegisteredEventListener.h"
 #include "SVGElement.h"
-#include "ScriptState.h"
 #include "ShadowRoot.h"
 #include "GCReachableRef.h"
 #include "StyleSheet.h"
@@ -68,10 +68,9 @@
 #include "StyledElement.h"
 #include "Text.h"
 
+namespace WebCore {
 
-namespace WebCore {
 using namespace JSC;
-
 using namespace HTMLNames;
 
 static inline bool isReachableFromDOM(Node* node, AbstractSlotVisitor& visitor, const char** reason)
@@ -212,14 +211,15 @@
     return globalObject->world().wrappers().get(&node);
 }
 
-void willCreatePossiblyOrphanedTreeByRemovalSlowCase(Node* root)
+void willCreatePossiblyOrphanedTreeByRemovalSlowCase(Node& root)
 {
-    JSC::JSGlobalObject* lexicalGlobalObject = mainWorldExecState(root->document().frame());
-    if (!lexicalGlobalObject)
+    auto frame = root.document().frame();
+    if (!frame)
         return;
 
-    JSLockHolder lock(lexicalGlobalObject);
-    toJS(lexicalGlobalObject, static_cast<JSDOMGlobalObject*>(lexicalGlobalObject), *root);
+    auto& globalObject = mainWorldGlobalObject(*frame);
+    JSLockHolder lock(&globalObject);
+    toJS(&globalObject, &globalObject, root);
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/bindings/js/JSNodeCustom.h (287326 => 287327)


--- trunk/Source/WebCore/bindings/js/JSNodeCustom.h	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/bindings/js/JSNodeCustom.h	2021-12-21 21:56:30 UTC (rev 287327)
@@ -69,16 +69,11 @@
 // root. In the _javascript_ DOM, a node tree survives as long as there is a
 // reference to any node in the tree. To model the _javascript_ DOM on top of
 // the C++ DOM, we ensure that the root of every tree has a _javascript_ wrapper.
-void willCreatePossiblyOrphanedTreeByRemovalSlowCase(Node* root);
-inline void willCreatePossiblyOrphanedTreeByRemoval(Node* root)
+void willCreatePossiblyOrphanedTreeByRemovalSlowCase(Node& root);
+inline void willCreatePossiblyOrphanedTreeByRemoval(Node& root)
 {
-    if (root->wrapper())
-        return;
-
-    if (!root->hasChildNodes())
-        return;
-
-    willCreatePossiblyOrphanedTreeByRemovalSlowCase(root);
+    if (!root.wrapper() && root.hasChildNodes())
+        willCreatePossiblyOrphanedTreeByRemovalSlowCase(root);
 }
 
 inline void* root(Node* node)

Modified: trunk/Source/WebCore/bindings/js/JSWindowProxy.h (287326 => 287327)


--- trunk/Source/WebCore/bindings/js/JSWindowProxy.h	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/bindings/js/JSWindowProxy.h	2021-12-21 21:56:30 UTC (rev 287327)
@@ -48,11 +48,7 @@
     static constexpr bool needsDestruction = true;
     static void destroy(JSCell*);
 
-    template<typename CellType, JSC::SubspaceAccess>
-    static JSC::IsoSubspace* subspaceFor(JSC::VM& vm)
-    {
-        return subspaceForImpl(vm);
-    }
+    template<typename CellType, JSC::SubspaceAccess> static JSC::IsoSubspace* subspaceFor(JSC::VM& vm) { return subspaceForImpl(vm); }
 
     static JSWindowProxy& create(JSC::VM&, AbstractDOMWindow&, DOMWrapperWorld&);
 
@@ -59,6 +55,7 @@
     DECLARE_INFO;
 
     JSDOMGlobalObject* window() const { return static_cast<JSDOMGlobalObject*>(target()); }
+
     void setWindow(JSC::VM&, JSDOMGlobalObject&);
     void setWindow(AbstractDOMWindow&);
 

Deleted: trunk/Source/WebCore/bindings/js/ScriptState.cpp (287326 => 287327)


--- trunk/Source/WebCore/bindings/js/ScriptState.cpp	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/bindings/js/ScriptState.cpp	2021-12-21 21:56:30 UTC (rev 287327)
@@ -1,107 +0,0 @@
-/*
- * Copyright (C) 2009, 2011 Google Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- *     * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- *     * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "ScriptState.h"
-
-#include "Document.h"
-#include "Frame.h"
-#include "JSDOMWindowBase.h"
-#include "JSWorkerGlobalScope.h"
-#include "JSWorkletGlobalScope.h"
-#include "Node.h"
-#include "Page.h"
-#include "ScriptController.h"
-#include "WorkerOrWorkletGlobalScope.h"
-#include "WorkerOrWorkletScriptController.h"
-#include "WorkletGlobalScope.h"
-#include <_javascript_Core/CallFrame.h>
-#include <_javascript_Core/JSGlobalObject.h>
-#include <_javascript_Core/StrongInlines.h>
-
-namespace WebCore {
-
-DOMWindow* domWindowFromExecState(JSC::JSGlobalObject* lexicalGlobalObject)
-{
-    JSC::JSGlobalObject* globalObject = lexicalGlobalObject;
-    JSC::VM& vm = globalObject->vm();
-    if (!globalObject->inherits<JSDOMWindowBase>(vm))
-        return nullptr;
-    return &JSC::jsCast<JSDOMWindowBase*>(globalObject)->wrapped();
-}
-
-Frame* frameFromExecState(JSC::JSGlobalObject* lexicalGlobalObject)
-{
-    ScriptExecutionContext* context = scriptExecutionContextFromExecState(lexicalGlobalObject);
-    Document* document = is<Document>(context) ? downcast<Document>(context) : nullptr;
-    return document ? document->frame() : nullptr;
-}
-
-ScriptExecutionContext* scriptExecutionContextFromExecState(JSC::JSGlobalObject* lexicalGlobalObject)
-{
-    JSC::JSGlobalObject* globalObject = lexicalGlobalObject;
-    JSC::VM& vm = globalObject->vm();
-    if (!globalObject->inherits<JSDOMGlobalObject>(vm))
-        return nullptr;
-    return JSC::jsCast<JSDOMGlobalObject*>(globalObject)->scriptExecutionContext();
-}
-
-JSC::JSGlobalObject* mainWorldExecState(Frame* frame)
-{
-    if (!frame)
-        return nullptr;
-    return frame->windowProxy().jsWindowProxy(mainThreadNormalWorld())->window();
-}
-
-JSC::JSGlobalObject* globalObject(DOMWrapperWorld& world, Node* node)
-{
-    if (!node)
-        return nullptr;
-    Frame* frame = node->document().frame();
-    if (!frame)
-        return nullptr;
-    if (!frame->script().canExecuteScripts(NotAboutToExecuteScript))
-        return nullptr;
-    return frame->script().globalObject(world);
-}
-
-JSC::JSGlobalObject* globalObject(DOMWrapperWorld& world, Frame* frame)
-{
-    return frame ? frame->script().globalObject(world) : nullptr;
-}
-
-JSC::JSGlobalObject* globalObject(WorkerOrWorkletGlobalScope& workerOrWorkletGlobalScope)
-{
-    if (auto* scriptController = workerOrWorkletGlobalScope.script())
-        return scriptController->globalScopeWrapper();
-    return nullptr;
-}
-
-}

Deleted: trunk/Source/WebCore/bindings/js/ScriptState.h (287326 => 287327)


--- trunk/Source/WebCore/bindings/js/ScriptState.h	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/bindings/js/ScriptState.h	2021-12-21 21:56:30 UTC (rev 287327)
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 2008, 2011 Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- *     * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- *     * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-namespace JSC {
-class CallFrame;
-class JSGlobalObject;
-}
-
-namespace WebCore {
-
-class DOMWindow;
-class DOMWrapperWorld;
-class Frame;
-class Node;
-class ScriptExecutionContext;
-class WorkerOrWorkletGlobalScope;
-
-DOMWindow* domWindowFromExecState(JSC::JSGlobalObject*);
-Frame* frameFromExecState(JSC::JSGlobalObject*);
-ScriptExecutionContext* scriptExecutionContextFromExecState(JSC::JSGlobalObject*);
-
-JSC::JSGlobalObject* mainWorldExecState(Frame*);
-
-JSC::JSGlobalObject* globalObject(DOMWrapperWorld&, Node*);
-WEBCORE_EXPORT JSC::JSGlobalObject* globalObject(DOMWrapperWorld&, Frame*);
-JSC::JSGlobalObject* globalObject(WorkerOrWorkletGlobalScope&);
-
-} // namespace WebCore

Modified: trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp (287326 => 287327)


--- trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp	2021-12-21 21:56:30 UTC (rev 287327)
@@ -56,15 +56,8 @@
 #include "JSRTCCertificate.h"
 #include "JSRTCDataChannel.h"
 #include "ScriptExecutionContext.h"
-#include "ScriptState.h"
 #include "SharedBuffer.h"
 #include "WebCoreJSClientData.h"
-#if PLATFORM(COCOA)
-#include <CoreFoundation/CoreFoundation.h>
-#endif
-#if USE(CG)
-#include <CoreGraphics/CoreGraphics.h>
-#endif
 #include <_javascript_Core/APICast.h>
 #include <_javascript_Core/BigIntObject.h>
 #include <_javascript_Core/BooleanObject.h>
@@ -101,6 +94,14 @@
 #include <wtf/Vector.h>
 #include <wtf/threads/BinarySemaphore.h>
 
+#if USE(CG)
+#include <CoreGraphics/CoreGraphics.h>
+#endif
+
+#if PLATFORM(COCOA)
+#include <CoreFoundation/CoreFoundation.h>
+#endif
+
 #if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS)
 #include "JSOffscreenCanvas.h"
 #include "OffscreenCanvas.h"
@@ -113,6 +114,7 @@
 #endif
 
 namespace WebCore {
+
 using namespace JSC;
 
 DEFINE_ALLOCATOR_WITH_HEAP_IDENTIFIER(SerializedScriptValue);
@@ -556,18 +558,14 @@
 #if ENABLE(WEB_CRYPTO)
 static bool wrapCryptoKey(JSGlobalObject* lexicalGlobalObject, const Vector<uint8_t>& key, Vector<uint8_t>& wrappedKey)
 {
-    ScriptExecutionContext* scriptExecutionContext = scriptExecutionContextFromExecState(lexicalGlobalObject);
-    if (!scriptExecutionContext)
-        return false;
-    return scriptExecutionContext->wrapCryptoKey(key, wrappedKey);
+    auto context = executionContext(lexicalGlobalObject);
+    return context && context->wrapCryptoKey(key, wrappedKey);
 }
 
 static bool unwrapCryptoKey(JSGlobalObject* lexicalGlobalObject, const Vector<uint8_t>& wrappedKey, Vector<uint8_t>& key)
 {
-    ScriptExecutionContext* scriptExecutionContext = scriptExecutionContextFromExecState(lexicalGlobalObject);
-    if (!scriptExecutionContext)
-        return false;
-    return scriptExecutionContext->unwrapCryptoKey(wrappedKey, key);
+    auto context = executionContext(lexicalGlobalObject);
+    return context && context->unwrapCryptoKey(wrappedKey, key);
 }
 #endif
 
@@ -958,7 +956,7 @@
         auto& vm = m_lexicalGlobalObject->vm();
         auto* globalObject = m_lexicalGlobalObject;
         if (globalObject->inherits<JSDOMGlobalObject>(vm))
-            return toJS(m_lexicalGlobalObject, jsCast<JSDOMGlobalObject*>(globalObject), &arrayBuffer);
+            return toJS(globalObject, jsCast<JSDOMGlobalObject*>(globalObject), &arrayBuffer);
 
         if (auto* buffer = arrayBuffer.m_wrapper.get())
             return buffer;
@@ -2566,7 +2564,7 @@
         if (!m_canCreateDOMObject)
             return true;
 
-        file = File::deserialize(scriptExecutionContextFromExecState(m_lexicalGlobalObject), filePath, URL(URL(), url->string()), type->string(), name->string(), optionalLastModified);
+        file = File::deserialize(executionContext(m_lexicalGlobalObject), filePath, URL(URL(), url->string()), type->string(), name->string(), optionalLastModified);
         return true;
     }
 
@@ -3296,7 +3294,7 @@
         }
 
         if (!m_offscreenCanvases[index])
-            m_offscreenCanvases[index] = OffscreenCanvas::create(*scriptExecutionContextFromExecState(m_lexicalGlobalObject), WTFMove(m_detachedOffscreenCanvases.at(index)));
+            m_offscreenCanvases[index] = OffscreenCanvas::create(*executionContext(m_lexicalGlobalObject), WTFMove(m_detachedOffscreenCanvases.at(index)));
 
         auto offscreenCanvas = m_offscreenCanvases[index].get();
         return getJSValue(offscreenCanvas);
@@ -3360,7 +3358,7 @@
 
         if (!m_rtcDataChannels[index]) {
             auto detachedChannel = WTFMove(m_detachedRTCDataChannels.at(index));
-            m_rtcDataChannels[index] = RTCDataChannel::create(*scriptExecutionContextFromExecState(m_lexicalGlobalObject), detachedChannel->identifier, WTFMove(detachedChannel->label), WTFMove(detachedChannel->options), detachedChannel->state);
+            m_rtcDataChannels[index] = RTCDataChannel::create(*executionContext(m_lexicalGlobalObject), detachedChannel->identifier, WTFMove(detachedChannel->label), WTFMove(detachedChannel->options), detachedChannel->state);
         }
 
         return getJSValue(m_rtcDataChannels[index].get());
@@ -3385,7 +3383,7 @@
         auto imageDataSize = logicalSize;
         imageDataSize.scale(resolutionScale);
 
-        auto buffer = ImageBitmap::createImageBuffer(*scriptExecutionContextFromExecState(m_lexicalGlobalObject), logicalSize, RenderingMode::Unaccelerated, colorSpace, resolutionScale);
+        auto buffer = ImageBitmap::createImageBuffer(*executionContext(m_lexicalGlobalObject), logicalSize, RenderingMode::Unaccelerated, colorSpace, resolutionScale);
         if (!buffer) {
             fail();
             return JSValue();
@@ -3651,7 +3649,7 @@
                 return JSValue();
             if (!m_canCreateDOMObject)
                 return jsNull();
-            return getJSValue(Blob::deserialize(scriptExecutionContextFromExecState(m_lexicalGlobalObject), URL(URL(), url->string()), type->string(), size, blobFilePathForBlobURL(url->string())).get());
+            return getJSValue(Blob::deserialize(executionContext(m_lexicalGlobalObject), URL(URL(), url->string()), type->string(), size, blobFilePathForBlobURL(url->string())).get());
         }
         case StringTag: {
             CachedStringRef cachedString;

Modified: trunk/Source/WebCore/dom/ContainerNode.cpp (287326 => 287327)


--- trunk/Source/WebCore/dom/ContainerNode.cpp	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/dom/ContainerNode.cpp	2021-12-21 21:56:30 UTC (rev 287327)
@@ -128,7 +128,7 @@
             removeBetween(nullptr, child->nextSibling(), *child);
             auto subtreeObservability = notifyChildNodeRemoved(*this, *child);
             if (source == ChildChange::Source::API && subtreeObservability == RemovedSubtreeObservability::MaybeObservableByRefPtr)
-                willCreatePossiblyOrphanedTreeByRemoval(child.get());
+                willCreatePossiblyOrphanedTreeByRemoval(*child);
         }
     }
 
@@ -210,7 +210,7 @@
     }
 
     if (source == ChildChange::Source::API && subtreeObservability == RemovedSubtreeObservability::MaybeObservableByRefPtr)
-        willCreatePossiblyOrphanedTreeByRemoval(&childToRemove);
+        willCreatePossiblyOrphanedTreeByRemoval(childToRemove);
 
     ASSERT_WITH_SECURITY_IMPLICATION(!document().selection().selection().isOrphan());
 

Modified: trunk/Source/WebCore/dom/Document.cpp (287326 => 287327)


--- trunk/Source/WebCore/dom/Document.cpp	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/dom/Document.cpp	2021-12-21 21:56:30 UTC (rev 287327)
@@ -133,6 +133,7 @@
 #include "InspectorInstrumentation.h"
 #include "IntersectionObserver.h"
 #include "JSCustomElementInterface.h"
+#include "JSDOMWindowCustom.h"
 #include "JSLazyEventListener.h"
 #include "KeyboardEvent.h"
 #include "KeyframeEffect.h"
@@ -210,7 +211,6 @@
 #include "ScriptModuleLoader.h"
 #include "ScriptRunner.h"
 #include "ScriptSourceCode.h"
-#include "ScriptState.h"
 #include "ScriptedAnimationController.h"
 #include "ScrollAnimator.h"
 #include "ScrollbarTheme.h"
@@ -8716,8 +8716,8 @@
             return;
 
         auto messageLevel = messageLevelFromWTFLogLevel(level);
-        auto message = makeUnique<Inspector::ConsoleMessage>(messageSource, MessageType::Log, messageLevel, WTFMove(logMessages), mainWorldExecState(weakThis->frame()));
-
+        auto* globalObject = mainWorldGlobalObject(weakThis->frame());
+        auto message = makeUnique<Inspector::ConsoleMessage>(messageSource, MessageType::Log, messageLevel, WTFMove(logMessages), globalObject);
         weakThis->addConsoleMessage(WTFMove(message));
     });
 }

Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.cpp (287326 => 287327)


--- trunk/Source/WebCore/dom/ScriptExecutionContext.cpp	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.cpp	2021-12-21 21:56:30 UTC (rev 287327)
@@ -56,7 +56,6 @@
 #include "SWContextManager.h"
 #include "ScriptController.h"
 #include "ScriptDisallowedScope.h"
-#include "ScriptState.h"
 #include "ServiceWorker.h"
 #include "ServiceWorkerGlobalScope.h"
 #include "ServiceWorkerProvider.h"
@@ -543,11 +542,15 @@
 
 JSC::JSGlobalObject* ScriptExecutionContext::globalObject()
 {
-    if (is<Document>(*this))
-        return WebCore::globalObject(mainThreadNormalWorld(), downcast<Document>(*this).frame());
+    if (is<Document>(*this)) {
+        auto frame = downcast<Document>(*this).frame();
+        return frame ? frame->script().globalObject(mainThreadNormalWorld()) : nullptr;
+    }
 
-    if (is<WorkerOrWorkletGlobalScope>(*this))
-        return WebCore::globalObject(downcast<WorkerOrWorkletGlobalScope>(*this));
+    if (is<WorkerOrWorkletGlobalScope>(*this)) {
+        auto script = downcast<WorkerOrWorkletGlobalScope>(*this).script();
+        return script ? script->globalScopeWrapper() : nullptr;
+    }
 
     ASSERT_NOT_REACHED();
     return nullptr;

Modified: trunk/Source/WebCore/inspector/InspectorFrontendAPIDispatcher.cpp (287326 => 287327)


--- trunk/Source/WebCore/inspector/InspectorFrontendAPIDispatcher.cpp	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/inspector/InspectorFrontendAPIDispatcher.cpp	2021-12-21 21:56:30 UTC (rev 287327)
@@ -33,7 +33,6 @@
 #include "ScriptController.h"
 #include "ScriptDisallowedScope.h"
 #include "ScriptSourceCode.h"
-#include "ScriptState.h"
 #include <_javascript_Core/FrameTracers.h>
 #include <_javascript_Core/JSPromise.h>
 #include <wtf/RunLoop.h>

Modified: trunk/Source/WebCore/inspector/InspectorFrontendClientLocal.cpp (287326 => 287327)


--- trunk/Source/WebCore/inspector/InspectorFrontendClientLocal.cpp	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/inspector/InspectorFrontendClientLocal.cpp	2021-12-21 21:56:30 UTC (rev 287327)
@@ -48,7 +48,6 @@
 #include "Page.h"
 #include "ScriptController.h"
 #include "ScriptSourceCode.h"
-#include "ScriptState.h"
 #include "Settings.h"
 #include "Timer.h"
 #include "UserGestureIndicator.h"

Modified: trunk/Source/WebCore/inspector/InspectorFrontendHost.cpp (287326 => 287327)


--- trunk/Source/WebCore/inspector/InspectorFrontendHost.cpp	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/inspector/InspectorFrontendHost.cpp	2021-12-21 21:56:30 UTC (rev 287327)
@@ -56,7 +56,6 @@
 #include "Page.h"
 #include "PagePasteboardContext.h"
 #include "Pasteboard.h"
-#include "ScriptState.h"
 #include "Settings.h"
 #include "SystemSoundManager.h"
 #include "UserGestureIndicator.h"
@@ -160,15 +159,15 @@
 
 void InspectorFrontendHost::addSelfToGlobalObjectInWorld(DOMWrapperWorld& world)
 {
-    auto& lexicalGlobalObject = *globalObject(world, m_frontendPage ? &m_frontendPage->mainFrame() : nullptr);
-    auto& vm = lexicalGlobalObject.vm();
+    // FIXME: What guarantees m_frontendPage is non-null?
+    // FIXME: What guarantees globalObject's return value is non-null?
+    auto& globalObject = *m_frontendPage->mainFrame().script().globalObject(world);
+    auto& vm = globalObject.vm();
     JSC::JSLockHolder lock(vm);
     auto scope = DECLARE_CATCH_SCOPE(vm);
-
-    auto& globalObject = *JSC::jsCast<JSDOMGlobalObject*>(&lexicalGlobalObject);
-    globalObject.putDirect(vm, JSC::Identifier::fromString(vm, "InspectorFrontendHost"), toJS<IDLInterface<InspectorFrontendHost>>(lexicalGlobalObject, globalObject, *this));
+    globalObject.putDirect(vm, JSC::Identifier::fromString(vm, "InspectorFrontendHost"), toJS<IDLInterface<InspectorFrontendHost>>(globalObject, globalObject, *this));
     if (UNLIKELY(scope.exception()))
-        reportException(&lexicalGlobalObject, scope.exception());
+        reportException(&globalObject, scope.exception());
 }
 
 void InspectorFrontendHost::loaded()
@@ -503,19 +502,20 @@
 void InspectorFrontendHost::showContextMenu(Event& event, Vector<ContextMenuItem>&& items)
 {
 #if ENABLE(CONTEXT_MENUS)
+    // FIXME: What guarantees m_frontendPage is non-null?
+    // FIXME: What guarantees globalObject's return value is non-null?
     ASSERT(m_frontendPage);
-
-    auto& lexicalGlobalObject = *globalObject(debuggerWorld(), &m_frontendPage->mainFrame());
-    auto& vm = lexicalGlobalObject.vm();
-    auto value = lexicalGlobalObject.get(&lexicalGlobalObject, JSC::Identifier::fromString(vm, "InspectorFrontendAPI"));
+    auto& globalObject = *m_frontendPage->mainFrame().script().globalObject(debuggerWorld());
+    auto& vm = globalObject.vm();
+    auto value = globalObject.get(&globalObject, JSC::Identifier::fromString(vm, "InspectorFrontendAPI"));
     ASSERT(value);
     ASSERT(value.isObject());
     auto* frontendAPIObject = asObject(value);
-    
+
     ContextMenu menu;
     populateContextMenu(WTFMove(items), menu);
 
-    auto menuProvider = FrontendMenuProvider::create(this, { &lexicalGlobalObject, frontendAPIObject }, menu.items());
+    auto menuProvider = FrontendMenuProvider::create(this, { &globalObject, frontendAPIObject }, menu.items());
     m_menuProvider = menuProvider.ptr();
     m_frontendPage->contextMenuController().showContextMenu(event, menuProvider);
 #else

Modified: trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp (287326 => 287327)


--- trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp	2021-12-21 21:56:30 UTC (rev 287327)
@@ -228,8 +228,11 @@
     if (LIKELY(!instrumentingAgents.inspectorEnvironment().developerExtrasEnabled()))
         return;
 
+    if (!window)
+        return;
+
     if (auto* consoleAgent = instrumentingAgents.webConsoleAgent())
-        consoleAgent->frameWindowDiscarded(window);
+        consoleAgent->frameWindowDiscarded(*window);
 }
 
 void InspectorInstrumentation::mediaQueryResultChangedImpl(InstrumentingAgents& instrumentingAgents)

Modified: trunk/Source/WebCore/inspector/WebInjectedScriptManager.cpp (287326 => 287327)


--- trunk/Source/WebCore/inspector/WebInjectedScriptManager.cpp	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/inspector/WebInjectedScriptManager.cpp	2021-12-21 21:56:30 UTC (rev 287327)
@@ -27,9 +27,7 @@
 #include "WebInjectedScriptManager.h"
 
 #include "CommandLineAPIModule.h"
-#include "ScriptState.h"
 
-
 namespace WebCore {
 
 using namespace Inspector;
@@ -69,33 +67,21 @@
     CommandLineAPIModule::injectIfNeeded(this, injectedScript);
 }
 
-void WebInjectedScriptManager::discardInjectedScriptsFor(DOMWindow* window)
+void WebInjectedScriptManager::discardInjectedScriptsFor(DOMWindow& window)
 {
     if (m_scriptStateToId.isEmpty())
         return;
 
-    Vector<long> idsToRemove;
-    for (const auto& it : m_idToInjectedScript) {
-        JSC::JSGlobalObject* lexicalGlobalObject = it.value.globalObject();
-        if (window != domWindowFromExecState(lexicalGlobalObject))
-            continue;
-        m_scriptStateToId.remove(lexicalGlobalObject);
-        idsToRemove.append(it.key);
-    }
+    auto* document = window.document();
+    if (!document)
+        return;
 
-    for (auto& id : idsToRemove)
-        m_idToInjectedScript.remove(id);
-
-    // Now remove script states that have id but no injected script.
-    Vector<JSC::JSGlobalObject*> scriptStatesToRemove;
-    for (const auto& it : m_scriptStateToId) {
-        JSC::JSGlobalObject* lexicalGlobalObject = it.key;
-        if (window == domWindowFromExecState(lexicalGlobalObject))
-            scriptStatesToRemove.append(lexicalGlobalObject);
-    }
-
-    for (auto& lexicalGlobalObject : scriptStatesToRemove)
-        m_scriptStateToId.remove(lexicalGlobalObject);
+    m_idToInjectedScript.removeIf([document](auto& entry) {
+        return executionContext(entry.value.globalObject()) == document;
+    });
+    m_scriptStateToId.removeIf([document](auto& entry) {
+        return executionContext(entry.key) == document;
+    });
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/inspector/WebInjectedScriptManager.h (287326 => 287327)


--- trunk/Source/WebCore/inspector/WebInjectedScriptManager.h	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/inspector/WebInjectedScriptManager.h	2021-12-21 21:56:30 UTC (rev 287327)
@@ -46,7 +46,7 @@
     void disconnect() override;
     void discardInjectedScripts() override;
 
-    void discardInjectedScriptsFor(DOMWindow*);
+    void discardInjectedScriptsFor(DOMWindow&);
 
 private:
     void didCreateInjectedScript(const Inspector::InjectedScript&) override;

Modified: trunk/Source/WebCore/inspector/agents/InspectorApplicationCacheAgent.cpp (287326 => 287327)


--- trunk/Source/WebCore/inspector/agents/InspectorApplicationCacheAgent.cpp	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/inspector/agents/InspectorApplicationCacheAgent.cpp	2021-12-21 21:56:30 UTC (rev 287327)
@@ -114,21 +114,21 @@
         return makeUnexpected("Page domain must be enabled"_s);
 
     auto result = JSON::ArrayOf<Protocol::ApplicationCache::FrameWithManifest>::create();
-    for (Frame* frame = &m_inspectedPage.mainFrame(); frame; frame = frame->tree().traverseNext()) {
-        auto* documentLoader = frame->loader().documentLoader();
+    m_inspectedPage.forEachFrame([&](Frame& frame) {
+        auto* documentLoader = frame.loader().documentLoader();
         if (!documentLoader)
-            continue;
+            return;
 
         auto& host = documentLoader->applicationCacheHost();
         String manifestURL = host.applicationCacheInfo().manifest.string();
         if (!manifestURL.isEmpty()) {
             result->addItem(Protocol::ApplicationCache::FrameWithManifest::create()
-                .setFrameId(pageAgent->frameId(frame))
+                .setFrameId(pageAgent->frameId(&frame))
                 .setManifestURL(manifestURL)
                 .setStatus(static_cast<int>(host.status()))
                 .release());
         }
-    }
+    });
     return result;
 }
 

Modified: trunk/Source/WebCore/inspector/agents/InspectorCanvasAgent.cpp (287326 => 287327)


--- trunk/Source/WebCore/inspector/agents/InspectorCanvasAgent.cpp	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/inspector/agents/InspectorCanvasAgent.cpp	2021-12-21 21:56:30 UTC (rev 287327)
@@ -50,7 +50,6 @@
 #include "JSExecState.h"
 #include "OffscreenCanvas.h"
 #include "Path2D.h"
-#include "ScriptState.h"
 #include "StringAdaptors.h"
 #include "WebGL2RenderingContext.h"
 #include "WebGLBuffer.h"

Modified: trunk/Source/WebCore/inspector/agents/InspectorDOMAgent.cpp (287326 => 287327)


--- trunk/Source/WebCore/inspector/agents/InspectorDOMAgent.cpp	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/inspector/agents/InspectorDOMAgent.cpp	2021-12-21 21:56:30 UTC (rev 287327)
@@ -85,6 +85,7 @@
 #include "InstrumentingAgents.h"
 #include "IntRect.h"
 #include "JSDOMBindingSecurity.h"
+#include "JSDOMWindowCustom.h"
 #include "JSEventListener.h"
 #include "JSNode.h"
 #include "MutationEvent.h"
@@ -96,7 +97,7 @@
 #include "RenderGrid.h"
 #include "RenderStyle.h"
 #include "RenderStyleConstants.h"
-#include "ScriptState.h"
+#include "ScriptController.h"
 #include "SelectorChecker.h"
 #include "ShadowRoot.h"
 #include "StaticNodeList.h"
@@ -1163,20 +1164,17 @@
         return;
 
     ASSERT(m_nodeToFocus);
-
-    RefPtr<Node> node = m_nodeToFocus.get();
-    m_nodeToFocus = nullptr;
-
-    Frame* frame = node->document().frame();
+    auto node = std::exchange(m_nodeToFocus, nullptr);
+    auto frame = node->document().frame();
     if (!frame)
         return;
 
-    JSC::JSGlobalObject* scriptState = mainWorldExecState(frame);
-    InjectedScript injectedScript = m_injectedScriptManager.injectedScriptFor(scriptState);
+    auto& globalObject = mainWorldGlobalObject(*frame);
+    auto injectedScript = m_injectedScriptManager.injectedScriptFor(&globalObject);
     if (injectedScript.hasNoValue())
         return;
 
-    injectedScript.inspectObject(nodeAsScriptValue(*scriptState, node.get()));
+    injectedScript.inspectObject(nodeAsScriptValue(globalObject, node.get()));
 }
 
 void InspectorDOMAgent::mouseDidMoveOverElement(const HitTestResult& result, unsigned)
@@ -1892,7 +1890,11 @@
 
         if (document) {
             handlerObject = scriptListener.ensureJSFunction(*document);
-            globalObject = WebCore::globalObject(scriptListener.isolatedWorld(), document);
+            if (auto frame = document->frame()) {
+                // FIXME: Why do we need the canExecuteScripts check here?
+                if (frame->script().canExecuteScripts(NotAboutToExecuteScript))
+                    globalObject = frame->script().globalObject(scriptListener.isolatedWorld());
+            }
         }
 
         if (handlerObject && globalObject) {
@@ -2846,12 +2848,12 @@
     if (!frame)
         return nullptr;
 
-    auto& state = *mainWorldExecState(frame);
-    auto injectedScript = m_injectedScriptManager.injectedScriptFor(&state);
+    auto& globalObject = mainWorldGlobalObject(*frame);
+    auto injectedScript = m_injectedScriptManager.injectedScriptFor(&globalObject);
     if (injectedScript.hasNoValue())
         return nullptr;
 
-    return injectedScript.wrapObject(nodeAsScriptValue(state, node), objectGroup);
+    return injectedScript.wrapObject(nodeAsScriptValue(globalObject, node), objectGroup);
 }
 
 Node* InspectorDOMAgent::scriptValueAsNode(JSC::JSValue value)

Modified: trunk/Source/WebCore/inspector/agents/InspectorIndexedDBAgent.cpp (287326 => 287327)


--- trunk/Source/WebCore/inspector/agents/InspectorIndexedDBAgent.cpp	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/inspector/agents/InspectorIndexedDBAgent.cpp	2021-12-21 21:56:30 UTC (rev 287327)
@@ -56,7 +56,7 @@
 #include "IDBTransaction.h"
 #include "InspectorPageAgent.h"
 #include "InstrumentingAgents.h"
-#include "ScriptState.h"
+#include "JSDOMWindowCustom.h"
 #include "SecurityOrigin.h"
 #include "WindowOrWorkerGlobalScopeIndexedDatabase.h"
 #include <_javascript_Core/HeapInlines.h>
@@ -617,14 +617,17 @@
     if (!getDocumentAndIDBFactoryFromFrameOrSendFailure(frame, document, idbFactory, callback))
         return;
 
-    InjectedScript injectedScript = m_injectedScriptManager.injectedScriptFor(mainWorldExecState(frame));
-    RefPtr<IDBKeyRange> idbKeyRange = keyRange ? idbKeyRangeFromKeyRange(*keyRange) : nullptr;
-    if (keyRange && !idbKeyRange) {
-        callback->sendFailure("Could not parse key range."_s);
-        return;
+    RefPtr<IDBKeyRange> idbKeyRange;
+    if (keyRange) {
+        idbKeyRange = idbKeyRangeFromKeyRange(*keyRange);
+        if (!idbKeyRange) {
+            callback->sendFailure("Could not parse key range."_s);
+            return;
+        }
     }
 
-    Ref<DataLoader> dataLoader = DataLoader::create(document, WTFMove(callback), injectedScript, objectStoreName, indexName, WTFMove(idbKeyRange), skipCount, pageSize);
+    auto injectedScript = m_injectedScriptManager.injectedScriptFor(&mainWorldGlobalObject(*frame));
+    auto dataLoader = DataLoader::create(document, WTFMove(callback), injectedScript, objectStoreName, indexName, WTFMove(idbKeyRange), skipCount, pageSize);
     dataLoader->start(idbFactory, &document->securityOrigin(), databaseName);
 }
 

Modified: trunk/Source/WebCore/inspector/agents/InspectorNetworkAgent.cpp (287326 => 287327)


--- trunk/Source/WebCore/inspector/agents/InspectorNetworkAgent.cpp	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/inspector/agents/InspectorNetworkAgent.cpp	2021-12-21 21:56:30 UTC (rev 287327)
@@ -51,6 +51,7 @@
 #include "InspectorDOMAgent.h"
 #include "InspectorTimelineAgent.h"
 #include "InstrumentingAgents.h"
+#include "JSDOMWindowCustom.h"
 #include "JSExecState.h"
 #include "JSWebSocket.h"
 #include "LoaderStrategy.h"
@@ -64,7 +65,6 @@
 #include "ResourceLoader.h"
 #include "ResourceRequest.h"
 #include "ResourceResponse.h"
-#include "ScriptState.h"
 #include "ScriptableDocumentParser.h"
 #include "SubresourceLoader.h"
 #include "TextResourceDecoder.h"
@@ -1043,11 +1043,11 @@
     if (!frame)
         return makeUnexpected("Missing frame of web socket for given requestId"_s);
 
-    auto& state = *mainWorldExecState(frame);
-    auto injectedScript = m_injectedScriptManager.injectedScriptFor(&state);
+    auto& globalObject = mainWorldGlobalObject(*frame);
+    auto injectedScript = m_injectedScriptManager.injectedScriptFor(&globalObject);
     ASSERT(!injectedScript.hasNoValue());
 
-    auto object = injectedScript.wrapObject(webSocketAsScriptValue(state, webSocket), objectGroup);
+    auto object = injectedScript.wrapObject(webSocketAsScriptValue(globalObject, webSocket), objectGroup);
     if (!object)
         return makeUnexpected("Internal error: unable to cast WebSocket");
 

Modified: trunk/Source/WebCore/inspector/agents/InspectorTimelineAgent.cpp (287326 => 287327)


--- trunk/Source/WebCore/inspector/agents/InspectorTimelineAgent.cpp	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/inspector/agents/InspectorTimelineAgent.cpp	2021-12-21 21:56:30 UTC (rev 287327)
@@ -47,7 +47,6 @@
 #include "PageDebugger.h"
 #include "PageHeapAgent.h"
 #include "RenderView.h"
-#include "ScriptState.h"
 #include "TimelineRecordFactory.h"
 #include "WebConsoleAgent.h"
 #include "WebDebuggerAgent.h"
@@ -66,7 +65,6 @@
 #include "RunLoopObserver.h"
 #endif
 
-
 namespace WebCore {
 
 using namespace Inspector;
@@ -290,8 +288,14 @@
     return m_environment.executionStopwatch().elapsedTime().seconds();
 }
 
-void InspectorTimelineAgent::startFromConsole(JSC::JSGlobalObject* exec, const String& title)
+static Frame* frame(JSC::JSGlobalObject* globalObject)
 {
+    auto context = executionContext(globalObject);
+    return is<Document>(context) ? downcast<Document>(*context).frame() : nullptr;
+}
+
+void InspectorTimelineAgent::startFromConsole(JSC::JSGlobalObject* globalObject, const String& title)
+{
     // Allow duplicate unnamed profiles. Disallow duplicate named profiles.
     if (!title.isEmpty()) {
         for (const TimelineRecordEntry& record : m_pendingConsoleProfileRecords) {
@@ -310,7 +314,7 @@
     if (!m_tracking && m_pendingConsoleProfileRecords.isEmpty())
         startProgrammaticCapture();
 
-    m_pendingConsoleProfileRecords.append(createRecordEntry(TimelineRecordFactory::createConsoleProfileData(title), TimelineRecordType::ConsoleProfile, true, frameFromExecState(exec)));
+    m_pendingConsoleProfileRecords.append(createRecordEntry(TimelineRecordFactory::createConsoleProfileData(title), TimelineRecordType::ConsoleProfile, true, frame(globalObject)));
 }
 
 void InspectorTimelineAgent::stopFromConsole(JSC::JSGlobalObject*, const String& title)
@@ -676,7 +680,7 @@
 
 void InspectorTimelineAgent::breakpointActionProbe(JSC::JSGlobalObject* lexicalGlobalObject, JSC::BreakpointActionID actionID, unsigned /*batchId*/, unsigned sampleId, JSC::JSValue)
 {
-    appendRecord(TimelineRecordFactory::createProbeSampleData(actionID, sampleId), TimelineRecordType::ProbeSample, false, frameFromExecState(lexicalGlobalObject));
+    appendRecord(TimelineRecordFactory::createProbeSampleData(actionID, sampleId), TimelineRecordType::ProbeSample, false, frame(lexicalGlobalObject));
 }
 
 static Protocol::Timeline::EventType toProtocol(TimelineRecordType type)

Modified: trunk/Source/WebCore/inspector/agents/WebConsoleAgent.cpp (287326 => 287327)


--- trunk/Source/WebCore/inspector/agents/WebConsoleAgent.cpp	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/inspector/agents/WebConsoleAgent.cpp	2021-12-21 21:56:30 UTC (rev 287327)
@@ -32,7 +32,6 @@
 #include "Logging.h"
 #include "ResourceError.h"
 #include "ResourceResponse.h"
-#include "ScriptState.h"
 #include "WebInjectedScriptManager.h"
 #include <_javascript_Core/ConsoleMessage.h>
 #include <_javascript_Core/JSCInlines.h>
@@ -39,7 +38,6 @@
 #include <_javascript_Core/ScriptArguments.h>
 #include <wtf/text/StringBuilder.h>
 
-
 namespace WebCore {
 
 using namespace Inspector;
@@ -49,19 +47,14 @@
 {
 }
 
-WebConsoleAgent::~WebConsoleAgent() = default;
-
-void WebConsoleAgent::frameWindowDiscarded(DOMWindow* window)
+void WebConsoleAgent::frameWindowDiscarded(DOMWindow& window)
 {
-    for (auto& message : m_consoleMessages) {
-        JSC::JSGlobalObject* lexicalGlobalObject = message->globalObject();
-        if (!lexicalGlobalObject)
-            continue;
-        if (domWindowFromExecState(lexicalGlobalObject) != window)
-            continue;
-        message->clear();
+    if (auto* document = window.document()) {
+        for (auto& message : m_consoleMessages) {
+            if (executionContext(message->globalObject()) == document)
+                message->clear();
+        }
     }
-
     static_cast<WebInjectedScriptManager&>(m_injectedScriptManager).discardInjectedScriptsFor(window);
 }
 

Modified: trunk/Source/WebCore/inspector/agents/WebConsoleAgent.h (287326 => 287327)


--- trunk/Source/WebCore/inspector/agents/WebConsoleAgent.h	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/inspector/agents/WebConsoleAgent.h	2021-12-21 21:56:30 UTC (rev 287327)
@@ -25,7 +25,6 @@
 
 #pragma once
 
-#include "InspectorWebAgentBase.h"
 #include "ResourceLoaderIdentifier.h"
 #include <_javascript_Core/InspectorConsoleAgent.h>
 
@@ -36,14 +35,12 @@
 class ResourceResponse;
 
 class WebConsoleAgent : public Inspector::InspectorConsoleAgent {
-    WTF_MAKE_NONCOPYABLE(WebConsoleAgent);
-    WTF_MAKE_FAST_ALLOCATED;
+protected:
+    explicit WebConsoleAgent(WebAgentContext&);
+
 public:
-    WebConsoleAgent(WebAgentContext&);
-    ~WebConsoleAgent() override;
-
     // InspectorInstrumentation
-    void frameWindowDiscarded(DOMWindow*);
+    void frameWindowDiscarded(DOMWindow&);
     void didReceiveResponse(ResourceLoaderIdentifier, const ResourceResponse&);
     void didFailLoading(ResourceLoaderIdentifier, const ResourceError&);
 };

Modified: trunk/Source/WebCore/inspector/agents/page/PageAuditAgent.cpp (287326 => 287327)


--- trunk/Source/WebCore/inspector/agents/page/PageAuditAgent.cpp	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/inspector/agents/page/PageAuditAgent.cpp	2021-12-21 21:56:30 UTC (rev 287327)
@@ -29,12 +29,12 @@
 #include "InspectorAuditAccessibilityObject.h"
 #include "InspectorAuditDOMObject.h"
 #include "InspectorAuditResourcesObject.h"
+#include "JSDOMWindowCustom.h"
 #include "JSInspectorAuditAccessibilityObject.h"
 #include "JSInspectorAuditDOMObject.h"
 #include "JSInspectorAuditResourcesObject.h"
 #include "Page.h"
 #include "PageConsoleClient.h"
-#include "ScriptState.h"
 #include <_javascript_Core/CallFrame.h>
 #include <_javascript_Core/InjectedScript.h>
 #include <_javascript_Core/InjectedScriptManager.h>
@@ -60,9 +60,7 @@
 {
     if (executionContextId)
         return injectedScriptManager().injectedScriptForId(*executionContextId);
-
-    JSC::JSGlobalObject* scriptState = mainWorldExecState(&m_inspectedPage.mainFrame());
-    return injectedScriptManager().injectedScriptFor(scriptState);
+    return injectedScriptManager().injectedScriptFor(&mainWorldGlobalObject(m_inspectedPage.mainFrame()));
 }
 
 InjectedScript PageAuditAgent::injectedScriptForEval(Protocol::ErrorString& errorString, std::optional<Protocol::Runtime::ExecutionContextId>&& executionContextId)

Modified: trunk/Source/WebCore/inspector/agents/page/PageDebuggerAgent.cpp (287326 => 287327)


--- trunk/Source/WebCore/inspector/agents/page/PageDebuggerAgent.cpp	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/inspector/agents/page/PageDebuggerAgent.cpp	2021-12-21 21:56:30 UTC (rev 287327)
@@ -38,11 +38,11 @@
 #include "Frame.h"
 #include "InspectorPageAgent.h"
 #include "InstrumentingAgents.h"
+#include "JSDOMWindowCustom.h"
 #include "Page.h"
 #include "PageConsoleClient.h"
 #include "PageDebugger.h"
 #include "ScriptExecutionContext.h"
-#include "ScriptState.h"
 #include "UserGestureEmulationScope.h"
 #include <_javascript_Core/InjectedScript.h>
 #include <_javascript_Core/InjectedScriptManager.h>
@@ -138,10 +138,8 @@
 
 InjectedScript PageDebuggerAgent::injectedScriptForEval(Protocol::ErrorString& errorString, std::optional<Protocol::Runtime::ExecutionContextId>&& executionContextId)
 {
-    if (!executionContextId) {
-        JSC::JSGlobalObject* scriptState = mainWorldExecState(&m_inspectedPage.mainFrame());
-        return injectedScriptManager().injectedScriptFor(scriptState);
-    }
+    if (!executionContextId)
+        return injectedScriptManager().injectedScriptFor(&mainWorldGlobalObject(m_inspectedPage.mainFrame()));
 
     InjectedScript injectedScript = injectedScriptManager().injectedScriptForId(*executionContextId);
     if (injectedScript.hasNoValue())

Modified: trunk/Source/WebCore/inspector/agents/page/PageNetworkAgent.cpp (287326 => 287327)


--- trunk/Source/WebCore/inspector/agents/page/PageNetworkAgent.cpp	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/inspector/agents/page/PageNetworkAgent.cpp	2021-12-21 21:56:30 UTC (rev 287327)
@@ -31,7 +31,6 @@
 #include "Frame.h"
 #include "InstrumentingAgents.h"
 #include "Page.h"
-#include "ScriptState.h"
 #include "WebSocket.h"
 #include "WebSocketChannel.h"
 

Modified: trunk/Source/WebCore/inspector/agents/page/PageRuntimeAgent.cpp (287326 => 287327)


--- trunk/Source/WebCore/inspector/agents/page/PageRuntimeAgent.cpp	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/inspector/agents/page/PageRuntimeAgent.cpp	2021-12-21 21:56:30 UTC (rev 287327)
@@ -37,11 +37,10 @@
 #include "Frame.h"
 #include "InspectorPageAgent.h"
 #include "InstrumentingAgents.h"
-#include "JSDOMWindowBase.h"
+#include "JSDOMWindowCustom.h"
 #include "Page.h"
 #include "PageConsoleClient.h"
 #include "ScriptController.h"
-#include "ScriptState.h"
 #include "SecurityOrigin.h"
 #include "UserGestureEmulationScope.h"
 #include <_javascript_Core/InjectedScript.h>
@@ -91,7 +90,7 @@
 void PageRuntimeAgent::frameNavigated(Frame& frame)
 {
     // Ensure execution context is created for the frame even if it doesn't have scripts.
-    mainWorldExecState(&frame);
+    mainWorldGlobalObject(frame);
 }
 
 void PageRuntimeAgent::didClearWindowObjectInWorld(Frame& frame, DOMWrapperWorld& world)
@@ -106,8 +105,7 @@
 InjectedScript PageRuntimeAgent::injectedScriptForEval(Protocol::ErrorString& errorString, std::optional<Protocol::Runtime::ExecutionContextId>&& executionContextId)
 {
     if (!executionContextId) {
-        JSC::JSGlobalObject* scriptState = mainWorldExecState(&m_inspectedPage.mainFrame());
-        InjectedScript result = injectedScriptManager().injectedScriptFor(scriptState);
+        InjectedScript result = injectedScriptManager().injectedScriptFor(&mainWorldGlobalObject(m_inspectedPage.mainFrame()));
         if (result.hasNoValue())
             errorString = "Internal error: main world execution context not found"_s;
         return result;
@@ -135,25 +133,25 @@
     if (!pageAgent)
         return;
 
-    for (auto* frame = &m_inspectedPage.mainFrame(); frame; frame = frame->tree().traverseNext()) {
-        if (!frame->script().canExecuteScripts(NotAboutToExecuteScript))
-            continue;
+    m_inspectedPage.forEachFrame([&](Frame& frame) {
+        if (!frame.script().canExecuteScripts(NotAboutToExecuteScript))
+            return;
 
-        auto frameId = pageAgent->frameId(frame);
+        auto frameId = pageAgent->frameId(&frame);
 
         // Always send the main world first.
-        auto* mainGlobalObject = mainWorldExecState(frame);
-        notifyContextCreated(frameId, mainGlobalObject, mainThreadNormalWorld());
+        auto& mainGlobalObject = mainWorldGlobalObject(frame);
+        notifyContextCreated(frameId, &mainGlobalObject, mainThreadNormalWorld());
 
-        for (auto& jsWindowProxy : frame->windowProxy().jsWindowProxiesAsVector()) {
+        for (auto& jsWindowProxy : frame.windowProxy().jsWindowProxiesAsVector()) {
             auto* globalObject = jsWindowProxy->window();
-            if (globalObject == mainGlobalObject)
+            if (globalObject == &mainGlobalObject)
                 continue;
 
             auto& securityOrigin = downcast<DOMWindow>(jsWindowProxy->wrapped()).document()->securityOrigin();
             notifyContextCreated(frameId, globalObject, jsWindowProxy->world(), &securityOrigin);
         }
-    }
+    });
 }
 
 static Protocol::Runtime::ExecutionContextType toProtocol(DOMWrapperWorld::Type type)

Modified: trunk/Source/WebCore/inspector/agents/worker/WorkerAuditAgent.cpp (287326 => 287327)


--- trunk/Source/WebCore/inspector/agents/worker/WorkerAuditAgent.cpp	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/inspector/agents/worker/WorkerAuditAgent.cpp	2021-12-21 21:56:30 UTC (rev 287327)
@@ -26,14 +26,12 @@
 #include "config.h"
 #include "WorkerAuditAgent.h"
 
-#include "ScriptState.h"
+#include "JSDOMGlobalObject.h"
 #include "WorkerOrWorkletGlobalScope.h"
+#include "WorkerOrWorkletScriptController.h"
 #include <_javascript_Core/InjectedScript.h>
 #include <_javascript_Core/InjectedScriptManager.h>
 #include <_javascript_Core/JSCInlines.h>
-#include <wtf/Ref.h>
-#include <wtf/RefPtr.h>
-#include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
@@ -55,7 +53,9 @@
         return InjectedScript();
     }
 
-    return injectedScriptManager().injectedScriptFor(globalObject(m_globalScope));
+    // FIXME: What guarantees m_globalScope.script() is non-null?
+    // FIXME: What guarantees globalScopeWrapper() is non-null?
+    return injectedScriptManager().injectedScriptFor(m_globalScope.script()->globalScopeWrapper());
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/inspector/agents/worker/WorkerDebuggerAgent.cpp (287326 => 287327)


--- trunk/Source/WebCore/inspector/agents/worker/WorkerDebuggerAgent.cpp	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/inspector/agents/worker/WorkerDebuggerAgent.cpp	2021-12-21 21:56:30 UTC (rev 287327)
@@ -26,8 +26,9 @@
 #include "config.h"
 #include "WorkerDebuggerAgent.h"
 
-#include "ScriptState.h"
+#include "JSDOMGlobalObject.h"
 #include "WorkerOrWorkletGlobalScope.h"
+#include "WorkerOrWorkletScriptController.h"
 #include <_javascript_Core/ConsoleMessage.h>
 #include <_javascript_Core/InjectedScript.h>
 #include <_javascript_Core/InjectedScriptManager.h>
@@ -60,7 +61,9 @@
         return InjectedScript();
     }
 
-    return injectedScriptManager().injectedScriptFor(globalObject(m_globalScope));
+    // FIXME: What guarantees m_globalScope.script() is non-null?
+    // FIXME: What guarantees globalScopeWrapper() is non-null?
+    return injectedScriptManager().injectedScriptFor(m_globalScope.script()->globalScopeWrapper());
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/inspector/agents/worker/WorkerRuntimeAgent.cpp (287326 => 287327)


--- trunk/Source/WebCore/inspector/agents/worker/WorkerRuntimeAgent.cpp	2021-12-21 20:16:05 UTC (rev 287326)
+++ trunk/Source/WebCore/inspector/agents/worker/WorkerRuntimeAgent.cpp	2021-12-21 21:56:30 UTC (rev 287327)
@@ -32,8 +32,9 @@
 #include "config.h"
 #include "WorkerRuntimeAgent.h"
 
-#include "ScriptState.h"
+#include "JSDOMGlobalObject.h"
 #include "WorkerOrWorkletGlobalScope.h"
+#include "WorkerOrWorkletScriptController.h"
 #include <_javascript_Core/InjectedScript.h>
 #include <_javascript_Core/InjectedScriptManager.h>
 
@@ -58,7 +59,9 @@
         return InjectedScript();
     }
 
-    return injectedScriptManager().injectedScriptFor(globalObject(m_globalScope));
+    // FIXME: What guarantees m_globalScope.script() is non-null?
+    // FIXME: What guarantees globalScopeWrapper() is non-null?
+    return injectedScriptManager().injectedScriptFor(m_globalScope.script()->globalScopeWrapper());
 }
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to