Index: dart/editor/tools/plugins/com.google.dart.tools.debug.core/src/com/google/dart/tools/debug/core/webkit/WebkitRemoteObject.java |
=================================================================== |
--- dart/editor/tools/plugins/com.google.dart.tools.debug.core/src/com/google/dart/tools/debug/core/webkit/WebkitRemoteObject.java (revision 37109) |
+++ dart/editor/tools/plugins/com.google.dart.tools.debug.core/src/com/google/dart/tools/debug/core/webkit/WebkitRemoteObject.java (working copy) |
@@ -17,6 +17,10 @@ |
import org.json.JSONException; |
import org.json.JSONObject; |
+import java.io.IOException; |
+import java.util.concurrent.CountDownLatch; |
+import java.util.concurrent.TimeUnit; |
+ |
/** |
* A WIP scope object. |
* |
@@ -63,6 +67,8 @@ |
private String value; |
+ private int listLength = -1; |
+ |
@Override |
public boolean equals(Object obj) { |
if (obj instanceof WebkitRemoteObject) { |
@@ -99,30 +105,39 @@ |
/** |
* Return the length of the list if this object is a list. |
* |
+ * @param webkitConnection |
* @return |
*/ |
- public int getListLength() { |
- // TODO(devoncarew): write a test to notify us when this convention changes |
+ public int getListLength(WebkitConnection connection) { |
+ if (listLength == -1) { |
+ final CountDownLatch latch = new CountDownLatch(1); |
- // Since there is no direct way to obtain the length of an array, use the description from |
- // Dartium to derive the array length. value.getDescription() == "Array[x]" |
+ try { |
+ connection.getRuntime().callListLength(objectId, new WebkitCallback<Integer>() { |
+ @Override |
+ public void handleResult(WebkitResult<Integer> result) { |
+ if (result.isError()) { |
+ listLength = 0; |
+ } else { |
+ listLength = result.getResult().intValue(); |
+ } |
- String str = getDescription(); |
+ latch.countDown(); |
+ } |
+ }); |
+ } catch (IOException e) { |
+ listLength = 0; |
+ latch.countDown(); |
+ } |
- int startIndex = str.indexOf('['); |
- int endIndex = str.indexOf(']', startIndex); |
- |
- if (startIndex != -1 && endIndex != -1) { |
- String val = str.substring(startIndex + 1, endIndex); |
- |
try { |
- return Integer.parseInt(val); |
- } catch (NumberFormatException nfe) { |
+ latch.await(3, TimeUnit.SECONDS); |
+ } catch (InterruptedException e) { |
} |
} |
- return 0; |
+ return listLength; |
} |
public String getObjectId() { |
@@ -186,7 +201,7 @@ |
} |
public boolean isList() { |
- return "array".equals(subtype); |
+ return "object".equals(type) && "List".equals(className); |
} |
public boolean isNode() { |
@@ -194,7 +209,7 @@ |
} |
public boolean isNull() { |
- if (isObject() && "null".equals(subtype)) { |
+ if (isObject() && "null".equals(value)) { |
return true; |
} else { |
return false; |