MCPcopy Index your code
hub / github.com/RustPython/RustPython / runJS

Function runJS

wasm/notebook/src/process.js:61–79  ·  view source on GitHub ↗
(code)

Source from the content-addressed store, hash-verified

59}
60
61async function runJS(code) {
62 const script = document.createElement('script');
63 const doc = document.body || document.documentElement;
64 const blob = new Blob([code], { type: 'text/javascript' });
65 const url = URL.createObjectURL(blob);
66 script.src = url;
67 const scriptLoaded = new Promise((resolve) => {
68 script.addEventListener('load', resolve);
69 });
70 doc.appendChild(script);
71 try {
72 URL.revokeObjectURL(url);
73 doc.removeChild(script);
74 await scriptLoaded;
75 } catch (e) {
76 // ignore if body is changed and script is detached
77 console.log(e);
78 }
79}
80
81export {
82 runPython,

Callers 1

executeNotebookFunction · 0.90

Calls 4

createElementMethod · 0.80
appendChildMethod · 0.45
removeChildMethod · 0.45
logMethod · 0.45

Tested by

no test coverage detected