thread-configuration-command.js (2509B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 /** 8 * The ThreadConfigurationCommand should be used to maintain thread settings 9 * sent from the client for the thread actor. 10 * 11 * See the ThreadConfigurationActor for a list of supported configuration options. 12 */ 13 class ThreadConfigurationCommand { 14 constructor({ commands, watcherFront }) { 15 this._commands = commands; 16 this._watcherFront = watcherFront; 17 } 18 19 /** 20 * Return a promise that resolves to the related thread configuration actor's front. 21 * 22 * @return {Promise<ThreadConfigurationFront>} 23 */ 24 async getThreadConfigurationFront() { 25 const front = await this._watcherFront.getThreadConfigurationActor(); 26 return front; 27 } 28 29 async updateConfiguration(configuration) { 30 if (this._commands.targetCommand.hasTargetWatcherSupport()) { 31 // Remove thread options that are not currently supported by 32 // the thread configuration actor. 33 const filteredConfiguration = Object.fromEntries( 34 Object.entries(configuration).filter( 35 ([key]) => !["breakpoints", "eventBreakpoints"].includes(key) 36 ) 37 ); 38 39 const threadConfigurationFront = await this.getThreadConfigurationFront(); 40 const updatedConfiguration = 41 await threadConfigurationFront.updateConfiguration( 42 filteredConfiguration 43 ); 44 this._configuration = updatedConfiguration; 45 } 46 47 let threadFronts = await this._commands.targetCommand.getAllFronts( 48 this._commands.targetCommand.ALL_TYPES, 49 "thread" 50 ); 51 52 // Lets always call reconfigure for all the target types that do not 53 // have target watcher support yet. e.g In the browser, even 54 // though `hasTargetWatcherSupport()` is true, only 55 // FRAME and CONTENT PROCESS targets use watcher actors, 56 // WORKER targets are supported via the legacy listerners. 57 threadFronts = threadFronts.filter( 58 threadFront => 59 !this._commands.targetCommand.hasTargetWatcherSupport( 60 threadFront.targetFront.targetType 61 ) 62 ); 63 64 // Ignore threads that fail to be configured. 65 // Some workers may be destroying and `reconfigure` would be rejected. 66 await Promise.allSettled( 67 threadFronts.map(threadFront => threadFront.reconfigure(configuration)) 68 ); 69 } 70 } 71 72 module.exports = ThreadConfigurationCommand;