- Notifications
You must be signed in to change notification settings - Fork 3
Description
isOpfsSupported
converts a function to a string to create a JS source string
Lines 41 to 46 in 08c341a
const url = URL.createObjectURL( | |
new Blob( | |
[`(${inner})().then(postMessage)`], | |
{ type: 'text/javascript' }, | |
), | |
) |
If this code is run through certain code transforms (e.g. tsc
with target of es2015
), the inner
function's string representation can become invalid worker code. In my project, inner.toString() === 'e'
, so the resulting worker source was (e)().then(postMessage)
(and e
's definition is outside of the worker) – attempting to use isOpfsSupported
raises an error because e.then
is not defined.
I think with target = es2015
, any async function would become invalid: demo.
This is an issue for me because I'm using your dialect-wasqlite-worker
(which is otherwise great, ty), which has an unskippable check to isOpfsSupported
when trying to use OPFS.
I don't need a fix urgently because I'm probably just going to patch dialect-wasqlite-worker
to unblock myself (I can assume OPFS is available in my app), but thought I'd bring this up as a potential pitfall.