Title: [294763] trunk
Revision
294763
Author
[email protected]
Date
2022-05-24 13:54:51 -0700 (Tue, 24 May 2022)

Log Message

Web Inspector: Assertion Failed: Expect an array of string values CSSCompletions.js:39
https://bugs.webkit.org/show_bug.cgi?id=240715

Reviewed by Devin Rousso.

When instantiating `WI.CSSCompletions` in `WI.CSSKeywordCompletions.forFunction()`
for "var" functions, the `values` array is initally empty.
An array of strings was expected.

The actual values are added immediately after instantiation via
`WI.CSSCompletions.addValues()`. They come from the custom completion provider
referenced by the `additionalFunctionValueCompletionsProvider` option.

There's no reason to have this two step approach. We can provide the result of
`additionalFunctionValueCompletionsProvider("var")` at `WI.CSSCompletions`
instantiation.

* Source/WebInspectorUI/UserInterface/Models/CSSCompletions.js:

Updated the assertion in the constructor to accept an empty array of values.
One may be returned when requesting CSS variable name completions on a
page without any variables defined.

(WI.CSSCompletions.prototype.addValues): Deleted.

The method can be removed because there are no other callers of `WI.CSSCompletions.addValues()`.

* Source/WebInspectorUI/UserInterface/Models/CSSKeywordCompletions.js:

We can concatenate the array of pre-defined values in
`WI.CSSKeywordCompletions.forFunction()` with the result of
`additionalFunctionValueCompletionsProvider()` and use the result when
instantiating `WI.CSSCompletions`.

* Source/WebInspectorUI/UserInterface/Models/CSSPropertyNameCompletions.js:
(WI.CSSPropertyNameCompletions.prototype.addValues): Deleted.

It was never expected to call `WI.CSSPropertyNameCompletions.addValues()` else
it would screw up the fixed list of supported property names instantiated only
once when Web Inspector connects to the backend. The subclass had an assertion
on `.addValues()` to remind us of this pitfall. This can go away too now.

Canonical link: https://commits.webkit.org/250929@main

Modified Paths

Diff

Modified: trunk/LayoutTests/inspector/unit-tests/css-keyword-completions.html (294762 => 294763)


--- trunk/LayoutTests/inspector/unit-tests/css-keyword-completions.html	2022-05-24 20:53:56 UTC (rev 294762)
+++ trunk/LayoutTests/inspector/unit-tests/css-keyword-completions.html	2022-05-24 20:54:51 UTC (rev 294763)
@@ -84,7 +84,7 @@
                 expectedPrefix ??= text;
                 expectedCompletions ??= [];
                 expectedCompletionCount ??= -1;
-                additionalFunctionValueCompletionsProvider ??= () => {};
+                additionalFunctionValueCompletionsProvider ??= () => [];
 
                 let completionResults = WI.CSSKeywordCompletions.forPartialPropertyValue(text, propertyName, {caretPosition, additionalFunctionValueCompletionsProvider});
                 InspectorTest.expectEqual(completionResults.prefix, expectedPrefix, `Expected result prefix to be "${expectedPrefix}"`);

Modified: trunk/Source/WebInspectorUI/UserInterface/Models/CSSCompletions.js (294762 => 294763)


--- trunk/Source/WebInspectorUI/UserInterface/Models/CSSCompletions.js	2022-05-24 20:53:56 UTC (rev 294762)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/CSSCompletions.js	2022-05-24 20:54:51 UTC (rev 294763)
@@ -36,7 +36,7 @@
     constructor(values, {acceptEmptyPrefix} = {})
     {
         console.assert(Array.isArray(values), values);
-        console.assert(typeof values[0] === "string", "Expect an array of string values", values);
+        console.assert(!values.length || typeof values[0] === "string", "Expected an array of string values or an empty array", values);
 
         this._values = values.slice();
         this._values.sort();
@@ -138,18 +138,6 @@
         return this._values;
     }
 
-    addValues(values)
-    {
-        console.assert(Array.isArray(values), values);
-        if (!values.length)
-            return;
-
-        this._values.pushAll(values);
-        this._values.sort();
-
-        this._queryController?.addValues(values);
-    }
-
     executeQuery(query)
     {
         if (!query)

Modified: trunk/Source/WebInspectorUI/UserInterface/Models/CSSKeywordCompletions.js (294762 => 294763)


--- trunk/Source/WebInspectorUI/UserInterface/Models/CSSKeywordCompletions.js	2022-05-24 20:53:56 UTC (rev 294762)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/CSSKeywordCompletions.js	2022-05-24 20:54:51 UTC (rev 294763)
@@ -125,10 +125,9 @@
     }
 
     let valueCompletions;
-    if (functionName) {
-        valueCompletions = WI.CSSKeywordCompletions.forFunction(functionName);
-        valueCompletions.addValues(additionalFunctionValueCompletionsProvider?.(functionName) ?? []);
-    } else
+    if (functionName)
+        valueCompletions = WI.CSSKeywordCompletions.forFunction(functionName, {additionalFunctionValueCompletionsProvider});
+    else
         valueCompletions = WI.CSSKeywordCompletions.forProperty(propertyName);
 
     let completions;
@@ -209,7 +208,7 @@
     return false;
 };
 
-WI.CSSKeywordCompletions.forFunction = function(functionName)
+WI.CSSKeywordCompletions.forFunction = function(functionName, {additionalFunctionValueCompletionsProvider} = {})
 {
     let suggestions = ["var()"];
 
@@ -230,6 +229,9 @@
         suggestions.pushAll(WI.CSSKeywordCompletions._colors);
     }
 
+    if (additionalFunctionValueCompletionsProvider)
+        suggestions.pushAll(additionalFunctionValueCompletionsProvider(functionName));
+
     return new WI.CSSCompletions(suggestions, {acceptEmptyPrefix: true});
 };
 

Modified: trunk/Source/WebInspectorUI/UserInterface/Models/CSSPropertyNameCompletions.js (294762 => 294763)


--- trunk/Source/WebInspectorUI/UserInterface/Models/CSSPropertyNameCompletions.js	2022-05-24 20:53:56 UTC (rev 294762)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/CSSPropertyNameCompletions.js	2022-05-24 20:54:51 UTC (rev 294763)
@@ -68,11 +68,6 @@
         return super.startsWith(prefix);
     }
 
-    addValues()
-    {
-        console.assert(false, "Adding values will overwrite the list of supported CSS property names.");
-    }
-
     // Private
 
     _updateValuesWithLatestCSSVariablesIfNeeded()
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to