Bug 234548

Summary: ScriptState.h/cpp is a remnant of JavaScript engine abstraction that can be removed
Product: WebKit Reporter: Darin Adler <darin>
Component: WebCore JavaScriptAssignee: Darin Adler <darin>
Status: RESOLVED FIXED    
Severity: Normal CC: alecflett, annulen, ashvayka, beidson, cdumez, esprehn+autocc, ews-watchlist, gyuyoung.kim, hi, joepeck, jsbell, kangil.han, pangle, ryuan.choi, sergio, webkit-bug-importer, ysuzuki
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: All   
OS: All   
Attachments:
Description Flags
Patch
ews-feeder: commit-queue-
Patch
ews-feeder: commit-queue-
Patch
ysuzuki: review+, ews-feeder: commit-queue-
Patch
ews-feeder: commit-queue-
Patch
ews-feeder: commit-queue-
Patch
ews-feeder: commit-queue-
Patch none

Description Darin Adler 2021-12-20 23:53:58 PST
ScriptState.h/cpp is a remnant of JavaScript engine abstraction that can be removed
Comment 1 Darin Adler 2021-12-21 00:45:28 PST Comment hidden (obsolete)
Comment 2 Darin Adler 2021-12-21 00:51:08 PST Comment hidden (obsolete)
Comment 3 Darin Adler 2021-12-21 01:36:43 PST
Created attachment 447697 [details]
Patch
Comment 4 Yusuke Suzuki 2021-12-21 01:51:57 PST
Comment on attachment 447697 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=447697&action=review

r=me with comments.

> Source/WebCore/ChangeLog:15
> +        Also begin to just call global objects "global object", and not "script state".

Nice.

> Source/WebCore/inspector/InspectorFrontendHost.cpp:164
> +    auto& globalObject = *m_frontendPage->mainFrame().script().globalObject(world);

In the old code, m_frontendPage can be nullptr.

> Source/WebCore/inspector/WebInjectedScriptManager.cpp:91
> +    {
> +        Vector<long> idsToRemove;
> +        for (auto& entry : m_idToInjectedScript) {
> +            auto* globalObject = entry.value.globalObject();
> +            if (executionContext(globalObject) == document) {
> +                m_scriptStateToId.remove(globalObject);
> +                idsToRemove.append(entry.key);
> +            }
> +        }
> +        for (auto& id : idsToRemove)
> +            m_idToInjectedScript.remove(id);
>      }

How about using `HashMap::removeIf`?

> Source/WebCore/inspector/WebInjectedScriptManager.cpp:103
> +    // Now remove global objects that have no injected script.
> +    {
> +        Vector<JSC::JSGlobalObject*> globalObjectsToRemove;
> +        for (auto& entry : m_scriptStateToId) {
> +            auto* globalObject = entry.key;
> +            if (executionContext(globalObject) == document)
> +                globalObjectsToRemove.append(globalObject);
> +        }
> +        for (auto& globalObject : globalObjectsToRemove)
> +            m_scriptStateToId.remove(globalObject);
> +    }

How about using `HashMap::removeIf`?

> Source/WebCore/inspector/agents/InspectorApplicationCacheAgent.cpp:117
> +    m_inspectedPage.forEachFrame([&] (Frame& frame) {

Remove space between [&] and (Frame& frame).

> Source/WebCore/inspector/agents/InspectorTimelineAgent.cpp:297
>  void InspectorTimelineAgent::startFromConsole(JSC::JSGlobalObject* exec, const String& title)

Let's rename exec to `globalObject` or `lexicalGlobalObject`.

> Source/WebCore/inspector/agents/page/PageRuntimeAgent.cpp:136
> +    m_inspectedPage.forEachFrame([&] (Frame& frame) {

Remove space between [] part and () part in lambda.
Comment 5 Darin Adler 2021-12-21 02:12:21 PST Comment hidden (obsolete)
Comment 6 Darin Adler 2021-12-21 02:26:25 PST Comment hidden (obsolete)
Comment 7 Darin Adler 2021-12-21 08:28:50 PST Comment hidden (obsolete)
Comment 8 Darin Adler 2021-12-21 11:28:48 PST
Created attachment 447738 [details]
Patch
Comment 9 Darin Adler 2021-12-21 13:56:43 PST
Committed r287327 (245477@trunk): <https://commits.webkit.org/245477@trunk>
Comment 10 Radar WebKit Bug Importer 2021-12-21 13:57:18 PST
<rdar://problem/86783286>