[Webkit-unassigned] [Bug 272100] New: Web Inspector: JavaScriptRuntimeCompletionProvider should be more proactive about clearing property name cache

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Wed Apr 3 11:45:41 PDT 2024


https://bugs.webkit.org/show_bug.cgi?id=272100

            Bug ID: 272100
           Summary: Web Inspector: JavaScriptRuntimeCompletionProvider
                    should be more proactive about clearing property name
                    cache
           Product: WebKit
           Version: Safari Technology Preview
          Hardware: All
                OS: All
            Status: NEW
          Severity: Normal
          Priority: P2
         Component: Web Inspector
          Assignee: webkit-unassigned at lists.webkit.org
          Reporter: qianlangchen at apple.com
                CC: inspector-bugzilla-changes at group.apple.com

Created attachment 470748

  --> https://bugs.webkit.org/attachment.cgi?id=470748&action=review

Video demo: Property `ooo.aab` does not get suggested

TL;DR: WI.JavaScriptRuntimeCompletionProvider needs to clear its property name cache for an object ideally when the object's property list changes, which can happen within the 30-second window the Provider normally holds the cache for.

---

Currently, our WI.JavaScriptRuntimeCompletionProvider, which is made use of by the console prompt and various breakpoint editors, has a mechanism to cache its list of property name suggestions: if the Provider is asked to suggest property names of the same object (with the same string typed in to the left of caret, like the "myObject." part), it reuses suggestions from last time to avoid fetching/evaluating them again which would likely result in the same suggestion list.

    - Source of the said cache being used: https://github.com/WebKit/WebKit/blob/4f1ded96b3967cf2de4cc260b1e49940e93822e4/Source/WebInspectorUI/UserInterface/Controllers/JavaScriptRuntimeCompletionProvider.js#L139-L147

As you imagine, a cache is susceptible to its data being outdated. If the list of properties of an object changes, the Provider needs to know to clear the cache and, the when asked to provide suggestions next time, re-evaluate the properties. The PR https://github.com/WebKit/WebKit/pull/26632 made an effort to clear the property name cache when either new commands are executed in the console or when the console clears. However, if the property list changes as a result of background-running JavaScript instead of the inspector's console, those changes aren't detected or reacted by the Provider, so it keeps suggesting the same thing from last time.

To mitigate that problem with outdated suggestions, the Provider currently automatically clears the cache every 30 seconds, to try and catch up in case the properties did change by background JavaScript. But that's definitely not enough as changes can happen before 30 seconds have passed.

   - Source of clearing the cache after 30 seconds: https://github.com/WebKit/WebKit/blob/4f1ded96b3967cf2de4cc260b1e49940e93822e4/Source/WebInspectorUI/UserInterface/Controllers/JavaScriptRuntimeCompletionProvider.js#L163-L165

Here's one way to reproduce the outdated suggestions (video demo attached):
   1. Open inspector's console
   2. Run the following code:
       ooo = {aaa: 42};
       setTimeout(() => ooo.aab = 77, 5000);
   3. Quickly type `ooo.` (without the backticks)
      => Observe that the only suggestion is `aaa`, which is correct, as the setTimeout function hasn't run yet
   4. After 5 seconds, type `a`
      => Observe that `aaa` is still the only suggestion, but you should expect `aab` to also be suggested

The JavaScriptRuntimeCompletionProvider needs to somehow know that `ooo` has been modified, with a new property added, and invalidate its property name cache.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20240403/8f204be0/attachment-0001.htm>


More information about the webkit-unassigned mailing list