Title: [249185] trunk
Revision
249185
Author
drou...@apple.com
Date
2019-08-27 17:10:47 -0700 (Tue, 27 Aug 2019)

Log Message

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.

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/_javascript_RuntimeCompletionProvider.js:
(WI._javascript_RuntimeCompletionProvider.completionControllerCompletionsNeeded.receivedPropertyNames):

LayoutTests:

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

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (249184 => 249185)


--- trunk/LayoutTests/ChangeLog	2019-08-27 23:48:54 UTC (rev 249184)
+++ trunk/LayoutTests/ChangeLog	2019-08-28 00:10:47 UTC (rev 249185)
@@ -1,3 +1,13 @@
+2019-08-27  Devin Rousso  <drou...@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_...@apple.com>
 
         [WebGPU] Implement GPUErrors for and relax GPUBuffer validation rules

Modified: trunk/LayoutTests/inspector/unit-tests/array-utilities-expected.txt (249184 => 249185)


--- trunk/LayoutTests/inspector/unit-tests/array-utilities-expected.txt	2019-08-27 23:48:54 UTC (rev 249184)
+++ trunk/LayoutTests/inspector/unit-tests/array-utilities-expected.txt	2019-08-28 00:10:47 UTC (rev 249185)
@@ -132,8 +132,3 @@
 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.
-

Modified: trunk/LayoutTests/inspector/unit-tests/array-utilities.html (249184 => 249185)


--- trunk/LayoutTests/inspector/unit-tests/array-utilities.html	2019-08-27 23:48:54 UTC (rev 249184)
+++ trunk/LayoutTests/inspector/unit-tests/array-utilities.html	2019-08-28 00:10:47 UTC (rev 249185)
@@ -304,21 +304,6 @@
         }
     });
 
-    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>

Modified: trunk/Source/WebInspectorUI/ChangeLog (249184 => 249185)


--- trunk/Source/WebInspectorUI/ChangeLog	2019-08-27 23:48:54 UTC (rev 249184)
+++ trunk/Source/WebInspectorUI/ChangeLog	2019-08-28 00:10:47 UTC (rev 249185)
@@ -1,5 +1,23 @@
 2019-08-27  Devin Rousso  <drou...@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/_javascript_RuntimeCompletionProvider.js:
+        (WI._javascript_RuntimeCompletionProvider.completionControllerCompletionsNeeded.receivedPropertyNames):
+
+2019-08-27  Devin Rousso  <drou...@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
 

Modified: trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js (249184 => 249185)


--- trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js	2019-08-27 23:48:54 UTC (rev 249184)
+++ trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js	2019-08-28 00:10:47 UTC (rev 249185)
@@ -690,17 +690,6 @@
     }
 });
 
-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)

Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorCompletionController.js (249184 => 249185)


--- trunk/Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorCompletionController.js	2019-08-27 23:48:54 UTC (rev 249184)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorCompletionController.js	2019-08-28 00:10:47 UTC (rev 249185)
@@ -654,7 +654,7 @@
         // 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",
@@ -661,29 +661,31 @@
             "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()

Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/_javascript_RuntimeCompletionProvider.js (249184 => 249185)


--- trunk/Source/WebInspectorUI/UserInterface/Controllers/_javascript_RuntimeCompletionProvider.js	2019-08-27 23:48:54 UTC (rev 249184)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/_javascript_RuntimeCompletionProvider.js	2019-08-28 00:10:47 UTC (rev 249185)
@@ -317,7 +317,7 @@
             }
 
             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 @@
                         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)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to