author | Eugene Ostroukhov <eugeneo@symbian.org> |
Mon, 07 Jun 2010 16:51:19 -0700 | |
changeset 355 | 8726e95bcbba |
parent 276 | f2f4a1259de8 |
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.sdk.internal; |
|
6 |
||
7 |
import java.util.ArrayList; |
|
8 |
import java.util.Collection; |
|
9 |
import java.util.Collections; |
|
10 |
import java.util.List; |
|
11 |
||
12 |
import org.chromium.sdk.CallFrame; |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
13 |
import org.chromium.sdk.JsEvaluateContext; |
2 | 14 |
import org.chromium.sdk.JsScope; |
15 |
import org.chromium.sdk.JsVariable; |
|
16 |
import org.chromium.sdk.Script; |
|
17 |
||
18 |
/** |
|
19 |
* A generic implementation of the CallFrame interface. |
|
20 |
*/ |
|
21 |
public class CallFrameImpl implements CallFrame { |
|
22 |
||
23 |
/** The frame ID as reported by the JavaScript VM. */ |
|
24 |
private final int frameId; |
|
25 |
||
26 |
/** The debug context this call frame belongs in. */ |
|
27 |
private final InternalContext context; |
|
28 |
||
29 |
/** The underlying frame data from the JavaScript VM. */ |
|
30 |
private final FrameMirror frameMirror; |
|
31 |
||
32 |
/** The variables known in this call frame. */ |
|
33 |
private Collection<JsVariableImpl> variables = null; |
|
34 |
||
35 |
/** The scopes known in this call frame. */ |
|
36 |
private List<? extends JsScope> scopes = null; |
|
37 |
||
38 |
/** The receiver variable known in this call frame. May be null. */ |
|
39 |
private JsVariable receiverVariable; |
|
40 |
private boolean receiverVariableLoaded = false; |
|
41 |
||
42 |
/** |
|
43 |
* Constructs a call frame for the given handler using the FrameMirror data |
|
44 |
* from the remote JavaScript VM. |
|
45 |
* |
|
46 |
* @param mirror frame in the VM |
|
47 |
* @param index call frame id (0 is the stack top) |
|
48 |
* @param context in which the call frame is created |
|
49 |
*/ |
|
50 |
public CallFrameImpl(FrameMirror mirror, int index, InternalContext context) { |
|
51 |
this.context = context; |
|
52 |
this.frameId = index; |
|
53 |
this.frameMirror = mirror; |
|
54 |
} |
|
55 |
||
56 |
public InternalContext getInternalContext() { |
|
57 |
return context; |
|
58 |
} |
|
59 |
||
60 |
@Deprecated |
|
61 |
public Collection<JsVariableImpl> getVariables() { |
|
62 |
ensureVariables(); |
|
63 |
return variables; |
|
64 |
} |
|
65 |
||
66 |
public List<? extends JsScope> getVariableScopes() { |
|
67 |
ensureScopes(); |
|
68 |
return scopes; |
|
69 |
} |
|
70 |
||
71 |
public JsVariable getReceiverVariable() { |
|
72 |
ensureReceiver(); |
|
73 |
return this.receiverVariable; |
|
74 |
} |
|
75 |
||
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
76 |
public JsEvaluateContext getEvaluateContext() { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
77 |
return evaluateContextImpl; |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
78 |
} |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
79 |
|
2 | 80 |
private void ensureVariables() { |
81 |
if (variables == null) { |
|
82 |
this.variables = Collections.unmodifiableCollection(createVariables()); |
|
83 |
} |
|
84 |
} |
|
85 |
||
86 |
private void ensureScopes() { |
|
87 |
if (scopes == null) { |
|
88 |
this.scopes = Collections.unmodifiableList(createScopes()); |
|
89 |
} |
|
90 |
} |
|
91 |
||
92 |
private void ensureReceiver() { |
|
93 |
if (!receiverVariableLoaded) { |
|
94 |
PropertyReference ref = frameMirror.getReceiverRef(); |
|
95 |
if (ref == null) { |
|
96 |
this.receiverVariable = null; |
|
97 |
} else { |
|
98 |
ValueLoader valueLoader = context.getValueLoader(); |
|
99 |
ValueMirror mirror = |
|
100 |
valueLoader.getOrLoadValueFromRefs(Collections.singletonList(ref)).get(0); |
|
276
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
52
diff
changeset
|
101 |
// This name should be string. We are making it string as a fall-back strategy. |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
52
diff
changeset
|
102 |
String varNameStr = ref.getName().toString(); |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
52
diff
changeset
|
103 |
this.receiverVariable = new JsVariableImpl(this.context, mirror, varNameStr); |
2 | 104 |
} |
105 |
this.receiverVariableLoaded = true; |
|
106 |
} |
|
107 |
} |
|
108 |
||
109 |
public int getLineNumber() { |
|
110 |
Script script = frameMirror.getScript(); |
|
111 |
// Recalculate respective to the script start |
|
112 |
// (frameMirror.getLine() returns the line offset in the resource). |
|
113 |
return script != null |
|
114 |
? frameMirror.getLine() - script.getStartLine() |
|
115 |
: -1; |
|
116 |
} |
|
117 |
||
118 |
public int getCharStart() { |
|
119 |
return -1; |
|
120 |
} |
|
121 |
||
122 |
public int getCharEnd() { |
|
123 |
return -1; |
|
124 |
} |
|
125 |
||
126 |
public String getFunctionName() { |
|
127 |
return frameMirror.getFunctionName(); |
|
128 |
} |
|
129 |
||
130 |
public Script getScript() { |
|
131 |
return frameMirror.getScript(); |
|
132 |
} |
|
133 |
||
134 |
/** |
|
135 |
* @return this call frame's unique identifier within the V8 VM (0 is the top |
|
136 |
* frame) |
|
137 |
*/ |
|
138 |
int getIdentifier() { |
|
139 |
return frameId; |
|
140 |
} |
|
141 |
||
142 |
/** |
|
143 |
* Initializes this frame with variables based on the frameMirror locals. |
|
144 |
*/ |
|
145 |
private Collection<JsVariableImpl> createVariables() { |
|
146 |
List<PropertyReference> refs = frameMirror.getLocals(); |
|
147 |
List<ValueMirror> mirrors = context.getValueLoader().getOrLoadValueFromRefs(refs); |
|
148 |
Collection<JsVariableImpl> result = new ArrayList<JsVariableImpl>(refs.size()); |
|
149 |
for (int i = 0; i < refs.size(); i++) { |
|
276
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
52
diff
changeset
|
150 |
// This name should be string. We are making it string as a fall-back strategy. |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
52
diff
changeset
|
151 |
String varNameStr = refs.get(i).getName().toString(); |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
52
diff
changeset
|
152 |
result.add(new JsVariableImpl(this.context, mirrors.get(i), varNameStr)); |
2 | 153 |
} |
154 |
return result; |
|
155 |
} |
|
156 |
||
157 |
private List<JsScopeImpl> createScopes() { |
|
158 |
List<ScopeMirror> scopes = frameMirror.getScopes(); |
|
159 |
List<JsScopeImpl> result = new ArrayList<JsScopeImpl>(scopes.size()); |
|
160 |
for (ScopeMirror mirror : scopes) { |
|
161 |
result.add(new JsScopeImpl(this, mirror)); |
|
162 |
} |
|
163 |
return result; |
|
164 |
} |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
165 |
|
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
166 |
private final JsEvaluateContextImpl evaluateContextImpl = new JsEvaluateContextImpl() { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
167 |
@Override |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
168 |
protected Integer getFrameIdentifier() { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
169 |
return getIdentifier(); |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
170 |
} |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
171 |
@Override |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
172 |
public InternalContext getInternalContext() { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
173 |
return context; |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
174 |
} |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
175 |
}; |
2 | 176 |
} |