entTypeRep, WindowRep, ObjectWithText, ObjectWithURL, ErrorRep, GripArray, GripMap, GripEntry, Grip, Undefined, Null, StringRep, NumberRep, BigIntRep, SymbolRep, InfinityRep, NaNRep, Accessor, ]; // Reps for rendering of native object reference (e.g. used from the JSONViewer, Netmonitor, …) const noGripReps = [ StringRep, JsonNumber, NumberRep, ArrayRep, Undefined, Null, Obj, ]; /** * Generic rep that is used for rendering native JS types or an object. * The right template used for rendering is picked automatically according * to the current value type. The value must be passed in as the 'object' * property. */ const Rep = function (props) { const { object, defaultRep } = props; const rep = getRep( object, defaultRep, props.noGrip, props.mayUseCustomFormatter ); return rep({ ...props, // To avoid circulary dependencies, pass down `Rep` via Props. // Clone `props` as this object is frozen when using Debug versions of React. Rep, }); }; const exportedReps = { Accessible, Accessor, ArrayRep, Attribute, BigInt: BigIntRep, CommentNode, DateTime, Document: DocumentRep, DocumentType: DocumentTypeRep, ElementNode, ErrorRep, Event: EventRep, Func, Grip, GripArray, GripMap, GripEntry, InfinityRep, NaNRep, Null, Number: NumberRep, Obj, ObjectWithText, ObjectWithURL, PromiseRep, RegExp: RegExpRep, Rep, StringRep, StyleSheet: StyleSheetRep, SymbolRep, TextNode, Undefined, WindowRep, }; // Custom Formatters // Services.prefs isn't available in jsonviewer. It doesn't matter as we don't want to use // custom formatters there if (typeof Services == "object" && Services?.prefs) { const useCustomFormatters = Services.prefs.getBoolPref( "devtools.custom-formatters.enabled", false ); if (useCustomFormatters) { reps.unshift(CustomFormatter); exportedReps.CustomFormatter = CustomFormatter; } } // Helpers /** * Return a rep object that is responsible for rendering given * object. * * @param object {Object} Object to be rendered in the UI. This * can be generic JS object as well as a grip (handle to a remote * debuggee object). * * @param defaultRep {React.Component} The default template * that should be used to render given object if none is found. * * @param noGrip {Boolean} If true, will only check reps not made for remote * objects. * * @param mayUseCustomFormatter {Boolean} If true, custom formatters are * allowed to be used as rep. */ function getRep( object, defaultRep = Grip, noGrip = false, mayUseCustomFormatter = false ) { const repsList = noGrip ? noGripReps : reps; for (const rep of repsList) { if (rep === exportedReps.CustomFormatter && !mayUseCustomFormatter) { continue; } try { // supportsObject could return weight (not only true/false // but a number), which would allow to priorities templates and // support better extensibility. if (rep.supportsObject(object, noGrip)) { return rep.rep; } } catch (err) { console.error(err); } } return defaultRep.rep; } export { Rep, exportedReps as REPS, getRep }; PK