Minor fixes in development toolchain

This commit is contained in:
Alexey Andreev 2018-12-25 18:45:26 +03:00
parent 6900fd587c
commit 58c19e3abc
7 changed files with 40 additions and 16 deletions

View File

@ -43,7 +43,7 @@ final class ExprOptimizer {
case LESS: case LESS:
return Expr.binary(BinaryOperation.GREATER_OR_EQUALS, binary.getType(), a, b, expr.getLocation()); return Expr.binary(BinaryOperation.GREATER_OR_EQUALS, binary.getType(), a, b, expr.getLocation());
case LESS_OR_EQUALS: case LESS_OR_EQUALS:
return Expr.binary(BinaryOperation.GREATER, binary.getType(), a, b); return Expr.binary(BinaryOperation.GREATER, binary.getType(), a, b, expr.getLocation());
case GREATER: case GREATER:
return Expr.binary(BinaryOperation.LESS_OR_EQUALS, binary.getType(), a, b, expr.getLocation()); return Expr.binary(BinaryOperation.LESS_OR_EQUALS, binary.getType(), a, b, expr.getLocation());
case GREATER_OR_EQUALS: case GREATER_OR_EQUALS:

View File

@ -14,13 +14,15 @@
* limitations under the License. * limitations under the License.
*/ */
var connected = false;
window.addEventListener("message", function(event) { window.addEventListener("message", function(event) {
if (event.source !== window) { if (event.source !== window) {
return; return;
} }
var data = event.data; var data = event.data;
if (typeof data.teavmDebugger !== "undefined") { if (typeof data.teavmDebugger !== "undefined" && !connected) {
connected = true;
chrome.runtime.sendMessage({ command: "debug", port: data.teavmDebugger.port }); chrome.runtime.sendMessage({ command: "debug", port: data.teavmDebugger.port });
} }
}, false); }, false);

View File

@ -20,10 +20,7 @@
var debugPort = DEBUG_PORT; var debugPort = DEBUG_PORT;
function createWebSocket() { function createWebSocket() {
var loc = window.location; return new WebSocket("ws://WS_PATH");
var newUri = loc.protocol === "https:" ? "wss:" : "ws:";
newUri += "//WS_PATH";
return new WebSocket(newUri);
} }
function createIndicator() { function createIndicator() {
@ -170,15 +167,18 @@
} }
if (debugPort > 0) { if (debugPort > 0) {
var connected = false;
function connectDebugAgent(event) { function connectDebugAgent(event) {
if (event.source !== window) { if (event.source !== window) {
return; return;
} }
var data = event.data; var data = event.data;
if (typeof data.teavmDebuggerRequest !== "undefined") { if (typeof data.teavmDebuggerRequest !== "undefined" && !connected) {
connected = true;
window.postMessage({teavmDebugger: {port: debugPort}}, "*"); window.postMessage({teavmDebugger: {port: debugPort}}, "*");
} }
} }
window.addEventListener("message", connectDebugAgent); window.addEventListener("message", connectDebugAgent);
window.postMessage({teavmDebugger: {port: debugPort}}, "*");
} }
})(); })();

View File

@ -30,4 +30,6 @@ public interface DevServerManager extends Remote {
void cancelBuild() throws RemoteException; void cancelBuild() throws RemoteException;
void addListener(DevServerManagerListener listener) throws RemoteException; void addListener(DevServerManagerListener listener) throws RemoteException;
void removeListener(DevServerManagerListener listener) throws RemoteException;
} }

View File

