Wrap baked extensions in an IIFE

Closes https://github.com/TurboWarp/packager/issues/636
This commit is contained in:
GarboMuffin committed 2023-02-25 19:21:01 -06:00
1 parent 5b508ddddd
commit cbf00dd8a1
1 file changed
+5 -1
+5 -1
View File
@@ -1012,7 +1012,11 @@ cd "$(dirname "$0")"
const url = urlsToFetch[i];
try {
const source = await Adapter.fetchExtensionScript(url);
const dataURI = `data:text/javascript;,${encodeURIComponent(source)}`;
// Wrap the extension in an IIFE so that extensions written for the sandbox are less
// likely to cause issues in an unsandboxed environment due to global pollution or
// overriding Scratch.*
const wrappedSource = `(function(Scratch) { ${source} })(Scratch);`
const dataURI = `data:text/javascript;,${encodeURIComponent(wrappedSource)}`;
finalURLs.push(dataURI);
} catch (e) {
finalURLs.push(url);