Web Inspector: replace uses of added utility `Array.prototype.keySet` with an actual...
authordrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 28 Aug 2019 00:10:47 +0000 (00:10 +0000)
committerdrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 28 Aug 2019 00:10:47 +0000 (00:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=201194

Reviewed by Ross Kirsling.

Source/WebInspectorUI:

They both have basically the same functionality, with one difference being that a `Set` can
work with arrays that have non-string values.

* UserInterface/Base/Utilities.js:
(Array.prototype.keySet): Deleted.
* UserInterface/Controllers/CodeMirrorCompletionController.js:
(WI.CodeMirrorCompletionController.prototype._generateJavaScriptCompletions):
(WI.CodeMirrorCompletionController.prototype._generateJavaScriptCompletions.matchKeywords):
* UserInterface/Controllers/JavaScriptRuntimeCompletionProvider.js:
(WI.JavaScriptRuntimeCompletionProvider.completionControllerCompletionsNeeded.receivedPropertyNames):

LayoutTests:

* inspector/unit-tests/array-utilities.html:
* inspector/unit-tests/array-utilities-expected.txt:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@249185 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/inspector/unit-tests/array-utilities-expected.txt
LayoutTests/inspector/unit-tests/array-utilities.html
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Base/Utilities.js
Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorCompletionController.js
Source/WebInspectorUI/UserInterface/Controllers/JavaScriptRuntimeCompletionProvider.js

index be12b0e..d010507 100644 (file)
@@ -1,3 +1,13 @@
+2019-08-27  Devin Rousso  <drousso@apple.com>
+
+        Web Inspector: replace uses of added utility `Array.prototype.keySet` with an actual `Set`
+        https://bugs.webkit.org/show_bug.cgi?id=201194
+
+        Reviewed by Ross Kirsling.
+
+        * inspector/unit-tests/array-utilities.html:
+        * inspector/unit-tests/array-utilities-expected.txt:
+
 2019-08-27  Justin Fan  <justin_fan@apple.com>
 
         [WebGPU] Implement GPUErrors for and relax GPUBuffer validation rules
index 9cc6c96..8dfbab5 100644 (file)
@@ -132,8 +132,3 @@ PASS: insertAtIndex with 0 < index < length should insert at the correct locatio
 PASS: insertAtIndex with negative index should insert from the end.
 PASS: insertAtIndex with index greater than array length should insert at the end.
 
--- Running test case: Array.prototype.keySet
-PASS: keySet should create an object with keys equal to the array values.
-PASS: keySet should create an object with all values equal to true.
-PASS: keySet should create an object with keys equal to stringified array values.
-
index c3282a7..8370833 100644 (file)
@@ -304,21 +304,6 @@ function test()
         }
     });
 
-    suite.addTestCase({
-        name: "Array.prototype.keySet",
-        test() {
-            let arr1 = ["abc", "def", "xyz"];
-            let keySet = arr1.keySet();
-            InspectorTest.expectShallowEqual(Object.keys(keySet), arr1, "keySet should create an object with keys equal to the array values.");
-            InspectorTest.expectShallowEqual(Object.values(keySet), [true, true, true], "keySet should create an object with all values equal to true.");
-
-            let arr2 = [1, 2, 3];
-            InspectorTest.expectShallowEqual(Object.keys(arr2.keySet()), arr2.map(x => x.toString()), "keySet should create an object with keys equal to stringified array values.");
-
-            return true;
-        }
-    });
-
     suite.runTestCasesAndFinish();
 }
 </script>
index 6bf2452..591002b 100644 (file)
@@ -1,5 +1,23 @@
 2019-08-27  Devin Rousso  <drousso@apple.com>
 
+        Web Inspector: replace uses of added utility `Array.prototype.keySet` with an actual `Set`
+        https://bugs.webkit.org/show_bug.cgi?id=201194
+
+        Reviewed by Ross Kirsling.
+
+        They both have basically the same functionality, with one difference being that a `Set` can
+        work with arrays that have non-string values.
+
+        * UserInterface/Base/Utilities.js:
+        (Array.prototype.keySet): Deleted.
+        * UserInterface/Controllers/CodeMirrorCompletionController.js:
+        (WI.CodeMirrorCompletionController.prototype._generateJavaScriptCompletions):
+        (WI.CodeMirrorCompletionController.prototype._generateJavaScriptCompletions.matchKeywords):
+        * UserInterface/Controllers/JavaScriptRuntimeCompletionProvider.js:
+        (WI.JavaScriptRuntimeCompletionProvider.completionControllerCompletionsNeeded.receivedPropertyNames):
+
+2019-08-27  Devin Rousso  <drousso@apple.com>
+
         Web Inspector: change the styling of the special log "bubble" to match WI.ScopeBar
         https://bugs.webkit.org/show_bug.cgi?id=201152
 