@ -46,7 +46,7 @@ public class DevServerRunner extends UnicastRemoteObject implements DevServerMan
private int port; private int port;
private Registry registry; private Registry registry;
private DevServer server; private DevServer server;
private List<DevServerManagerListener> listeners = new ArrayList<>(); private final List<DevServerManagerListener> listeners = new ArrayList<>();
private DevServerRunner(DevServer server) throws RemoteException { private DevServerRunner(DevServer server) throws RemoteException {
super(); super();
@ -94,7 +94,16 @@ public class DevServerRunner extends UnicastRemoteObject implements DevServerMan
@Override @Override
public void addListener(DevServerManagerListener listener) { public void addListener(DevServerManagerListener listener) {
listeners.add(listener); synchronized (listeners) {
listeners.add(listener);
}
}
@Override
public void removeListener(DevServerManagerListener listener) {
synchronized (listeners) {
listeners.remove(listener);
}
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
@ -265,10 +274,16 @@ public class DevServerRunner extends UnicastRemoteObject implements DevServerMan
} }
} }
private List<DevServerManagerListener> getListeners() {
synchronized (listeners) {
return new ArrayList<>(listeners);
}
}
final DevServerListener devServerListener = new DevServerListener() { final DevServerListener devServerListener = new DevServerListener() {
@Override @Override
public void compilationStarted() { public void compilationStarted() {
for (DevServerManagerListener listener : listeners) { for (DevServerManagerListener listener : getListeners()) {
try { try {
listener.compilationStarted(); listener.compilationStarted();
} catch (RemoteException e) { } catch (RemoteException e) {
@ -279,7 +294,7 @@ public class DevServerRunner extends UnicastRemoteObject implements DevServerMan
@Override @Override
public void compilationProgress(double v) { public void compilationProgress(double v) {
for (DevServerManagerListener listener : listeners) { for (DevServerManagerListener listener : getListeners()) {
try { try {
listener.compilationProgress(v); listener.compilationProgress(v);
} catch (RemoteException e) { } catch (RemoteException e) {
@ -293,7 +308,7 @@ public class DevServerRunner extends UnicastRemoteObject implements DevServerMan
DevServerBuildResult result = new DevServerBuildResult(); DevServerBuildResult result = new DevServerBuildResult();
result.callGraph = buildResult.getCallGraph(); result.callGraph = buildResult.getCallGraph();
result.problems.addAll(buildResult.getProblems().getProblems()); result.problems.addAll(buildResult.getProblems().getProblems());
for (DevServerManagerListener listener : listeners) { for (DevServerManagerListener listener : getListeners()) {
try { try {
listener.compilationComplete(result); listener.compilationComplete(result);
} catch (RemoteException e) { } catch (RemoteException e) {
@ -304,7 +319,7 @@ public class DevServerRunner extends UnicastRemoteObject implements DevServerMan
@Override @Override
public void compilationCancelled() { public void compilationCancelled() {
for (DevServerManagerListener listener : listeners) { for (DevServerManagerListener listener : getListeners()) {
try { try {
listener.compilationCancelled(); listener.compilationCancelled();
} catch (RemoteException e) { } catch (RemoteException e) {

View File

@ -74,11 +74,15 @@ public class TeaVMDevServerRunner extends GenericProgramRunner<RunnerSettings> {
}); });
runContent = debugSession.getRunContentDescriptor(); runContent = debugSession.getRunContentDescriptor();
ProcessHandler debugProcessHandler = debugSession.getDebugProcess().getProcessHandler(); runContent.getProcessHandler().addProcessListener(new ProcessAdapter() {
debugProcessHandler.addProcessListener(new ProcessAdapter() { @Override
public void startNotified(@NotNull ProcessEvent event) {
processHandler.startNotify();
}
@Override @Override
public void processTerminated(@NotNull ProcessEvent event) { public void processTerminated(@NotNull ProcessEvent event) {
processHandler.destroyProcess(); processHandler.detachProcess();
} }
}); });
} }

View File

@ -96,6 +96,7 @@ public class TeaVMDevServerConsole extends JPanel implements ConsoleView {
} catch (RemoteException e) { } catch (RemoteException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
serverListener = null;
} }
underlyingConsole.dispose(); underlyingConsole.dispose();
} }