/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
const l10n = new LocalizationHelper( "devtools/client/locales/components.properties"
); const webl10n = new LocalizationHelper( "devtools/client/locales/webconsole.properties"
);
function savedFrameToLocation(frame) { const { source: url, line, column, sourceId } = frame; return {
url,
line,
column, // The sourceId will be a string if it's a source actor ID, otherwise // it is either a Spidermonkey-internal ID from a SavedFrame or missing, // and in either case we can't use the ID for anything useful.
id: typeof sourceId === "string" ? sourceId : null,
};
}
/** * Get the tooltip message. * @param {string|undefined} messageSource * @param {string} url * @returns {string}
*/ function getTooltipMessage(messageSource, url) { if (messageSource && messageSource === MESSAGE_SOURCE.CSS) { return l10n.getFormatStr("frame.viewsourceinstyleeditor", url);
} return l10n.getFormatStr("frame.viewsourceindebugger", url);
}
class Frame extends Component { static get propTypes() { return { // Optional className that will be put into the element.
className: PropTypes.string, // SavedFrame, or an object containing all the required properties.
frame: PropTypes.shape({
functionDisplayName: PropTypes.string, // This could be a SavedFrame with a numeric sourceId, or it could // be a SavedFrame-like client-side object, in which case the // "sourceId" will be a source actor ID.
sourceId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
source: PropTypes.string.isRequired,
line: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
column: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
}).isRequired, // Clicking on the frame link -- probably should link to the debugger.
onClick: PropTypes.func, // Option to display a function name before the source link.
showFunctionName: PropTypes.bool, // Option to display a function name even if it's anonymous.
showAnonymousFunctionName: PropTypes.bool, // Option to display a host name after the source link.
showHost: PropTypes.bool, // Option to display a host name if the filename is empty or just '/'
showEmptyPathAsHost: PropTypes.bool, // Option to display a full source instead of just the filename.
showFullSourceUrl: PropTypes.bool, // Service to enable the source map feature for console.
sourceMapURLService: PropTypes.object, // The source of the message
messageSource: PropTypes.string,
};
}
componentDidMount() { if (this.props.sourceMapURLService) { const location = savedFrameToLocation(this.props.frame); // Many things that make use of this component either: // a) Pass in no sourceId because they have no way to know. // b) Pass in no sourceId because the actor wasn't created when the // server sent its response. // // and due to that, we need to use subscribeByLocation in order to // handle both cases with an without an ID. this.unsubscribeSourceMapURLService = this.props.sourceMapURLService.subscribeByLocation(
location, this._locationChanged
);
}
}
componentWillUnmount() { if (this.unsubscribeSourceMapURLService) { this.unsubscribeSourceMapURLService();
}
}
// Reparse the URL to determine if we should link this; `getSourceNames` // has already cached this indirectly. We don't want to attempt to // link to "self-hosted" and "(unknown)". // Source mapped sources might not necessary linkable, but they // are still valid in the debugger. // If we have a source ID then we can show the source in the debugger. return !!(
originalLocation ||
generatedLocation.id ||
!!parseURL(generatedLocation.url)
);
};
/** * Get the props of the top element.
*/
#getTopElementProps = () => { const { className } = this.props;
// Exclude all falsy values, including `0`, as line numbers start with 1. if (line) {
url += `:${line}`; // Intentionally exclude 0 if (column) {
url += `:${column}`;
}
}
// Inner el is useful for achieving ellipsis on the left and correct LTR/RTL // ordering. See CSS styles for frame-link-source-[inner] and bug 1290056. const tooltipMessage = getTooltipMessage(messageSource, url);
if (isLinkable) { return {
...sourceElConfig,
onClick: e => { // We always need to prevent the default behavior of <a> link
e.preventDefault(); if (onClick) {
e.stopPropagation();
if (this.#isCurrentLocationLinkable()) { return dom.a(this.#getSourceElementsProps(), sourceElements);
} // If source is not a URL (self-hosted, eval, etc.), don't make // it an anchor link, as we can't link to it. return dom.span(this.#getSourceElementsProps(), sourceElements);
};
// In case of pretty-printed HTML file, we would only get the formatted suffix; replace // it with the full URL instead if (showEmptyPathAsHost && displaySource == ":formatted") {
displaySource = host + displaySource;
}
} elseif (
showEmptyPathAsHost &&
(displaySource === "" || displaySource === "/")
) {
displaySource = host;
}
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 ist noch experimentell.