| 51 | * @param {boolean | RawOverlayOptions | OverlayOptions} overlayOptions overlay options |
| 52 | */ |
| 53 | const decodeOverlayOptions = (overlayOptions) => { |
| 54 | if (typeof overlayOptions === "object") { |
| 55 | const requiredOptions = ["warnings", "errors", "runtimeErrors"]; |
| 56 | |
| 57 | for (let i = 0; i < requiredOptions.length; i++) { |
| 58 | const property = |
| 59 | /** @type {keyof Omit<RawOverlayOptions, "trustedTypesPolicyName">} */ |
| 60 | (requiredOptions[i]); |
| 61 | |
| 62 | if (typeof overlayOptions[property] === "string") { |
| 63 | const overlayFilterFunctionString = decodeURIComponent( |
| 64 | overlayOptions[property], |
| 65 | ); |
| 66 | |
| 67 | /** @type {OverlayOptions} */ |
| 68 | (overlayOptions)[property] = /** @type {(error: Error) => boolean} */ ( |
| 69 | // eslint-disable-next-line no-new-func |
| 70 | new Function( |
| 71 | "message", |
| 72 | `var callback = ${overlayFilterFunctionString} |
| 73 | return callback(message)`, |
| 74 | ) |
| 75 | ); |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | }; |
| 80 | |
| 81 | /** |
| 82 | * @type {Status} |