Closed imolorhe closed 4 years ago
Just fixed. Keep it open until next release.
@Siubaak thanks for the speedy implementation. When will the next release be?
@imolorhe 0.4.8 released. try it
Thanks, it works!
@Siubaak using 0.4.8, calling some window methods (including atob
and btoa
) directly (not through window.
) throws the Illegal invocation error for me. Not sure if I could be doing something wrong - I'm using your library in a chrome extension content script.
Anyway, the following workaround works for me:
const bindings = [
'fetch',
'setInterval',
'clearInterval',
'setTimeout',
'clearTimeout',
'atob',
'btoa'
]
.map((method) => `window.${method} = window.${method}.bind(null);\n`).join('');
const createSval = (options?: SvalOptions) => {
const interpreter = new Sval(options);
interpreter.run(bindings);
return interpreter;
};
Setting the this
arg to null
is counterintuitive, but it seems to fix the issue.
Also, not all methods are affected by the issue eg. localStorage
appears to work correctly without the fix.
@Siubaak using 0.4.8, calling some window methods (including
atob
andbtoa
) directly (not throughwindow.
) throws the Illegal invocation error for me. Not sure if I could be doing something wrong - I'm using your library in a chrome extension content script.Anyway, the following workaround works for me:
const bindings = [ 'fetch', 'setInterval', 'clearInterval', 'setTimeout', 'clearTimeout', 'atob', 'btoa' ] .map((method) => `window.${method} = window.${method}.bind(null);\n`).join(''); const createSval = (options?: SvalOptions) => { const interpreter = new Sval(options); interpreter.run(bindings); return interpreter; };
Setting the
this
arg tonull
is counterintuitive, but it seems to fix the issue. Also, not all methods are affected by the issue eg.localStorage
appears to work correctly without the fix.
It seems to be a bug. Please create an issue, thanks. Or, pr is welcomed, anytime. :D
When running code within the sval interpreter that uses
window.atob
orwindow.btoa
(those are the ones I've experienced the issue with so far), I get aTypeError: Illegal invocation
error.