From 7303da3991814a0ce220bf2fff3e51b968913b86 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Fri, 29 Dec 2023 19:17:46 -0500 Subject: Cross frame API safety (#491) * Require error type * Add TODOs * Fix init * Updates * More type safety * Fix incorrect API map * Update type safety * Updates * Add API * Update types * Update types * Updates * Remove unused * Restore types * Update frame ancestry handler * Simplify names * Fix * Remove old message handlers --- ext/js/core.js | 32 -------------------------------- 1 file changed, 32 deletions(-) (limited to 'ext/js/core.js') diff --git a/ext/js/core.js b/ext/js/core.js index c9c989ac..726b037c 100644 --- a/ext/js/core.js +++ b/ext/js/core.js @@ -320,38 +320,6 @@ export function promiseAnimationFrame(timeout) { }); } -/** - * Invokes a standard message handler. This function is used to react and respond - * to communication messages within the extension. - * @template {import('core').SafeAny} TParams - * @param {import('core').MessageHandler} handler The message handler function. - * @param {TParams} params Information which was passed with the original message. - * @param {(response: import('core').Response) => void} callback A callback function which is invoked after the handler has completed. The value passed - * to the function is in the format: - * - `{result: unknown}` if the handler invoked successfully. - * - `{error: object}` if the handler thew an error. The error is serialized. - * @param {...*} extraArgs Additional arguments which are passed to the `handler` function. - * @returns {boolean} `true` if the function is invoked asynchronously, `false` otherwise. - */ -export function invokeMessageHandler(handler, params, callback, ...extraArgs) { - try { - const promiseOrResult = handler(params, ...extraArgs); - if (promiseOrResult instanceof Promise) { - /** @type {Promise} */ (promiseOrResult).then( - (result) => { callback({result}); }, - (error) => { callback({error: ExtensionError.serialize(error)}); } - ); - return true; - } else { - callback({result: promiseOrResult}); - return false; - } - } catch (error) { - callback({error: ExtensionError.serialize(error)}); - return false; - } -} - /** * The following typedef is required because the JSDoc `implements` tag doesn't work with `import()`. * https://github.com/microsoft/TypeScript/issues/49905 -- cgit v1.2.3