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

Unified Diff: plugins/org.chromium.sdk.wipbackend.wk118685/src/org/chromium/sdk/internal/wip/WipContextBuilder.java

Issue 11602013: Redesign scope API, separate declarative and object scopes. (Closed) Base URL: https://chromedevtools.googlecode.com/svn/trunk
Patch Set: patching other backends Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: plugins/org.chromium.sdk.wipbackend.wk118685/src/org/chromium/sdk/internal/wip/WipContextBuilder.java
diff --git a/plugins/org.chromium.sdk.wipbackend.wk118685/src/org/chromium/sdk/internal/wip/WipContextBuilder.java b/plugins/org.chromium.sdk.wipbackend.wk118685/src/org/chromium/sdk/internal/wip/WipContextBuilder.java
index 96f6a4b2d161005e97bcdabcd3898a1b63d126e8..1dedd7b6d5e01368126fa7e801ea22c5ea4d654f 100644
--- a/plugins/org.chromium.sdk.wipbackend.wk118685/src/org/chromium/sdk/internal/wip/WipContextBuilder.java
+++ b/plugins/org.chromium.sdk.wipbackend.wk118685/src/org/chromium/sdk/internal/wip/WipContextBuilder.java
@@ -480,36 +480,42 @@ class WipContextBuilder {
if (type == null) {
type = JsScope.Type.UNKNOWN;
}
- if (type == JsScope.Type.WITH) {
- return new WithScopeImpl(scopeData, valueLoader);
+ if (type == JsScope.Type.WITH || type == JsScope.Type.GLOBAL) {
+ return new ObjectScopeImpl(scopeData, type, valueLoader);
} else {
- return new ScopeImpl(scopeData, type, valueLoader);
+ return new DeclarativeScopeImpl(scopeData, type, valueLoader);
}
}
- private static class ScopeImpl implements JsScope {
+ private static class DeclarativeScopeImpl implements JsScope.Declarative {
private final AsyncFutureRef<Getter<ScopeVariables>> propertiesRef =
new AsyncFutureRef<Getter<ScopeVariables>>();
private final String objectId;
private final Type type;
private final WipValueLoader valueLoader;
- public ScopeImpl(ScopeValue scopeData, Type type, WipValueLoader valueLoader) {
+ public DeclarativeScopeImpl(ScopeValue scopeData, Type type, WipValueLoader valueLoader) {
this.type = type;
this.objectId = scopeData.object().objectId();
this.valueLoader = valueLoader;
}
- @Override
- public Type getType() {
+ @Override public Type getType() {
return type;
}
- @Override
- public WithScope asWithScope() {
+ @Override public Declarative asDeclarativeScope() {
+ return this;
+ }
+
+ @Override public ObjectBased asObjectBased() {
return null;
}
+ @Override public <R> R accept(Visitor<R> visitor) {
+ return visitor.visitDeclarative(this);
+ }
+
@Override
public List<? extends JsVariable> getVariables() throws MethodIsBlockingException {
int currentCacheState = valueLoader.getCacheState();
@@ -582,35 +588,38 @@ class WipContextBuilder {
}
}
- private static class WithScopeImpl implements JsScope.WithScope {
+ private static class ObjectScopeImpl implements JsScope.ObjectBased {
private final JsValue jsValue;
+ private final JsScope.Type type;
- WithScopeImpl(ScopeValue scopeData, WipValueLoader valueLoader) {
+ ObjectScopeImpl(ScopeValue scopeData, JsScope.Type type, WipValueLoader valueLoader) {
jsValue = valueLoader.getValueBuilder().wrap(scopeData.object(), null);
+ this.type = type;
}
- @Override
- public Type getType() {
- return Type.WITH;
+ @Override public Type getType() {
+ return type;
}
- @Override
- public WithScope asWithScope() {
+ @Override public Declarative asDeclarativeScope() {
+ return null;
+ }
+
+ @Override public ObjectBased asObjectBased() {
return this;
}
- @Override
- public List<? extends JsVariable> getVariables() throws MethodIsBlockingException {
- JsObject asObject = jsValue.asObject();
- if (asObject == null) {
- return Collections.emptyList();
- }
- return new ArrayList<JsVariable>(asObject.getProperties());
+ @Override public <R> R accept(Visitor<R> visitor) {
+ return visitor.visitObject(this);
}
@Override
- public JsValue getWithArgument() {
- return jsValue;
+ public JsObject getScopeObject() throws MethodIsBlockingException {
+ JsObject jsObject = jsValue.asObject();
+ if (jsObject == null) {
+ throw new RuntimeException("Received scope object value is not an object");
+ }
+ return jsObject;
}
}

Powered by Google App Engine
This is Rietveld 408576698