Bug 234548 - ScriptState.h/cpp is a remnant of JavaScript engine abstraction that can be removed
Summary: ScriptState.h/cpp is a remnant of JavaScript engine abstraction that can be r...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore JavaScript (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Darin Adler
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-12-20 23:53 PST by Darin Adler
Modified: 2021-12-21 13:57 PST (History)
17 users (show)

See Also:


Attachments
Patch (77.03 KB, patch)
2021-12-21 00:45 PST, Darin Adler
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (77.64 KB, patch)
2021-12-21 00:51 PST, Darin Adler
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (77.65 KB, patch)
2021-12-21 01:36 PST, Darin Adler
ysuzuki: review+
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (77.19 KB, patch)
2021-12-21 02:12 PST, Darin Adler
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (77.42 KB, patch)
2021-12-21 02:26 PST, Darin Adler
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (77.73 KB, patch)
2021-12-21 08:28 PST, Darin Adler
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (76.22 KB, patch)
2021-12-21 11:28 PST, Darin Adler
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
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>