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.HashMap; |
|
9 |
import java.util.List; |
|
10 |
import java.util.Map; |
|
11 |
||
12 |
import org.chromium.sdk.JsScope; |
|
13 |
import org.chromium.sdk.JsVariable; |
|
14 |
||
15 |
/** |
|
16 |
* A generic implementation of the JsScope interface. |
|
17 |
*/ |
|
18 |
public class JsScopeImpl implements JsScope { |
|
19 |
||
20 |
private final CallFrameImpl callFrameImpl; |
|
21 |
private final ScopeMirror mirror; |
|
22 |
private List<JsVariable> properties = null; |
|
23 |
||
24 |
public JsScopeImpl(CallFrameImpl callFrameImpl, ScopeMirror mirror) { |
|
25 |
this.callFrameImpl = callFrameImpl; |
|
26 |
this.mirror = mirror; |
|
27 |
} |
|
28 |
||
29 |
public Type getType() { |
|
30 |
Type type = CODE_TO_TYPE.get(mirror.getType()); |
|
31 |
if (type == null) { |
|
32 |
type = Type.UNKNOWN; |
|
33 |
} |
|
34 |
return type; |
|
35 |
} |
|
36 |
||
37 |
public synchronized List<? extends JsVariable> getVariables() { |
|
38 |
if (properties == null) { |
|
39 |
ValueLoader valueLoader = callFrameImpl.getInternalContext().getValueLoader(); |
|
40 |
List<? extends PropertyReference> propertyRefs = |
|
41 |
valueLoader.loadScopeFields(mirror.getIndex(), callFrameImpl.getIdentifier()); |
|
42 |
List<ValueMirror> propertyMirrors = valueLoader.getOrLoadValueFromRefs(propertyRefs); |
|
43 |
||
44 |
properties = new ArrayList<JsVariable>(propertyMirrors.size()); |
|
45 |
for (int i = 0; i < propertyMirrors.size(); i++) { |
|
276
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
52
diff
changeset
|
46 |
// 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
|
47 |
String varNameStr = propertyRefs.get(i).getName().toString(); |
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
48 |
properties.add(new JsVariableImpl(callFrameImpl.getInternalContext(), |
276
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
52
diff
changeset
|
49 |
propertyMirrors.get(i), varNameStr)); |
2 | 50 |
} |
51 |
} |
|
52 |
return properties; |
|
53 |
} |
|
54 |
||
55 |
private static final Map<Integer, Type> CODE_TO_TYPE; |
|
56 |
static { |
|
57 |
CODE_TO_TYPE = new HashMap<Integer, Type>(); |
|
58 |
CODE_TO_TYPE.put(0, Type.GLOBAL); |
|
59 |
CODE_TO_TYPE.put(1, Type.LOCAL); |
|
60 |
CODE_TO_TYPE.put(2, Type.WITH); |
|
61 |
CODE_TO_TYPE.put(3, Type.CLOSURE); |
|
62 |
CODE_TO_TYPE.put(4, Type.CATCH); |
|
63 |
} |
|
64 |
} |