21 */ |
21 */ |
22 class JsObjectImpl extends JsValueImpl implements JsObject { |
22 class JsObjectImpl extends JsValueImpl implements JsObject { |
23 |
23 |
24 private final InternalContext context; |
24 private final InternalContext context; |
25 |
25 |
26 private final String parentFqn; |
26 /** |
|
27 * Fully qualified name of variable holding this object. |
|
28 */ |
|
29 private final String variableFqn; |
27 |
30 |
28 /** |
31 /** |
29 * This constructor implies the lazy resolution of object properties. |
32 * This constructor implies the lazy resolution of object properties. |
30 * |
33 * |
31 * @param context where this instance belongs in |
34 * @param context where this instance belongs in |
32 * @param parentFqn the fully qualified name of the object parent |
35 * @param variableFqn the fully qualified name of the variable holding this object |
33 * @param valueState the value data from the JS VM |
36 * @param valueState the value data from the JS VM |
34 */ |
37 */ |
35 JsObjectImpl(InternalContext context, String parentFqn, ValueMirror valueState) { |
38 JsObjectImpl(InternalContext context, String variableFqn, ValueMirror valueState) { |
36 super(valueState); |
39 super(valueState); |
37 this.context = context; |
40 this.context = context; |
38 this.parentFqn = parentFqn; |
41 this.variableFqn = variableFqn; |
39 } |
42 } |
40 |
43 |
41 public Collection<JsVariableImpl> getProperties() throws MethodIsBlockingException { |
44 public Collection<JsVariableImpl> getProperties() throws MethodIsBlockingException { |
42 return subproperties.getPropertiesLazily(); |
45 return subproperties.getPropertiesLazily(); |
43 } |
46 } |
88 return subproperties.getProperty(name); |
91 return subproperties.getProperty(name); |
89 } |
92 } |
90 |
93 |
91 public String getClassName() { |
94 public String getClassName() { |
92 return getMirror().getClassName(); |
95 return getMirror().getClassName(); |
93 } |
|
94 |
|
95 protected JsVariableImpl.NameDecorator getChildPropertyNameDecorator() { |
|
96 return JsVariableImpl.NameDecorator.NOOP; |
|
97 } |
96 } |
98 |
97 |
99 protected InternalContext getInternalContext() { |
98 protected InternalContext getInternalContext() { |
100 return context; |
99 return context; |
101 } |
100 } |
134 // TODO(peter.rybin) Maybe assert that context is valid here |
133 // TODO(peter.rybin) Maybe assert that context is valid here |
135 |
134 |
136 List<JsVariableImpl> result = new ArrayList<JsVariableImpl>(mirrorProperties.size()); |
135 List<JsVariableImpl> result = new ArrayList<JsVariableImpl>(mirrorProperties.size()); |
137 for (int i = 0; i < mirrorProperties.size(); i++) { |
136 for (int i = 0; i < mirrorProperties.size(); i++) { |
138 ValueMirror mirror = mirrorProperties.get(i); |
137 ValueMirror mirror = mirrorProperties.get(i); |
139 String varName = propertyRefs.get(i).getName(); |
138 Object varName = propertyRefs.get(i).getName(); |
140 String fqn = getFullyQualifiedName(varName); |
139 String fqn = getFullyQualifiedName(varName); |
141 if (fqn == null) { |
140 if (fqn == null) { |
142 continue; |
141 continue; |
143 } |
142 } |
144 result.add(new JsVariableImpl(context, mirror, varName, fqn, |
143 String decoratedName = JsVariableImpl.NameDecorator.decorateVarName(varName); |
145 getNameDecorator())); |
144 result.add(new JsVariableImpl(context, mirror, varName, decoratedName, fqn)); |
146 } |
145 } |
147 return result; |
146 return result; |
148 } |
147 } |
149 |
148 |
150 private String getFullyQualifiedName(String propName) { |
149 private String getFullyQualifiedName(Object propName) { |
151 if (propName.startsWith(".")) { |
150 if (variableFqn == null) { |
152 // ".arguments" is not legal |
|
153 return null; |
151 return null; |
154 } |
152 } |
155 return parentFqn + getNameDecorator().buildAccessSuffix(propName); |
153 if (propName instanceof String) { |
|
154 String propNameStr = (String) propName; |
|
155 if (propNameStr.startsWith(".")) { |
|
156 // ".arguments" is not legal |
|
157 return null; |
|
158 } |
|
159 } |
|
160 return variableFqn + JsVariableImpl.NameDecorator.buildAccessSuffix(propName); |
156 } |
161 } |
157 |
162 |
158 JsVariableImpl getProperty(String propertyName) { |
163 JsVariableImpl getProperty(String propertyName) { |
159 return ensurePropertyMap().get(propertyName); |
164 return ensurePropertyMap().get(propertyName); |
160 } |
165 } |
173 } |
178 } |
174 return properties; |
179 return properties; |
175 } |
180 } |
176 } |
181 } |
177 |
182 |
178 abstract JsVariableImpl.NameDecorator getNameDecorator(); |
|
179 abstract List<? extends PropertyReference> getPropertyRefs( |
183 abstract List<? extends PropertyReference> getPropertyRefs( |
180 SubpropertiesMirror subpropertiesMirror); |
184 SubpropertiesMirror subpropertiesMirror); |
181 } |
185 } |
182 |
186 |
183 private final Subproperties subproperties = new Subproperties() { |
187 private final Subproperties subproperties = new Subproperties() { |
184 @Override |
|
185 JsVariableImpl.NameDecorator getNameDecorator() { |
|
186 return getChildPropertyNameDecorator(); |
|
187 } |
|
188 @Override |
188 @Override |
189 List<? extends PropertyReference> getPropertyRefs(SubpropertiesMirror subpropertiesMirror) { |
189 List<? extends PropertyReference> getPropertyRefs(SubpropertiesMirror subpropertiesMirror) { |
190 return subpropertiesMirror.getProperties(); |
190 return subpropertiesMirror.getProperties(); |
191 } |
191 } |
192 }; |
192 }; |
193 |
193 |
194 private final Subproperties internalProperties = new Subproperties() { |
194 private final Subproperties internalProperties = new Subproperties() { |
195 @Override |
195 @Override |
196 JsVariableImpl.NameDecorator getNameDecorator() { |
|
197 return JsVariableImpl.NameDecorator.NOOP; |
|
198 } |
|
199 @Override |
|
200 List<? extends PropertyReference> getPropertyRefs(SubpropertiesMirror subpropertiesMirror) { |
196 List<? extends PropertyReference> getPropertyRefs(SubpropertiesMirror subpropertiesMirror) { |
201 return subpropertiesMirror.getInternalProperties(); |
197 return subpropertiesMirror.getInternalProperties(); |
202 } |
198 } |
203 }; |
199 }; |
204 } |
200 } |