Created
October 18, 2022 10:48
-
-
Save semlinker/15511bb4450f41fc54b21858fa87f970 to your computer and use it in GitHub Desktop.
Revisions
-
semlinker created this gist
Oct 18, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ function sandbox(code) { code = "with (sandbox) {" + code + "}"; const fn = new Function("sandbox", code); return function (sandbox) { const sandboxProxy = new Proxy(sandbox, { has(target, key) { return true; }, get(target, key) { if (key === Symbol.unscopables) return undefined; return target[key]; }, }); return fn(sandboxProxy); }; }