⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 249185 in webkit


Ignore:
Timestamp:
Aug 27, 2019, 5:10:47 PM (7 years ago)
Author:
Devin Rousso
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/JavaScriptRuntimeCompletionProvider.js:

(WI.JavaScriptRuntimeCompletionProvider.completionControllerCompletionsNeeded.receivedPropertyNames):

LayoutTests:

  • inspector/unit-tests/array-utilities.html:
  • inspector/unit-tests/array-utilities-expected.txt:
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r249183 r249185  
     12019-08-27  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: replace uses of added utility `Array.prototype.keySet` with an actual `Set`
     4        https://bugs.webkit.org/show_bug.cgi?id=201194
     5
     6        Reviewed by Ross Kirsling.
     7
     8        * inspector/unit-tests/array-utilities.html:
     9        * inspector/unit-tests/array-utilities-expected.txt:
     10
    1112019-08-27  Justin Fan  <justin_fan@apple.com>
    212
  • trunk/LayoutTests/inspector/unit-tests/array-utilities-expected.txt

    r245991 r249185  
    133133PASS: insertAtIndex with index greater than array length should insert at the end.
    134134
    135 -- Running test case: Array.prototype.keySet
    136 PASS: keySet should create an object with keys equal to the array values.
    137 PASS: keySet should create an object with all values equal to true.
    138 PASS: keySet should create an object with keys equal to stringified array values.
    139 
  • trunk/LayoutTests/inspector/unit-tests/array-utilities.html

    r245991 r249185  
    305305    });
    306306
    307     suite.addTestCase({
    308         name: "Array.prototype.keySet",
    309         test() {
    310             let arr1 = ["abc", "def", "xyz"];
    311             let keySet = arr1.keySet();
    312             InspectorTest.expectShallowEqual(Object.keys(keySet), arr1, "keySet should create an object with keys equal to the array values.");
    313             InspectorTest.expectShallowEqual(Object.values(keySet), [true, true, true], "keySet should create an object with all values equal to true.");
    314 
    315             let arr2 = [1, 2, 3];
    316             InspectorTest.expectShallowEqual(Object.keys(arr2.keySet()), arr2.map(x => x.toString()), "keySet should create an object with keys equal to stringified array values.");
    317 
    318             return true;
    319         }
    320     });
    321 
    322307    suite.runTestCasesAndFinish();
    323308}
  • trunk/Source/WebInspectorUI/ChangeLog

    r249163 r249185  
     12019-08-27  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: replace uses of added utility `Array.prototype.keySet` with an actual `Set`
     4        https://bugs.webkit.org/show_bug.cgi?id=201194
     5
     6        Reviewed by Ross Kirsling.
     7
     8        They both have basically the same functionality, with one difference being that a `Set` can
     9        work with arrays that have non-string values.
     10
     11        * UserInterface/Base/Utilities.js:
     12        (Array.prototype.keySet): Deleted.
     13        * UserInterface/Controllers/CodeMirrorCompletionController.js:
     14        (WI.CodeMirrorCompletionController.prototype._generateJavaScriptCompletions):
     15        (WI.CodeMirrorCompletionController.prototype._generateJavaScriptCompletions.matchKeywords):
     16        * UserInterface/Controllers/JavaScriptRuntimeCompletionProvider.js:
     17        (WI.JavaScriptRuntimeCompletionProvider.completionControllerCompletionsNeeded.receivedPropertyNames):
     18
    1192019-08-27  Devin Rousso  <drousso@apple.com>
    220
  • trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js

    r248537 r249185  
    691691});
    692692
    693 Object.defineProperty(Array.prototype, "keySet",
    694 {
    695     value()
    696     {
    697         let keys = Object.create(null);
    698         for (var i = 0; i < this.length; ++i)
    699             keys[this[i]] = true;
    700         return keys;
    701     }
    702 });
    703 
    704693Object.defineProperty(Array.prototype, "partition",
    705694{
  • trunk/Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorCompletionController.js

    r239630 r249185  
    655655        // var moduleKeywords = ["default", "export", "import"];
    656656
    657         var allKeywords = [
     657        const allKeywords = [
    658658            "break", "case", "catch", "class", "const", "continue", "debugger", "default",
    659659            "delete", "do", "else", "extends", "false", "finally", "for", "function",
     
    662662            "typeof", "undefined", "var", "void", "while", "with", "yield"
    663663        ];
    664         var valueKeywords = ["false", "Infinity", "NaN", "null", "this", "true", "undefined", "globalThis"];
    665 
    666         var allowedKeywordsInsideBlocks = allKeywords.keySet();
    667         var allowedKeywordsWhenDeclaringVariable = valueKeywords.keySet();
    668         var allowedKeywordsInsideParenthesis = valueKeywords.concat(["class", "function"]).keySet();
    669         var allowedKeywordsInsideBrackets = allowedKeywordsInsideParenthesis;
    670         var allowedKeywordsOnlyInsideSwitch = ["case", "default"].keySet();
     664        const valueKeywords = ["false", "Infinity", "NaN", "null", "this", "true", "undefined", "globalThis"];
     665
     666        const allowedKeywordsInsideBlocks = new Set(allKeywords);
     667        const allowedKeywordsWhenDeclaringVariable = new Set(valueKeywords);
     668        const allowedKeywordsInsideParenthesis = new Set(valueKeywords.concat(["class", "function"]));
     669        const allowedKeywordsInsideBrackets = allowedKeywordsInsideParenthesis;
     670        const allowedKeywordsOnlyInsideSwitch = new Set(["case", "default"]);
    671671
    672672        function matchKeywords(keywords)
    673673        {
    674             matchingWords = matchingWords.concat(keywords.filter(function(word) {
    675                 if (!insideSwitch && word in allowedKeywordsOnlyInsideSwitch)
    676                     return false;
    677                 if (insideBlock && !(word in allowedKeywordsInsideBlocks))
    678                     return false;
    679                 if (insideBrackets && !(word in allowedKeywordsInsideBrackets))
    680                     return false;
    681                 if (insideParenthesis && !(word in allowedKeywordsInsideParenthesis))
    682                     return false;
    683                 if (declaringVariable && !(word in allowedKeywordsWhenDeclaringVariable))
    684                     return false;
    685                 return word.startsWith(prefix);
    686             }));
     674            for (let keyword of keywords) {
     675                if (!insideSwitch && allowedKeywordsOnlyInsideSwitch.has(keyword))
     676                    continue;
     677                if (insideBlock && !allowedKeywordsInsideBlocks.has(keyword))
     678                    continue;
     679                if (insideBrackets && !allowedKeywordsInsideBrackets.has(keyword))
     680                    continue;
     681                if (insideParenthesis && !allowedKeywordsInsideParenthesis.has(keyword))
     682                    continue;
     683                if (declaringVariable && !allowedKeywordsWhenDeclaringVariable.has(keyword))
     684                    continue;
     685                if (!keyword.startsWith(prefix))
     686                    continue;
     687                matchingWords.push(keyword);
     688            }
    687689        }
    688690
  • trunk/Source/WebInspectorUI/UserInterface/Controllers/JavaScriptRuntimeCompletionProvider.js

    r249078 r249185  
    318318
    319319            var completions = defaultCompletions;
    320             var knownCompletions = completions.keySet();
     320            let knownCompletions = new Set(completions);
    321321
    322322            for (var i = 0; i < propertyNames.length; ++i) {
     
    331331                }
    332332
    333                 if (!property.startsWith(prefix) || property in knownCompletions)
     333                if (!property.startsWith(prefix) || knownCompletions.has(property))
    334334                    continue;
    335335
    336336                completions.push(property);
    337                 knownCompletions[property] = true;
     337                knownCompletions.add(property);
    338338            }
    339339
Note: See TracChangeset for help on using the changeset viewer.