index dde9eeb..74be421 100644 (file)
@@ -690,17 +690,6 @@ Object.defineProperty(Array.prototype, "insertAtIndex",
     }
 });
 
-Object.defineProperty(Array.prototype, "keySet",
-{
-    value()
-    {
-        let keys = Object.create(null);
-        for (var i = 0; i < this.length; ++i)
-            keys[this[i]] = true;
-        return keys;
-    }
-});
-
 Object.defineProperty(Array.prototype, "partition",
 {
     value(callback)
index 7774f1c..c94a75a 100644 (file)
@@ -654,36 +654,38 @@ WI.CodeMirrorCompletionController = class CodeMirrorCompletionController extends
         // FIXME: Include module keywords if we know this is a module environment.
         // var moduleKeywords = ["default", "export", "import"];
 
-        var allKeywords = [
+        const allKeywords = [
             "break", "case", "catch", "class", "const", "continue", "debugger", "default",
             "delete", "do", "else", "extends", "false", "finally", "for", "function",
             "if", "in", "Infinity", "instanceof", "let", "NaN", "new", "null", "of",
             "return", "static", "super", "switch", "this", "throw", "true", "try",
             "typeof", "undefined", "var", "void", "while", "with", "yield"
         ];
-        var valueKeywords = ["false", "Infinity", "NaN", "null", "this", "true", "undefined", "globalThis"];
+        const valueKeywords = ["false", "Infinity", "NaN", "null", "this", "true", "undefined", "globalThis"];
 
-        var allowedKeywordsInsideBlocks = allKeywords.keySet();
-        var allowedKeywordsWhenDeclaringVariable = valueKeywords.keySet();
-        var allowedKeywordsInsideParenthesis = valueKeywords.concat(["class", "function"]).keySet();
-        var allowedKeywordsInsideBrackets = allowedKeywordsInsideParenthesis;
-        var allowedKeywordsOnlyInsideSwitch = ["case", "default"].keySet();
+        const allowedKeywordsInsideBlocks = new Set(allKeywords);
+        const allowedKeywordsWhenDeclaringVariable = new Set(valueKeywords);
+        const allowedKeywordsInsideParenthesis = new Set(valueKeywords.concat(["class", "function"]));
+        const allowedKeywordsInsideBrackets = allowedKeywordsInsideParenthesis;
+        const allowedKeywordsOnlyInsideSwitch = new Set(["case", "default"]);
 
         function matchKeywords(keywords)
         {
-            matchingWords = matchingWords.concat(keywords.filter(function(word) {
-                if (!insideSwitch && word in allowedKeywordsOnlyInsideSwitch)
-                    return false;
-                if (insideBlock && !(word in allowedKeywordsInsideBlocks))
-                    return false;
-                if (insideBrackets && !(word in allowedKeywordsInsideBrackets))
-                    return false;
-                if (insideParenthesis && !(word in allowedKeywordsInsideParenthesis))
-                    return false;
-                if (declaringVariable && !(word in allowedKeywordsWhenDeclaringVariable))
-                    return false;
-                return word.startsWith(prefix);
-            }));
+            for (let keyword of keywords) {
+                if (!insideSwitch && allowedKeywordsOnlyInsideSwitch.has(keyword))
+                    continue;
+                if (insideBlock && !allowedKeywordsInsideBlocks.has(keyword))
+                    continue;
+                if (insideBrackets && !allowedKeywordsInsideBrackets.has(keyword))
+                    continue;
+                if (insideParenthesis && !allowedKeywordsInsideParenthesis.has(keyword))
+                    continue;
+                if (declaringVariable && !allowedKeywordsWhenDeclaringVariable.has(keyword))
+                    continue;
+                if (!keyword.startsWith(prefix))
+                    continue;
+                matchingWords.push(keyword);
+            }
         }
 
         function matchVariables()
index d12d42b..e52273c 100644 (file)
@@ -317,7 +317,7 @@ WI.JavaScriptRuntimeCompletionProvider = class JavaScriptRuntimeCompletionProvid
             }
 
             var completions = defaultCompletions;
-            var knownCompletions = completions.keySet();
+            let knownCompletions = new Set(completions);
 
             for (var i = 0; i < propertyNames.length; ++i) {
                 var property = propertyNames[i];
@@ -330,11 +330,11 @@ WI.JavaScriptRuntimeCompletionProvider = class JavaScriptRuntimeCompletionProvid
                         property = quoteUsed + property.escapeCharacters(quoteUsed + "\\") + (suffix !== quoteUsed ? quoteUsed : "");
                 }
 
-                if (!property.startsWith(prefix) || property in knownCompletions)
+                if (!property.startsWith(prefix) || knownCompletions.has(property))
                     continue;
 
                 completions.push(property);
-                knownCompletions[property] = true;
+                knownCompletions.add(property);
             }
 
             function compare(a, b)