Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: dart/editor/tools/plugins/com.google.dart.tools.debug.core/src/com/google/dart/tools/debug/core/webkit/WebkitRemoteObject.java

Issue 328663002: Version 1.5.0-dev.4.5 (Closed) Base URL: http://dart.googlecode.com/svn/trunk/
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012, the Dart project authors. 2 * Copyright (c) 2012, the Dart project authors.
3 * 3 *
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u se this file except 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u se this file except
5 * in compliance with the License. You may obtain a copy of the License at 5 * in compliance with the License. You may obtain a copy of the License at
6 * 6 *
7 * http://www.eclipse.org/legal/epl-v10.html 7 * http://www.eclipse.org/legal/epl-v10.html
8 * 8 *
9 * Unless required by applicable law or agreed to in writing, software distribut ed under the License 9 * Unless required by applicable law or agreed to in writing, software distribut ed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K IND, either express 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K IND, either express
11 * or implied. See the License for the specific language governing permissions a nd limitations under 11 * or implied. See the License for the specific language governing permissions a nd limitations under
12 * the License. 12 * the License.
13 */ 13 */
14 14
15 package com.google.dart.tools.debug.core.webkit; 15 package com.google.dart.tools.debug.core.webkit;
16 16
17 import org.json.JSONException; 17 import org.json.JSONException;
18 import org.json.JSONObject; 18 import org.json.JSONObject;
19 19
20 import java.io.IOException;
21 import java.util.concurrent.CountDownLatch;
22 import java.util.concurrent.TimeUnit;
23
20 /** 24 /**
21 * A WIP scope object. 25 * A WIP scope object.
22 * 26 *
23 * @see http://code.google.com/chrome/devtools/docs/protocol/tot/runtime.html#ty pe-RemoteObject 27 * @see http://code.google.com/chrome/devtools/docs/protocol/tot/runtime.html#ty pe-RemoteObject
24 */ 28 */
25 public class WebkitRemoteObject { 29 public class WebkitRemoteObject {
26 30
27 public static WebkitRemoteObject createFrom(JSONObject params) throws JSONExce ption { 31 public static WebkitRemoteObject createFrom(JSONObject params) throws JSONExce ption {
28 WebkitRemoteObject remoteObject = new WebkitRemoteObject(); 32 WebkitRemoteObject remoteObject = new WebkitRemoteObject();
29 33
(...skipping 26 matching lines...) Expand all
56 private String description; 60 private String description;
57 61
58 private String objectId; 62 private String objectId;
59 63
60 private String subtype; 64 private String subtype;
61 65
62 private String type; 66 private String type;
63 67
64 private String value; 68 private String value;
65 69
70 private int listLength = -1;
71
66 @Override 72 @Override
67 public boolean equals(Object obj) { 73 public boolean equals(Object obj) {
68 if (obj instanceof WebkitRemoteObject) { 74 if (obj instanceof WebkitRemoteObject) {
69 return ((WebkitRemoteObject) obj).getObjectId().equals(getObjectId()); 75 return ((WebkitRemoteObject) obj).getObjectId().equals(getObjectId());
70 } 76 }
71 77
72 return false; 78 return false;
73 } 79 }
74 80
75 public String getClassName() { 81 public String getClassName() {
(...skipping 16 matching lines...) Expand all
92 return null; 98 return null;
93 } 99 }
94 100
95 public String getDescription() { 101 public String getDescription() {
96 return description; 102 return description;
97 } 103 }
98 104
99 /** 105 /**
100 * Return the length of the list if this object is a list. 106 * Return the length of the list if this object is a list.
101 * 107 *
108 * @param webkitConnection
102 * @return 109 * @return
103 */ 110 */
104 public int getListLength() { 111 public int getListLength(WebkitConnection connection) {
105 // TODO(devoncarew): write a test to notify us when this convention changes 112 if (listLength == -1) {
106 113 final CountDownLatch latch = new CountDownLatch(1);
107 // Since there is no direct way to obtain the length of an array, use the de scription from
108 // Dartium to derive the array length. value.getDescription() == "Array[x]"
109
110 String str = getDescription();
111
112 int startIndex = str.indexOf('[');
113 int endIndex = str.indexOf(']', startIndex);
114
115 if (startIndex != -1 && endIndex != -1) {
116 String val = str.substring(startIndex + 1, endIndex);
117 114
118 try { 115 try {
119 return Integer.parseInt(val); 116 connection.getRuntime().callListLength(objectId, new WebkitCallback<Inte ger>() {
120 } catch (NumberFormatException nfe) { 117 @Override
118 public void handleResult(WebkitResult<Integer> result) {
119 if (result.isError()) {
120 listLength = 0;
121 } else {
122 listLength = result.getResult().intValue();
123 }
124
125 latch.countDown();
126 }
127 });
128 } catch (IOException e) {
129 listLength = 0;
130 latch.countDown();
131 }
132
133 try {
134 latch.await(3, TimeUnit.SECONDS);
135 } catch (InterruptedException e) {
121 136
122 } 137 }
123 } 138 }
124 139
125 return 0; 140 return listLength;
126 } 141 }
127 142
128 public String getObjectId() { 143 public String getObjectId() {
129 return objectId; 144 return objectId;
130 } 145 }
131 146
132 /** 147 /**
133 * One of "array", "date", "node", "null", "regexp". 148 * One of "array", "date", "node", "null", "regexp".
134 */ 149 */
135 public String getSubtype() { 150 public String getSubtype() {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 */ 194 */
180 public boolean isLibraryRef() { 195 public boolean isLibraryRef() {
181 if (className == null) { 196 if (className == null) {
182 return false; 197 return false;
183 } 198 }
184 199
185 return className.startsWith("file:") || className.startsWith("http:"); 200 return className.startsWith("file:") || className.startsWith("http:");
186 } 201 }
187 202
188 public boolean isList() { 203 public boolean isList() {
189 return "array".equals(subtype); 204 return "object".equals(type) && "List".equals(className);
190 } 205 }
191 206
192 public boolean isNode() { 207 public boolean isNode() {
193 return "node".equals(subtype); 208 return "node".equals(subtype);
194 } 209 }
195 210
196 public boolean isNull() { 211 public boolean isNull() {
197 if (isObject() && "null".equals(subtype)) { 212 if (isObject() && "null".equals(value)) {
198 return true; 213 return true;
199 } else { 214 } else {
200 return false; 215 return false;
201 } 216 }
202 } 217 }
203 218
204 public boolean isNumber() { 219 public boolean isNumber() {
205 return "number".equals(type); 220 return "number".equals(type);
206 } 221 }
207 222
(...skipping 23 matching lines...) Expand all
231 return "[" + type + "," + description + "]"; 246 return "[" + type + "," + description + "]";
232 } else { 247 } else {
233 return "[" + type + "," + value + "]"; 248 return "[" + type + "," + value + "]";
234 } 249 }
235 } 250 }
236 251
237 void setDescription(String value) { 252 void setDescription(String value) {
238 description = value; 253 description = value;
239 } 254 }
240 } 255 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698