From 0cdf960ba51c8b46cc9e38a79843231962def467 Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Sat, 14 Feb 2015 17:18:40 +0400 Subject: [PATCH] Fix Chrome RDP backend --- .../teavm/chromerdp/ChromeRDPDebugger.java | 28 +++++----- .../org/teavm/samples/async/AsyncProgram.java | 52 ++++++++----------- 2 files changed, 38 insertions(+), 42 deletions(-) diff --git a/teavm-chrome-rdp/src/main/java/org/teavm/chromerdp/ChromeRDPDebugger.java b/teavm-chrome-rdp/src/main/java/org/teavm/chromerdp/ChromeRDPDebugger.java index 3738c7a5a..eb8964e2d 100644 --- a/teavm-chrome-rdp/src/main/java/org/teavm/chromerdp/ChromeRDPDebugger.java +++ b/teavm-chrome-rdp/src/main/java/org/teavm/chromerdp/ChromeRDPDebugger.java @@ -465,18 +465,22 @@ public class ChromeRDPDebugger implements JavaScriptDebugger, ChromeRDPExchangeC for (PropertyDescriptorDTO property : properties) { RemoteObjectDTO remoteValue = property.getValue(); RDPValue value; - switch (remoteValue.getType()) { - case "undefined": - value = new RDPValue(this, "undefined", "undefined", null, false); - break; - case "object": - case "function": - value = new RDPValue(this, null, remoteValue.getType(), remoteValue.getObjectId(), true); - break; - default: - value = new RDPValue(this, remoteValue.getValue().asText(), remoteValue.getType(), - remoteValue.getObjectId(), false); - break; + if (remoteValue != null && remoteValue.getType() != null) { + switch (remoteValue.getType()) { + case "undefined": + value = new RDPValue(this, "undefined", "undefined", null, false); + break; + case "object": + case "function": + value = new RDPValue(this, null, remoteValue.getType(), remoteValue.getObjectId(), true); + break; + default: + value = new RDPValue(this, remoteValue.getValue().asText(), remoteValue.getType(), + remoteValue.getObjectId(), false); + break; + } + } else { + value = new RDPValue(this, "null", "null", "null", false); } RDPLocalVariable var = new RDPLocalVariable(property.getName(), value); diff --git a/teavm-samples/teavm-samples-async/src/main/java/org/teavm/samples/async/AsyncProgram.java b/teavm-samples/teavm-samples-async/src/main/java/org/teavm/samples/async/AsyncProgram.java index 89ead77cf..955129369 100644 --- a/teavm-samples/teavm-samples-async/src/main/java/org/teavm/samples/async/AsyncProgram.java +++ b/teavm-samples/teavm-samples-async/src/main/java/org/teavm/samples/async/AsyncProgram.java @@ -15,7 +15,6 @@ */ package org.teavm.samples.async; - /** * * @author Alexey Andreev @@ -28,68 +27,62 @@ public final class AsyncProgram { withoutAsync(); System.out.println(); withAsync(); - - System.out.println(); - - - - final Object lock = new Object(); - - Thread t = new Thread(new Runnable(){ + System.out.println(); + final Object lock = new Object(); + Thread t = new Thread(new Runnable() { @Override public void run() { try { doRun(lock); - } catch (InterruptedException ex){ + } catch (InterruptedException ex) { System.out.println(ex.getMessage()); } } - + }, "Test Thread"); t.start(); - - Thread t2 = new Thread(new Runnable(){ + Thread t2 = new Thread(new Runnable() { @Override public void run() { try { doRun(lock); - } catch (InterruptedException ex){ + } catch (InterruptedException ex) { System.out.println(ex.getMessage()); } } - }, "Test Thread 2"); t2.start(); - System.out.println("Should be main -> Current thread is "+Thread.currentThread().getName()); + + System.out.println("Should be main -> Current thread is " + Thread.currentThread().getName()); System.out.println("Now trying wait..."); - + lock.wait(20000); System.out.println("Finished waiting"); - + } private static void doRun(Object lock) throws InterruptedException { - System.out.println("Current thread is "+Thread.currentThread().getName()); + System.out.println("Current thread is " + Thread.currentThread().getName()); System.out.println("Executing timer task"); Thread.sleep(2000); - System.out.println("Current thread is "+Thread.currentThread().getName()); + System.out.println("Current thread is " + Thread.currentThread().getName()); System.out.println("Calling lock.notify()"); lock.notify(); - System.out.println("Current thread is "+Thread.currentThread().getName()); + System.out.println("Current thread is " + Thread.currentThread().getName()); System.out.println("Finished calling lock.notify()"); Thread.sleep(5000); - System.out.println("Current thread is "+Thread.currentThread().getName()); + System.out.println("Current thread is " + Thread.currentThread().getName()); System.out.println("Finished another 5 second sleep"); - - synchronized(lock){ - System.out.println("Inside locked section of thread "+Thread.currentThread().getName()); + + synchronized (lock) { + System.out.println("Inside locked section of thread " + Thread.currentThread().getName()); Thread.sleep(2000); - System.out.println("Finished locked section of thread "+Thread.currentThread().getName()); + System.out.println("Finished locked section of thread " + Thread.currentThread().getName()); } } - + private static void withoutAsync() { System.out.println("Start sync"); for (int i = 0; i < 20; ++i) { @@ -117,7 +110,7 @@ public final class AsyncProgram { } System.out.println("2nd Thread.sleep in same method"); Thread.sleep(1000); - + System.out.println("Complete async"); System.out.println("Throwing exception"); @@ -133,6 +126,5 @@ public final class AsyncProgram { System.out.println("Thread.yield called"); throw new IllegalStateException(); } - - + }