Skip to content

Commit 6158a5a

Browse files
committed
workers: Add removePlugin function
1 parent 69846b0 commit 6158a5a

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

packages/workers/src/PluginWorker.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ lockdown({
3434
dateTaming: 'unsafe',
3535
});
3636

37+
/**
38+
* TODO:
39+
* To support multiple plugins per worker, we need to duplex the rpcStream
40+
* on this end, and pass MetaMaskInpageProvider the appropriate stream name.
41+
*/
42+
3743
// init
3844
(function () {
3945
class Controller {
@@ -191,7 +197,7 @@ lockdown({
191197
});
192198
compartment.evaluate(sourceCode);
193199
} catch (err) {
194-
// _removePlugin(pluginName) // TODO:WW
200+
this.removePlugin(pluginName);
195201
console.error(
196202
`Error while running plugin '${pluginName}' in worker:${self.name}.`,
197203
err,
@@ -215,9 +221,18 @@ lockdown({
215221
this.pluginRpcHandlers.set(pluginName, func);
216222
};
217223

224+
// TODO: harden throws an error. Why?
218225
// return harden(pluginProvider as PluginProvider);
219226
return pluginProvider as PluginProvider;
220227
}
228+
229+
/**
230+
* Removes the plugin with the given name. Specifically:
231+
* - Deletes the plugin's RPC handler, if any
232+
*/
233+
private removePlugin(pluginName: string): void {
234+
this.pluginRpcHandlers.delete(pluginName);
235+
}
221236
}
222237

223238
function setupMultiplex(

0 commit comments

Comments
 (0)