fix: run module in an isolated context
This commit is contained in:
parent
ba6462458c
commit
f8553b79f9
@ -92,7 +92,7 @@ public class Context implements Extensions {
|
||||
return new Context(ext);
|
||||
}
|
||||
public static Extensions clean(Extensions ext) {
|
||||
if (ext instanceof Context) return ((Context)ext).extensions;
|
||||
if (ext instanceof Context) return clean(((Context)ext).extensions);
|
||||
else return ext;
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ public class GlobalScope {
|
||||
return Values.hasMember(ext, obj, name, false);
|
||||
}
|
||||
|
||||
public GlobalScope globalChild() {
|
||||
public GlobalScope child() {
|
||||
var obj = new ObjectValue();
|
||||
Values.setPrototype(null, obj, this.obj);
|
||||
return new GlobalScope(obj);
|
||||
|
@ -6,6 +6,7 @@ import me.topchetoeu.jscript.common.Filename;
|
||||
import me.topchetoeu.jscript.runtime.Context;
|
||||
import me.topchetoeu.jscript.runtime.Extensions;
|
||||
import me.topchetoeu.jscript.runtime.Key;
|
||||
import me.topchetoeu.jscript.runtime.scope.GlobalScope;
|
||||
import me.topchetoeu.jscript.utils.filesystem.Filesystem;
|
||||
import me.topchetoeu.jscript.utils.filesystem.Mode;
|
||||
|
||||
@ -25,8 +26,10 @@ public interface ModuleRepo {
|
||||
|
||||
if (modules.containsKey(name)) return modules.get(name);
|
||||
|
||||
var env = ctx.extensions.child();
|
||||
var env = Context.clean(ctx.extensions).child();
|
||||
env.add(CWD, fs.normalize(name, ".."));
|
||||
var glob = env.get(GlobalScope.KEY);
|
||||
env.add(GlobalScope.KEY, glob.child());
|
||||
|
||||
var mod = new SourceModule(filename, src, env);
|
||||
modules.put(name, mod);
|
||||
|
Loading…
Reference in New Issue
Block a user