mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 1676974 - [devtools] Remove unused protocol/utils.js method() helper r=ochameau
Current implementation ```lang=javascript exports.method = function(fn, spec = {}) { fn._methodSpec = Object.freeze(spec); if (spec.request) { Object.freeze(spec.request); } if (spec.response) { Object.freeze(spec.response); } return fn; }; ``` https://searchfox.org/mozilla-central/rev/5a1a34953a26117f3be1a00db20c8bbdc03273d6/devtools/shared/protocol/utils.js#70-79 The helper method() in protocol/utils.js is only called from two methods: - actorBridge (never used in the codebase) - actorBridgeWithSpec (used by a few actors) actorBridgeWithSpec doesn't pass the second argument, so in practice, this method could be reduced to: ```lang=javascript exports.method = function(fn) { fn._methodSpec = Object.freeze({}); return fn; }; ``` `_methodSpec` is only mentioned in one other spot: https://searchfox.org/mozilla-central/rev/5a1a34953a26117f3be1a00db20c8bbdc03273d6/devtools/shared/protocol/Actor/generateActorSpec.js#27-40 But based on our coverage tooling, we never actually have a `_methodSpec` when we run this code: https://coverage.moz.tools/#view=file&revision=latest&path=devtools/shared/protocol/Actor/generateActorSpec.js To hit it, we would have to call `generateActorSpec` directly with an actor where we used `actorBridgeWithSpec`. But we never do that, we only use it with plain JS objects in the devtools/shared/specs folder. Consequently, this helper can be removed. Differential Revision: https://phabricator.services.mozilla.com/D96935
This commit is contained in:
parent
9dc1dcab9f
commit
3ad6fe2ca8
@ -4,8 +4,6 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
const { method } = require("devtools/shared/protocol");
|
||||
|
||||
/**
|
||||
* A SourceLocation represents a location in a source.
|
||||
*
|
||||
@ -106,28 +104,13 @@ function expectState(expectedState, methodFunc, activity) {
|
||||
exports.expectState = expectState;
|
||||
|
||||
/**
|
||||
* Proxies a call from an actor to an underlying module, stored
|
||||
* as `bridge` on the actor. This allows a module to be defined in one
|
||||
* place, usable by other modules/actors on the server, but a separate
|
||||
* module defining the actor/RDP definition.
|
||||
*
|
||||
* @see Framerate implementation: devtools/server/performance/framerate.js
|
||||
* @see Framerate actor definition: devtools/server/actors/framerate.js
|
||||
*/
|
||||
function actorBridge(methodName, definition = {}) {
|
||||
return method(function() {
|
||||
return this.bridge[methodName].apply(this.bridge, arguments);
|
||||
}, definition);
|
||||
}
|
||||
exports.actorBridge = actorBridge;
|
||||
|
||||
/**
|
||||
* Like `actorBridge`, but without a spec definition, for when the actor is
|
||||
* created with `ActorClassWithSpec` rather than vanilla `ActorClass`.
|
||||
* Autobind method from a `bridge` property set on some actors where the
|
||||
* implementation is delegated to a separate class, and where `bridge` points
|
||||
* to an instance of this class.
|
||||
*/
|
||||
function actorBridgeWithSpec(methodName) {
|
||||
return method(function() {
|
||||
return function() {
|
||||
return this.bridge[methodName].apply(this.bridge, arguments);
|
||||
});
|
||||
};
|
||||
}
|
||||
exports.actorBridgeWithSpec = actorBridgeWithSpec;
|
||||
|
@ -12,7 +12,6 @@ var {
|
||||
getFront,
|
||||
createRootFront,
|
||||
} = require("devtools/shared/protocol/types");
|
||||
var { method } = require("devtools/shared/protocol/utils");
|
||||
var { Front } = require("devtools/shared/protocol/Front");
|
||||
var {
|
||||
FrontClassWithSpec,
|
||||
@ -36,4 +35,3 @@ exports.RetVal = RetVal;
|
||||
exports.registerFront = registerFront;
|
||||
exports.getFront = getFront;
|
||||
exports.createRootFront = createRootFront;
|
||||
exports.method = method;
|
||||
|
@ -17,28 +17,6 @@ var generateActorSpec = function(actorDesc) {
|
||||
methods: [],
|
||||
};
|
||||
|
||||
// Find method and form specifications attached to properties.
|
||||
for (const name of Object.getOwnPropertyNames(actorDesc)) {
|
||||
const desc = Object.getOwnPropertyDescriptor(actorDesc, name);
|
||||
if (!desc.value) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (desc.value._methodSpec) {
|
||||
const methodSpec = desc.value._methodSpec;
|
||||
const spec = {};
|
||||
spec.name = methodSpec.name || name;
|
||||
spec.request = new Request(
|
||||
Object.assign({ type: spec.name }, methodSpec.request || undefined)
|
||||
);
|
||||
spec.response = new Response(methodSpec.response || undefined);
|
||||
spec.release = methodSpec.release;
|
||||
spec.oneway = methodSpec.oneway;
|
||||
|
||||
actorSpec.methods.push(spec);
|
||||
}
|
||||
}
|
||||
|
||||
// Find additional method specifications
|
||||
if (actorDesc.methods) {
|
||||
for (const name in actorDesc.methods) {
|
||||
|
@ -55,25 +55,3 @@ function getPath(obj, path) {
|
||||
return obj;
|
||||
}
|
||||
exports.getPath = getPath;
|
||||
|
||||
/**
|
||||
* Tags a prtotype method as an actor method implementation.
|
||||
*
|
||||
* @param function fn
|
||||
* The implementation function, will be returned.
|
||||
* @param spec
|
||||
* The method specification, with the following (optional) properties:
|
||||
* request (object): a request template.
|
||||
* response (object): a response template.
|
||||
* oneway (bool): 'true' if no response should be sent.
|
||||
*/
|
||||
exports.method = function(fn, spec = {}) {
|
||||
fn._methodSpec = Object.freeze(spec);
|
||||
if (spec.request) {
|
||||
Object.freeze(spec.request);
|
||||
}
|
||||
if (spec.response) {
|
||||
Object.freeze(spec.response);
|
||||
}
|
||||
return fn;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user