Browse files

Clean up grip infrastructure, Remove GripClient, rename Grip to Objec…

…Grip, clean up grip cache
  • Loading branch information...
1 parent 3783e17 commit 10d667937f3f45913ad5bd4762ae8c02a9a87221 @janodvarko janodvarko committed Sep 19, 2012
View
25 extension/content/firebug/debugger/commands.js
@@ -2,8 +2,9 @@
define([
"firebug/lib/trace",
+ "firebug/debugger/rdp",
],
-function(FBTrace) {
+function(FBTrace, RDP) {
// ********************************************************************************************* //
// Constants
@@ -28,24 +29,14 @@ function pauseGrip(context, args)
if (!actor)
return "No actor specified";
- var grip = thread.pauseGrip({actor: actor});
- var handler = grip.getPrototypeAndProperties;
- switch (type)
- {
- case "object":
- handler = grip.getPrototypeAndProperties;
- break;
-
- case "function":
- handler = grip.getSignature;
- break;
+ var cache = context.debuggerClient.activeThread.gripCache;
- case "decompile":
- handler = grip.getSource;
- break;
- }
+ var packet = {
+ to: actor,
+ type: type || RDP.DebugProtocolTypes.prototypeAndProperties
+ };
- handler.call(grip, function(response)
+ cache.request(packet).then(function(response)
{
Firebug.Console.log(response);
});
View
85 extension/content/firebug/debugger/gripCache.js
@@ -5,16 +5,15 @@ define([
"firebug/firebug",
"firebug/lib/object",
"firebug/lib/promise",
- "firebug/debugger/gripClient",
"firebug/debugger/grips",
],
-function (FBTrace, Firebug, Obj, Promise, GripClient, Grips) {
+function (FBTrace, Firebug, Obj, Promise, Grips) {
// ********************************************************************************************* //
// Constants
-var gripNull = new Grips.Grip({type: "null"});
-var gripUndefined = new Grips.Grip({type: "undefined"});
+var gripNull = new Grips.ObjectGrip({type: "null"});
+var gripUndefined = new Grips.ObjectGrip({type: "undefined"});
// ********************************************************************************************* //
// GripCache
@@ -23,30 +22,24 @@ function GripCache(connection)
{
this.connection = connection;
+ // Initialization
this.clear();
}
GripCache.prototype =
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
- // Public Cache API
+ // Objects
clear: function()
{
+ for each (var grip in this.grips)
+ grip.valid = false;
+
this.grips = {};
this.signatures = {};
},
- request: function(packet)
- {
- var deferred = Promise.defer();
- this.connection.request(packet, function(response)
- {
- deferred.resolve(response);
- });
- return deferred.promise;
- },
-
getObject: function(grip)
{
if (!grip)
@@ -74,69 +67,17 @@ GripCache.prototype =
},
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+ // Packets
- fetchProperties: function(grip)
- {
- if (FBTrace.DBG_GRIPCACHE)
- FBTrace.sysout("gripCache.fetchProperties; ", grip);
-
- var deferred = Promise.defer();
- var object = this.getObject(grip);
- if (object.loaded)
- return Promise.resolve(object.properties);
-
- var self = this;
- var gripClient = new GripClient(this.connection, grip);
-
- gripClient.getPrototypeAndProperties(function(response)
- {
- object.loaded = true;
- object.properties = Grips.Factory.parseProperties(response.ownProperties, self);
-
- if (FBTrace.DBG_GRIPCACHE)
- FBTrace.sysout("gripCache.onFetchProperties;", object);
-
- deferred.resolve(object.properties);
- });
-
- return deferred.promise;
- },
-
- getSignature: function(grip)
- {
- if (!grip || !grip.actor)
- return null;
-
- var object = this.signatures[grip.actor];
- if (object)
- return object;
-
- object = Grips.Factory.createGrip(grip);
- this.signatures[grip.actor] = object;
-
- return object;
- },
-
- fetchSignature: function(grip)
+ request: function(packet)
{
- if (FBTrace.DBG_GRIPCACHE)
- FBTrace.sysout("gripCache.fetchSignature; ", grip);
+ //xxxHonza: packets should be also cached.
var deferred = Promise.defer();
- var object = this.getSignature(grip);
- if (object.loaded)
- return Promise.resolve(object.signature);
-
- var self = this;
- var gripClient = new GripClient(this.connection, grip);
-
- gripClient.getSignature(function(response)
+ this.connection.request(packet, function(response)
{
- object.loaded = true;
- object.signature = response.name + "(" + response.parameters.join(", ") + ")";
- deferred.resolve(object.signature);
+ deferred.resolve(response);
});
-
return deferred.promise;
},
};
View
155 extension/content/firebug/debugger/gripClient.js
@@ -1,155 +0,0 @@
-/* See license.txt for terms of usage */
-
-define([
- "firebug/lib/object",
- "firebug/lib/options",
- "firebug/debugger/sourceFile",
- "firebug/debugger/rdp",
-],
-function (Obj, Options, SourceFile, RDP) {
-
-// ********************************************************************************************* //
-// Constants and Services
-
-var Cu = Components.utils;
-
-Cu["import"]("resource:///modules/devtools/dbg-client.jsm");
-Cu["import"]("resource:///modules/devtools/dbg-server.jsm");
-
-// ********************************************************************************************* //
-
-/**
- * Grip clients are used to retrieve information about the relevant object.
- *
- * @param aClient DebuggerClient
- * The debugger client parent.
- * @param aGrip object
- * A pause-lifetime object grip returned by the protocol.
- */
-function GripClient(connection, grip)
-{
- this.grip = grip;
- this.connection = connection;
-}
-
-GripClient.prototype =
-{
- getActor: function()
- {
- return this.grip.actor;
- },
-
- _valid: true,
- get valid() { return this._valid; },
- set valid(aValid) { this._valid = !!aValid; },
-
- /**
- * Request the name of the function and its formal parameters.
- *
- * @param onResponse function
- * Called with the request's response.
- */
- getSignature: function GC_getSignature(onResponse)
- {
- if (this.grip["class"] !== "Function")
- throw "getSignature is only valid for function grips.";
-
- var packet = {
- to: this.getActor(),
- type: RDP.DebugProtocolTypes.nameAndParameters
- };
-
- this.connection.request(packet, function (response)
- {
- if (onResponse)
- onResponse(response);
- });
- },
-
- /**
- * Request the names of the properties defined on the object and not its
- * prototype.
- *
- * @param onResponse function Called with the request's response.
- */
- getOwnPropertyNames: function GC_getOwnPropertyNames(onResponse)
- {
- var packet = {
- to: this.getActor(),
- type: RDP.DebugProtocolTypes.ownPropertyNames
- };
-
- this.connection.request(packet, function (response)
- {
- if (onResponse)
- onResponse(response);
- });
- },
-
- /**
- * Request the prototype and own properties of the object.
- *
- * @param onResponse function Called with the request's response.
- */
- getPrototypeAndProperties: function GC_getPrototypeAndProperties(onResponse)
- {
- var packet = {
- to: this.getActor(),
- type: RDP.DebugProtocolTypes.prototypeAndProperties
- };
-
- this.connection.request(packet, function (response)
- {
- if (onResponse)
- onResponse(response);
- });
- },
-
- /**
- * Request the property descriptor of the object's specified property.
- *
- * @param name string The name of the requested property.
- * @param onResponse function Called with the request's response.
- */
- getProperty: function GC_getProperty(name, onResponse)
- {
- var packet = {
- to: this.getActor(),
- type: RDP.DebugProtocolTypes.property,
- name: name
- };
-
- this.connection.request(packet, function (response)
- {
- if (onResponse)
- onResponse(response);
- });
- },
-
- /**
- * Request the prototype of the object.
- *
- * @param onResponse function Called with the request's response.
- */
- getPrototype: function GC_getPrototype(onResponse)
- {
- var packet = {
- to: this.getActor(),
- type: RDP.DebugProtocolTypes.prototype
- };
-
- this.connection.request(packet, function (response)
- {
- if (onResponse)
- onResponse(response);
- });
- }
-};
-
-// ********************************************************************************************* //
-// Registration
-
-return GripClient;
-
-// ********************************************************************************************* //
-});
View
37 extension/content/firebug/debugger/grips.js
@@ -13,14 +13,14 @@ function (FBTrace, Obj, Str, Locale, Promise, RDP) {
// ********************************************************************************************* //
// Object Grip
-function Grip(grip, cache)
+function ObjectGrip(grip, cache)
{
this.grip = grip;
this.cache = cache;
this.properties = null;
}
-Grip.prototype =
+ObjectGrip.prototype =
{
getActor: function()
{
@@ -69,11 +69,16 @@ Grip.prototype =
getProperties: function()
{
+ return this.getPrototypeAndProperties(this.getActor());
+ },
+
+ getPrototypeAndProperties: function(actor)
+ {
if (this.properties)
return this.properties;
var packet = {
- to: this.getActor(),
+ to: actor,
type: RDP.DebugProtocolTypes.prototypeAndProperties
};
@@ -96,7 +101,7 @@ function FunctionGrip(grip, cache)
this.signature = null;
}
-FunctionGrip.prototype = Obj.descend(new Grip(),
+FunctionGrip.prototype = Obj.descend(new ObjectGrip(),
{
toString: function()
{
@@ -155,13 +160,14 @@ function LongString()
// ********************************************************************************************* //
// Scope
-function Scope(grip)
+function Scope(grip, cache)
{
this.grip = grip;
+ this.cache = cache;
this.properties = null;
}
-Scope.prototype = Obj.descend(new Grip(),
+Scope.prototype = Obj.descend(new ObjectGrip(),
{
getName: function()
{
@@ -198,7 +204,8 @@ Scope.prototype = Obj.descend(new Grip(),
{
case "with":
case "object":
- return cache.fetchProperties(this.grip.object);
+ var actor = this.grip.object.actor;
+ return ObjectGrip.prototype.getPrototypeAndProperties.call(this, actor);
case "block":
case "function":
@@ -229,7 +236,7 @@ Property.prototype =
{
var result = false;
- if (this.value instanceof Grip)
+ if (this.value instanceof ObjectGrip)
result = this.value.hasProperties();
//FBTrace.sysout("Property.hasProperties; " + this.name + ", " + result);
@@ -239,23 +246,23 @@ Property.prototype =
getChildren: function()
{
- if (this.value instanceof Grip)
+ if (this.value instanceof ObjectGrip)
return this.value.getProperties();
return [];
},
getValue: function()
{
- if (this.value instanceof Grip)
+ if (this.value instanceof ObjectGrip)
return this.value.getValue();
return this.value;
},
getType: function()
{
- if (this.value instanceof Grip)
+ if (this.value instanceof ObjectGrip)
return this.value.getType();
return typeof(this.value);
@@ -290,7 +297,7 @@ var Factory =
case "Function":
return new FunctionGrip(grip, cache);
}
- return new Grip(grip, cache);
+ return new ObjectGrip(grip, cache);
},
parseProperties: function(ownProperties, cache)
@@ -317,9 +324,9 @@ var Factory =
return result;
},
- createScope: function(grip)
+ createScope: function(grip, cache)
{
- return new Scope(grip);
+ return new Scope(grip, cache);
}
}
@@ -328,7 +335,7 @@ var Factory =
return {
Property: Property,
- Grip: Grip,
+ ObjectGrip: ObjectGrip,
Scope: Scope,
Factory: Factory,
WatchExpression: WatchExpression,
View
1 extension/content/firebug/debugger/main.js
@@ -15,7 +15,6 @@ define([
"firebug/debugger/stackFrame",
"firebug/debugger/stackTrace",
"firebug/debugger/watchPanel",
- "firebug/debugger/gripClient",
"firebug/debugger/gripCache",
"firebug/debugger/commands",
],
View
4 extension/content/firebug/debugger/stackFrame.js
@@ -139,12 +139,14 @@ StackFrame.prototype =
thisScope.name = "this";
this.scopes.push(thisScope);
+ var cache = this.context.debuggerClient.activeThread.gripCache;
+
// Now iterate all parent scopes. This represents the chain of scopes
// in the Watch panel.
var scope = this.nativeFrame.environment;
while (scope)
{
- this.scopes.push(Grips.Factory.createScope(scope));
+ this.scopes.push(Grips.Factory.createScope(scope, cache));
scope = scope.parent;
}
View
36 extension/content/firebug/debugger/threadClient.js
@@ -7,9 +7,8 @@ define([
"firebug/debugger/rdp",
"firebug/debugger/breakpointClient",
"firebug/debugger/gripCache",
- "firebug/debugger/gripClient",
],
-function (Obj, Options, SourceFile, RDP, BreakpointClient, GripCache, GripClient) {
+function (Obj, Options, SourceFile, RDP, BreakpointClient, GripCache) {
// ********************************************************************************************* //
// Constants and Services
@@ -457,36 +456,6 @@ ThreadClient.prototype = Obj.extend(new Firebug.EventSource(),
},
/**
- * Return a GripClient object for the given object grip.
- *
- * @param aGrip object
- * A pause-lifetime object grip returned by the protocol.
- */
- pauseGrip: function DebuggerClient_pauseGrip(aGrip)
- {
- if (!this.pauseGrips)
- this.pauseGrips = {};
-
- if (aGrip.actor in this.pauseGrips)
- return this.pauseGrips[aGrip.actor];
-
- var client = new GripClient(this.connection, aGrip);
- this.pauseGrips[aGrip.actor] = client;
- return client;
- },
-
- /**
- * Invalidate pause-lifetime grip clients and clear the list of
- * current grip clients.
- */
- clearPauseGrips: function DebuggerClient_clearPauseGrips(aPacket)
- {
- for each (var grip in this.pauseGrips)
- grip.valid = false;
- this.pauseGrips = null;
- },
-
- /**
* Handle thread state change by doing necessary cleanup and notifying all
* registered listeners.
*/
@@ -499,9 +468,8 @@ ThreadClient.prototype = Obj.extend(new Firebug.EventSource(),
FBTrace.sysout("threadClient.onThreadState; type: " + packet.type, packet);
this.state = RDP.ThreadStateTypes[packet.type];
- this.clearFrames();
- this.clearPauseGrips();
+ this.clearFrames();
this.gripCache.clear();
if (this.connection.eventsEnabled)

0 comments on commit 10d6679

Please sign in to comment.