/* 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/. */ "use strict";
// The cache used in the `parseURL` function. const gURLStore = new Map(); // The cache used in the `getSourceNames` function. const gSourceNamesStore = new Map();
/** * Takes a string and returns an object containing all the properties * available on an URL instance, with additional properties (fileName), * Leverages caching. * * @param {String} location * @return {Object?} An object containing most properties available * in https://developer.mozilla.org/en-US/docs/Web/API/URL
*/
function parseURL(location) {
let url = gURLStore.get(location);
if (url !== void 0) { return url;
}
try {
url = new URL(location); // The callers were generally written to expect a URL from // sdk/url, which is subtly different. So, work around some // important differences here.
url = {
href: url.href,
protocol: url.protocol,
host: url.host,
hostname: url.hostname,
port: url.port || null,
pathname: url.pathname,
search: url.search,
hash: url.hash,
username: url.username,
password: url.password,
origin: url.origin,
};
/** * Parse a source into a short and long name as well as a host name. * * @param {String} source * The source to parse. Can be a URI or names like "(eval)" or * "self-hosted". * @return {Object} * An object with the following properties: * - {String} short: A short name for the source. * - "http://page.com/test.js#go?q=query" -> "test.js" * - {String} long: The full, long name for the source, with hash/query stripped. * - "http://page.com/test.js#go?q=query" -> "http://page.com/test.js" * - {String?} host: If available, the host name for the source. * - "http://page.com/test.js#go?q=query" -> "page.com"
*/ function getSourceNames(source) { const data = gSourceNamesStore.get(source);
// If `data:...` uri if (isDataScheme(sourceStr)) { const commaIndex = sourceStr.indexOf(","); if (commaIndex > -1) { // The `short` name for a data URI becomes `data:` followed by the actual // encoded content, omitting the MIME type, and charset. short = `data:${sourceStr.substring(commaIndex + 1)}`.slice(0, 100); const result = { short, long: sourceStr };
gSourceNamesStore.set(source, result); return result;
}
}
const parsedUrl = parseURL(sourceStr);
if (!parsedUrl) { // Malformed URI. long = sourceStr; short = sourceStr.slice(0, 100);
} else {
host = parsedUrl.host;
long = parsedUrl.href; if (parsedUrl.hash) { long = long.replace(parsedUrl.hash, "");
} if (parsedUrl.search) { long = long.replace(parsedUrl.search, "");
}
short = parsedUrl.fileName; // If `short` is just a slash, and we actually have a path, // strip the slash and parse again to get a more useful short name. // e.g. "http://foo.com/bar/" -> "bar", rather than "/" if (short === "/" && parsedUrl.pathname !== "/") { short = parseURL(long.replace(/\/$/, "")).fileName;
}
}
if (!short) { if (!long) { long = UNKNOWN_SOURCE_STRING;
} short = long.slice(0, 100);
}
// For the functions below, we assume that we will never access the location // argument out of bounds, which is indeed the vast majority of cases. // // They are written this way because they are hot. Each frame is checked for // being content or chrome when processing the profile.
/** * A utility method to get the file name from a sourcemapped location * The sourcemap location can be in any form. This method returns a * formatted file name for different cases like Windows or OSX. * @param source * @returns String
*/ function getSourceMappedFile(source) { // If sourcemapped source is a OSX path, return // the characters after last "/". // If sourcemapped source is a Windowss path, return // the characters after last "\\". if (source.lastIndexOf("/") >= 0) {
source = source.slice(source.lastIndexOf("/") + 1);
} elseif (source.lastIndexOf("\\") >= 0) {
source = source.slice(source.lastIndexOf("\\") + 1);
} return source;
}
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.