Skip to content

Commit

Permalink
Allow usage of require in the debugger and use ES6
Browse files Browse the repository at this point in the history
  • Loading branch information
andreabergia committed Nov 11, 2024
1 parent 59eb197 commit 7cf4828
Showing 1 changed file with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@

package org.mozilla.javascript.tools.debugger;

import java.io.File;
import java.io.InputStream;
import java.io.PrintStream;
import java.net.URI;
import java.util.List;
import javax.swing.JFrame;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.ContextFactory;
import org.mozilla.javascript.Kit;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.commonjs.module.ModuleScope;
import org.mozilla.javascript.tools.shell.Global;

/**
Expand Down Expand Up @@ -163,20 +167,29 @@ public static void main(String[] args) {
System.setOut(main.getOut());
System.setErr(main.getErr());

Global global = org.mozilla.javascript.tools.shell.Main.getGlobal();
global.setIn(main.getIn());
global.setOut(main.getOut());
global.setErr(main.getErr());

main.attachTo(org.mozilla.javascript.tools.shell.Main.shellContextFactory);
try (Context cx = Context.enter()) {
cx.setLanguageVersion(Context.VERSION_ES6);

main.setScope(global);
Global global = org.mozilla.javascript.tools.shell.Main.getGlobal();
global.init(cx);
global.setIn(main.getIn());
global.setOut(main.getOut());
global.setErr(main.getErr());

main.pack();
main.setSize(600, 460);
main.setVisible(true);
global.installRequire(cx, List.of(), false);

URI uri = new File(System.getProperty("user.dir")).toURI();
ModuleScope scope = new ModuleScope(global, uri, null);

org.mozilla.javascript.tools.shell.Main.exec(args);
main.setScope(scope);

main.pack();
main.setSize(600, 460);
main.setVisible(true);

org.mozilla.javascript.tools.shell.Main.exec(args);
}
}

/**
Expand Down

0 comments on commit 7cf4828

Please sign in to comment.