Bug 1515862 - Remove protocol.js's formType. r=jdescottes

None of our actor define a `formType` in its specification.
This feature has never been used, so remove it and its test.

Differential Revision: https://phabricator.services.mozilla.com/D17612

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Alexandre Poirot 2019-01-28 18:42:33 +00:00
Родитель d257d1d3f5
Коммит 385ac7de96
3 изменённых файлов: 3 добавлений и 213 удалений

Просмотреть файл

@ -1,182 +0,0 @@
"use strict";
var protocol = require("devtools/shared/protocol");
var {RetVal} = protocol;
protocol.types.addActorType("child");
protocol.types.addActorType("root");
const childSpec = protocol.generateActorSpec({
typeName: "child",
methods: {
getChild: {
response: RetVal("child"),
},
},
});
// The child actor doesn't provide a form description
var ChildActor = protocol.ActorClassWithSpec(childSpec, {
initialize(conn) {
protocol.Actor.prototype.initialize.call(this, conn);
},
form(detail) {
return {
actor: this.actorID,
extra: "extra",
};
},
getChild: function() {
return this;
},
});
class ChildFront extends protocol.FrontClassWithSpec(childSpec) {
form(v, ctx, detail) {
this.extra = v.extra;
}
}
protocol.registerFront(ChildFront);
const rootSpec = protocol.generateActorSpec({
typeName: "root",
// Basic form type, relies on implicit DictType creation
formType: {
childActor: "child",
},
// This detail uses explicit DictType creation
"formType#detail1": protocol.types.addDictType("RootActorFormTypeDetail1", {
detailItem: "child",
}),
// This detail a string type.
"formType#actorid": "string",
methods: {
getDefault: {
response: RetVal("root"),
},
getDetail1: {
response: RetVal("root#detail1"),
},
getDetail2: {
response: {
item: RetVal("root#actorid"),
},
},
getUnknownDetail: {
response: RetVal("root#unknownDetail"),
},
},
});
// The root actor does provide a form description.
var RootActor = protocol.ActorClassWithSpec(rootSpec, {
initialize(conn) {
protocol.Actor.prototype.initialize.call(this, conn);
this.manage(this);
this.child = new ChildActor();
},
sayHello() {
return {
from: "root",
applicationType: "xpcshell-tests",
traits: [],
};
},
form(detail) {
if (detail === "detail1") {
return {
actor: this.actorID,
detailItem: this.child,
};
} else if (detail === "actorid") {
return this.actorID;
}
return {
actor: this.actorID,
childActor: this.child,
};
},
getDefault: function() {
return this;
},
getDetail1: function() {
return this;
},
getDetail2: function() {
return this;
},
getUnknownDetail: function() {
return this;
},
});
class RootFront extends protocol.FrontClassWithSpec(rootSpec) {
constructor(client) {
super(client);
this.actorID = "root";
// Root owns itself.
this.manage(this);
}
form(v, ctx, detail) {
this.lastForm = v;
}
}
const run_test = Test(async function() {
DebuggerServer.createRootActor = (conn => {
return RootActor(conn);
});
DebuggerServer.init();
const connection = DebuggerServer.connectPipe();
const conn = new DebuggerClient(connection);
const client = Async(conn);
await client.connect();
// DebuggerClient.connect() will instantiate the regular RootFront
// which will override the one we just registered and mess up with this test.
// So override it again with test one before asserting.
protocol.types.registeredTypes.get("root").actorSpec = rootSpec;
const rootFront = new RootFront(conn);
// Trigger some methods that return forms.
let retval = await rootFront.getDefault();
Assert.ok(retval instanceof RootFront);
Assert.ok(rootFront.lastForm.childActor instanceof ChildFront);
retval = await rootFront.getDetail1();
Assert.ok(retval instanceof RootFront);
Assert.ok(rootFront.lastForm.detailItem instanceof ChildFront);
retval = await rootFront.getDetail2();
Assert.ok(retval instanceof RootFront);
Assert.ok(typeof (rootFront.lastForm) === "string");
// getUnknownDetail should fail, since no typeName is specified.
try {
await rootFront.getUnknownDetail();
Assert.ok(false);
} catch (ex) {
// empty
}
await client.close();
});

Просмотреть файл

@ -101,7 +101,6 @@ skip-if = coverage # bug 1336670
[test_protocol_abort.js] [test_protocol_abort.js]
[test_protocol_async.js] [test_protocol_async.js]
[test_protocol_children.js] [test_protocol_children.js]
[test_protocol_formtype.js]
[test_protocol_longstring.js] [test_protocol_longstring.js]
[test_protocol_onFront.js] [test_protocol_onFront.js]
[test_protocol_simple.js] [test_protocol_simple.js]

Просмотреть файл

@ -341,7 +341,7 @@ types.addActorType = function(name) {
ctx.marshallPool().manage(front); ctx.marshallPool().manage(front);
} }
v = type.formType(detail).read(v, front, detail); v = identityWrite(v);
front.form(v, detail, ctx); front.form(v, detail, ctx);
return front; return front;
@ -353,28 +353,12 @@ types.addActorType = function(name) {
if (!v.actorID) { if (!v.actorID) {
ctx.marshallPool().manage(v); ctx.marshallPool().manage(v);
} }
return type.formType(detail).write(v.form(detail), ctx, detail); return identityWrite(v.form(detail));
} }
// Writing a request from the client side, just send the actor id. // Writing a request from the client side, just send the actor id.
return v.actorID; return v.actorID;
}, },
formType: (detail) => {
if (!("formType" in type.actorSpec)) {
return types.Primitive;
}
let formAttr = "formType";
if (detail) {
formAttr += "#" + detail;
}
if (!(formAttr in type.actorSpec)) {
throw new Error("No type defined for " + formAttr);
}
return type.actorSpec[formAttr];
},
}); });
return type; return type;
}; };
@ -1118,17 +1102,6 @@ var generateActorSpec = function(actorDesc) {
continue; continue;
} }
if (name.startsWith("formType")) {
if (typeof (desc.value) === "string") {
actorSpec[name] = types.getType(desc.value);
} else if (desc.value.name && registeredTypes.has(desc.value.name)) {
actorSpec[name] = desc.value;
} else {
// Shorthand for a newly-registered DictType.
actorSpec[name] = types.addDictType(actorDesc.typeName + "__" + name, desc.value);
}
}
if (desc.value._methodSpec) { if (desc.value._methodSpec) {
const methodSpec = desc.value._methodSpec; const methodSpec = desc.value._methodSpec;
const spec = {}; const spec = {};
@ -1312,7 +1285,7 @@ class Front extends Pool {
// protocol.js, in which case this can probably go away. // protocol.js, in which case this can probably go away.
if (form) { if (form) {
this.actorID = form.actor; this.actorID = form.actor;
form = types.getType(this.typeName).formType(detail).read(form, this, detail); form = identityWrite(form);
this.form(form, detail, context); this.form(form, detail, context);
} }
} }