Skip to content
Browse files
Web Inspector: Assertion Failed: Expect an array of string values CSS…

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`

* 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:
git-svn-id: 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
rcaliman-apple committed May 24, 2022
1 parent 7f96d4f commit 48fd2556eb253349ab5d5ae326e0327e24aa1793
Showing 4 changed files with 9 additions and 24 deletions.
@@ -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}"`);
@@ -36,7 +36,7 @@ WI.CSSCompletions = class CSSCompletions
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();
@@ -138,18 +138,6 @@ WI.CSSCompletions = class CSSCompletions
return this._values;

console.assert(Array.isArray(values), values);
if (!values.length)



if (!query)
@@ -125,10 +125,9 @@ WI.CSSKeywordCompletions.forPartialPropertyValue = function(text, propertyName,

let valueCompletions;
if (functionName) {
valueCompletions = WI.CSSKeywordCompletions.forFunction(functionName);
valueCompletions.addValues(additionalFunctionValueCompletionsProvider?.(functionName) ?? []);
} else
if (functionName)
valueCompletions = WI.CSSKeywordCompletions.forFunction(functionName, {additionalFunctionValueCompletionsProvider});
valueCompletions = WI.CSSKeywordCompletions.forProperty(propertyName);

let completions;
@@ -209,7 +208,7 @@ WI.CSSKeywordCompletions.isTimingFunctionAwareProperty = function(name)
return false;

WI.CSSKeywordCompletions.forFunction = function(functionName)
WI.CSSKeywordCompletions.forFunction = function(functionName, {additionalFunctionValueCompletionsProvider} = {})
let suggestions = ["var()"];

@@ -230,6 +229,9 @@ WI.CSSKeywordCompletions.forFunction = function(functionName)

if (additionalFunctionValueCompletionsProvider)

return new WI.CSSCompletions(suggestions, {acceptEmptyPrefix: true});

@@ -68,11 +68,6 @@ WI.CSSPropertyNameCompletions = class CSSPropertyNameCompletions extends WI.CSSC
return super.startsWith(prefix);

console.assert(false, "Adding values will overwrite the list of supported CSS property names.");

// Private


0 comments on commit 48fd255

Please sign in to comment.