This repository was archived by the owner on Jan 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 747
Create search worker #3139
Merged
jasonLaster
merged 3 commits into
firefox-devtools:master
from
jasonLaster:search-worker
Jun 9, 2017
Merged
Create search worker #3139
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,4 +9,5 @@ DevToolsModules( | |
| 'panel.js', | ||
| 'parser-worker.js', | ||
| 'pretty-print-worker.js', | ||
| 'search-worker.js', | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| // @flow | ||
|
|
||
| import prettyFast from "pretty-fast"; | ||
| import assert from "../assert"; | ||
|
|
||
| import { workerUtils } from "devtools-utils"; | ||
| const { workerHandler } = workerUtils; | ||
|
|
||
| type Mappings = { | ||
| _array: Mapping[] | ||
|
|
@@ -24,19 +26,15 @@ type InvertedMapping = { | |
| }; | ||
|
|
||
| function prettyPrint({ url, indent, source }) { | ||
| try { | ||
| const prettified = prettyFast(source, { | ||
| url: url, | ||
| indent: " ".repeat(indent) | ||
| }); | ||
| const prettified = prettyFast(source, { | ||
| url: url, | ||
| indent: " ".repeat(indent) | ||
| }); | ||
|
|
||
| return { | ||
| code: prettified.code, | ||
| mappings: prettified.map._mappings | ||
| }; | ||
| } catch (e) { | ||
| throw new Error(`${e.message}\n${e.stack}`); | ||
| } | ||
| return { | ||
| code: prettified.code, | ||
| mappings: invertMappings(prettified.map._mappings) | ||
| }; | ||
| } | ||
|
|
||
| function invertMappings(mappings: Mappings) { | ||
|
|
@@ -59,20 +57,4 @@ function invertMappings(mappings: Mappings) { | |
| }); | ||
| } | ||
|
|
||
| self.onmessage = function(msg) { | ||
| const { id, args } = msg.data; | ||
| assert(msg.data.method === "prettyPrint", "Method must be `prettyPrint`"); | ||
|
|
||
| try { | ||
| let { code, mappings } = prettyPrint(args[0]); | ||
| self.postMessage({ | ||
| id, | ||
| response: { | ||
| code, | ||
| mappings: invertMappings(mappings) | ||
| } | ||
| }); | ||
| } catch (e) { | ||
| self.postMessage({ id, error: e }); | ||
| } | ||
| }; | ||
| self.onmessage = workerHandler({ prettyPrint }); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did a bit of clean up while i was in the worker code |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { workerUtils } from "devtools-utils"; | ||
| const { WorkerDispatcher } = workerUtils; | ||
|
|
||
| const dispatcher = new WorkerDispatcher(); | ||
| export const startSearchWorker = dispatcher.start.bind(dispatcher); | ||
| export const stopSearchWorker = dispatcher.stop.bind(dispatcher); | ||
|
|
||
| export const countMatches = dispatcher.task("countMatches"); |
2 changes: 1 addition & 1 deletion
2
src/utils/tests/build-query.js → src/utils/search/tests/build-query.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import { countMatches } from "../worker"; | ||
|
|
||
| describe("search", () => { | ||
| describe("countMatches", () => { | ||
| it("counts basic string match", () => { | ||
| const text = "the test string with test in it multiple times test."; | ||
| const query = "test"; | ||
| const count = countMatches(query, text, { | ||
| caseSensitive: true, | ||
| wholeWord: false, | ||
| regexMatch: false | ||
| }); | ||
| expect(count).toBe(3); | ||
| }); | ||
|
|
||
| it("counts basic string match case-sensitive", () => { | ||
| const text = "the Test string with test in it multiple times test."; | ||
| const query = "Test"; | ||
| const count = countMatches(query, text, { | ||
| caseSensitive: true, | ||
| wholeWord: false, | ||
| regexMatch: false | ||
| }); | ||
| expect(count).toBe(1); | ||
| }); | ||
|
|
||
| it("counts whole word string match", () => { | ||
| const text = "the test string test in it multiple times whoatestthe."; | ||
| const query = "test"; | ||
| const count = countMatches(query, text, { | ||
| caseSensitive: true, | ||
| wholeWord: true, | ||
| regexMatch: false | ||
| }); | ||
| expect(count).toBe(2); | ||
| }); | ||
|
|
||
| it("counts regex match", () => { | ||
| const text = "the test string test in it multiple times whoatestthe."; | ||
| const query = "(\\w+)\\s+(\\w+)"; | ||
| const count = countMatches(query, text, { | ||
| caseSensitive: true, | ||
| wholeWord: false, | ||
| regexMatch: true | ||
| }); | ||
| expect(count).toBe(4); | ||
| }); | ||
| }); | ||
| }); |
2 changes: 1 addition & 1 deletion
2
src/utils/editor/build-query.js → src/utils/search/utils/build-query.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import buildQuery from "./utils/build-query"; | ||
| import { workerUtils } from "devtools-utils"; | ||
| const { workerHandler } = workerUtils; | ||
|
|
||
| export function countMatches( | ||
| query: string, | ||
| text: string, | ||
| modifiers: SearchModifiers | ||
| ): number { | ||
| const regexQuery = buildQuery(query, modifiers, { | ||
| isGlobal: true | ||
| }); | ||
| const match = text.match(regexQuery); | ||
| return match ? match.length : 0; | ||
| } | ||
|
|
||
| self.onmessage = workerHandler({ countMatches }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ooh, we an use export directly and avoid the module.exports... yay