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

Unified Diff: plugins/org.chromium.sdk/src/org/chromium/sdk/JsScope.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/src/org/chromium/sdk/JsScope.java
diff --git a/plugins/org.chromium.sdk/src/org/chromium/sdk/JsScope.java b/plugins/org.chromium.sdk/src/org/chromium/sdk/JsScope.java
index eea840c381935c63ce1b0235e6137144178e6d34..7cbd32e38a19b12e12af9cdf6fa6e92765c24529 100644
--- a/plugins/org.chromium.sdk/src/org/chromium/sdk/JsScope.java
+++ b/plugins/org.chromium.sdk/src/org/chromium/sdk/JsScope.java
@@ -9,8 +9,8 @@ import java.util.List;
import org.chromium.sdk.util.MethodIsBlockingException;
/**
- * An object that represents a scope in JavaScript.
- * TODO: consider adding object getter for both with and global scopes.
+ * An object that represents a scope in JavaScript. It could be either declarative or object
+ * scope.
*/
public interface JsScope {
@@ -30,24 +30,43 @@ public interface JsScope {
Type getType();
/**
+ * @return optional subtype when type is a native JavaScript scope and null otherwise
+ */
+ Declarative asDeclarativeScope();
+
+ /**
* @return optional subtype when type is {@link Type#WITH} and null otherwise
*/
- WithScope asWithScope();
+ ObjectBased asObjectBased();
+
+ <R> R accept(Visitor<R> visitor);
+
+ interface Visitor<R> {
+ R visitDeclarative(Declarative declarativeScope);
+ R visitObject(ObjectBased objectScope);
+ }
/**
- * @return the variables known in this scope, in lexicographical order
- * @throws MethodIsBlockingException because it may need to load value from remote
+ * Mirrors <i>declarative</i> scope. It's all scopes except 'with' and 'global'. This scope
+ * has a well-defined set of variables.
*/
- List<? extends JsVariable> getVariables() throws MethodIsBlockingException;
+ interface Declarative extends JsScope {
+ /**
+ * @return the variables known in this scope, in lexicographical order
+ * @throws MethodIsBlockingException because it may need to load value from remote
+ */
+ List<? extends JsVariable> getVariables() throws MethodIsBlockingException;
+ }
/**
- * Subtype that exposes the value of the 'with' statement expression (the value might be
- * already converted by ToObject).
+ * Mirrors <i>object</i> scope, i.e. the one built above a JavaScript object. It's either
+ * 'with' or 'global' scope. Such scope contains all properties of the object, including
+ * indirect ones from the prototype chain.
*/
- interface WithScope extends JsScope {
+ interface ObjectBased extends JsScope {
/**
* @throws MethodIsBlockingException because it may need to load value from remote
*/
- JsValue getWithArgument() throws MethodIsBlockingException;
+ JsObject getScopeObject() throws MethodIsBlockingException;
}
}

Powered by Google App Engine
This is Rietveld 408576698