author | Eugene Ostroukhov <eugeneo@symbian.org> |
Wed, 27 Jan 2010 15:45:27 -0800 | |
changeset 52 | f577ea64429e |
parent 2 | e4420d2515f1 |
permissions | -rw-r--r-- |
2 | 1 |
// Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 |
// Use of this source code is governed by a BSD-style license that can be |
|
3 |
// found in the LICENSE file. |
|
4 |
||
5 |
package org.chromium.debug.ui; |
|
6 |
||
7 |
import org.chromium.debug.core.ChromiumDebugPlugin; |
|
8 |
import org.chromium.debug.core.model.DebugElementImpl; |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
9 |
import org.chromium.debug.core.model.EvaluateContext; |
2 | 10 |
import org.chromium.debug.core.model.Variable; |
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
11 |
import org.chromium.sdk.JsEvaluateContext; |
2 | 12 |
import org.chromium.sdk.JsVariable; |
13 |
import org.eclipse.core.runtime.Status; |
|
14 |
import org.eclipse.debug.core.DebugException; |
|
15 |
import org.eclipse.debug.core.model.IDebugElement; |
|
16 |
import org.eclipse.debug.core.model.IValue; |
|
17 |
import org.eclipse.debug.core.model.IWatchExpressionDelegate; |
|
18 |
import org.eclipse.debug.core.model.IWatchExpressionListener; |
|
19 |
import org.eclipse.debug.core.model.IWatchExpressionResult; |
|
20 |
||
21 |
/** |
|
22 |
* Performs the Watch expression evaluation while debugging Chromium JavaScript. |
|
23 |
*/ |
|
24 |
public class JsWatchExpressionDelegate implements IWatchExpressionDelegate { |
|
25 |
||
26 |
private static final String[] EMPTY_STRINGS = new String[0]; |
|
27 |
||
28 |
private static final class GoodWatchExpressionResult implements IWatchExpressionResult { |
|
29 |
||
30 |
private final Variable variable; |
|
31 |
||
32 |
private final String expression; |
|
33 |
||
34 |
private IValue value; |
|
35 |
||
36 |
private DebugException exception; |
|
37 |
||
38 |
private GoodWatchExpressionResult(Variable variable, String expression) { |
|
39 |
this.variable = variable; |
|
40 |
this.expression = expression; |
|
41 |
} |
|
42 |
||
43 |
public String[] getErrorMessages() { |
|
44 |
return exception == null |
|
45 |
? EMPTY_STRINGS |
|
46 |
: new String[] { exception.getStatus().getMessage() }; |
|
47 |
} |
|
48 |
||
49 |
public DebugException getException() { |
|
50 |
getValue(); |
|
51 |
return exception; |
|
52 |
} |
|
53 |
||
54 |
public String getExpressionText() { |
|
55 |
return expression; |
|
56 |
} |
|
57 |
||
58 |
public synchronized IValue getValue() { |
|
59 |
if (value == null && exception == null) { |
|
60 |
try { |
|
61 |
value = variable.getValue(); |
|
62 |
} catch (DebugException e) { |
|
63 |
this.exception = e; |
|
64 |
} |
|
65 |
} |
|
66 |
return value; |
|
67 |
} |
|
68 |
||
69 |
public boolean hasErrors() { |
|
70 |
getValue(); |
|
71 |
return exception != null; |
|
72 |
} |
|
73 |
} |
|
74 |
||
75 |
private static final class BadWatchExpressionResult implements IWatchExpressionResult { |
|
76 |
||
77 |
private final DebugException exception; |
|
78 |
||
79 |
private final String expressionText; |
|
80 |
||
81 |
private BadWatchExpressionResult(DebugException exception, String expressionText) { |
|
82 |
this.exception = exception; |
|
83 |
this.expressionText = expressionText; |
|
84 |
} |
|
85 |
||
86 |
public String[] getErrorMessages() { |
|
87 |
return new String[] { exception.getStatus().getMessage() }; |
|
88 |
} |
|
89 |
||
90 |
public DebugException getException() { |
|
91 |
return exception; |
|
92 |
} |
|
93 |
||
94 |
public String getExpressionText() { |
|
95 |
return expressionText; |
|
96 |
} |
|
97 |
||
98 |
public IValue getValue() { |
|
99 |
return null; |
|
100 |
} |
|
101 |
||
102 |
public boolean hasErrors() { |
|
103 |
return true; |
|
104 |
} |
|
105 |
} |
|
106 |
||
107 |
public void evaluateExpression(final String expression, final IDebugElement context, |
|
108 |
final IWatchExpressionListener listener) { |
|
109 |
final DebugElementImpl contextImpl = (DebugElementImpl) context; |
|
110 |
if (!contextImpl.getDebugTarget().isSuspended()) { |
|
111 |
// can only evaluate while suspended. Notify empty result. |
|
112 |
listener.watchEvaluationFinished(new IWatchExpressionResult() { |
|
113 |
||
114 |
public String[] getErrorMessages() { |
|
115 |
return EMPTY_STRINGS; |
|
116 |
} |
|
117 |
||
118 |
public DebugException getException() { |
|
119 |
return null; |
|
120 |
} |
|
121 |
||
122 |
public String getExpressionText() { |
|
123 |
return expression; |
|
124 |
} |
|
125 |
||
126 |
public IValue getValue() { |
|
127 |
return null; |
|
128 |
} |
|
129 |
||
130 |
public boolean hasErrors() { |
|
131 |
return false; |
|
132 |
} |
|
133 |
}); |
|
134 |
return; |
|
135 |
} |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
136 |
|
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
137 |
final EvaluateContext evaluateContext = |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
138 |
(EvaluateContext) contextImpl.getAdapter(EvaluateContext.class); |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
139 |
if (evaluateContext == null) { |
2 | 140 |
listener.watchEvaluationFinished(new BadWatchExpressionResult( |
141 |
new DebugException( |
|
142 |
new Status(Status.ERROR, ChromiumDebugUIPlugin.PLUGIN_ID, "Bad debug context")), //$NON-NLS-1$ |
|
143 |
expression)); |
|
144 |
return; |
|
145 |
} |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
146 |
|
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
147 |
evaluateContext.getJsEvaluateContext().evaluateAsync( |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
148 |
expression, |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
149 |
new JsEvaluateContext.EvaluateCallback() { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
150 |
public void success(JsVariable variable) { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
151 |
final Variable var = new Variable(contextImpl.getDebugTarget(), variable, false); |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
152 |
listener.watchEvaluationFinished(new GoodWatchExpressionResult(var, expression)); |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
153 |
} |
2 | 154 |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
155 |
public void failure(String message) { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
156 |
listener.watchEvaluationFinished(new BadWatchExpressionResult(new DebugException( |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
157 |
createErrorStatus(message == null |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
158 |
? Messages.JsWatchExpressionDelegate_ErrorEvaluatingExpression |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
159 |
: message, null)), expression)); |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
160 |
return; |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
161 |
} |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
162 |
}, |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
163 |
null); |
2 | 164 |
} |
165 |
||
166 |
private static Status createErrorStatus(String message, Exception e) { |
|
167 |
return new Status(Status.ERROR, ChromiumDebugPlugin.PLUGIN_ID, message, e); |
|
168 |
} |
|
169 |
||
170 |
} |