/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
var {
findPlaceholders,
getPath,
} = require("resource://devtools/shared/protocol/utils.js"); var { types } = require("resource://devtools/shared/protocol/types.js");
/** *Managesaresponsetemplate.
*/ class Response { /** *@param{object}template *Theresponsetemplate.
*/
constructor(template = {}) { this.template = template; if (this.template instanceof RetVal && this.template.isArrayType()) { throw Error("Arrays should be wrapped in objects");
}
const placeholders = findPlaceholders(template, RetVal); if (placeholders.length > 1) { throw Error("More than one RetVal specified in response");
} const placeholder = placeholders.shift(); if (placeholder) { this.retVal = placeholder.placeholder; this.path = placeholder.path;
}
} /** *Writearesponseforthegivenreturnvalue. * *@paramvalret *Thereturnvalue. *@param{object}ctx *Theobjectwritingtheresponse.
*/
write(ret, ctx) { // Consider that `template` is either directly a `RetVal`, // or a dictionary with may be one `RetVal`. if (this.template instanceof RetVal) { returnthis.template.write(ret, ctx);
} const result = {}; for (const key in this.template) { const value = this.template[key]; if (value instanceof RetVal) {
result[key] = value.write(ret, ctx);
} else { thrownew Error( "Response can only be a `RetVal` instance or an object " + "with one property being a `RetVal` instance."
);
}
} return result;
}
/** *Placeholderforreturnvaluesinaresponsetemplate.
*/ class RetVal { /** *@paramtypetype *Thereturnvalueshouldbemarshalledasthistype.
*/
constructor(type) { this._type = type; // Prevent force loading all RetVal types by accessing it only when needed
loader.lazyGetter(this, "type", function () { return types.getType(type);
});
}
write(v, ctx) { returnthis.type.write(v, ctx);
}
read(v, ctx) { returnthis.type.read(v, ctx);
}
isArrayType() { // `_type` should always be a string, but a few incorrect RetVal calls // pass `0`. See Bug 1677703. returntypeofthis._type === "string" && this._type.startsWith("array:");
}
}
// Outside of protocol.js, RetVal is called as factory method, without the new keyword.
exports.RetVal = function (type) { returnnew RetVal(type);
};
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet am 2026-08-25)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.