tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

source-url.js (1523B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 /**
      8 * Debugger.Source objects have a `url` property that exposes the value
      9 * that was passed to SpiderMonkey, but unfortunately often SpiderMonkey
     10 * sets a URL even in cases where it doesn't make sense, so we have to
     11 * explicitly ignore the URL value in these contexts to keep things a bit
     12 * more consistent.
     13 *
     14 * @param {Debugger.Source} source
     15 *
     16 * @return {string | null}
     17 */
     18 function getDebuggerSourceURL(source) {
     19  const introType = source.introductionType;
     20 
     21  // These are all the sources that are eval or eval-like, but may still have
     22  // a URL set on the source, so we explicitly ignore the source URL for these.
     23  if (
     24    introType === "injectedScript" ||
     25    introType === "eval" ||
     26    introType === "debugger eval" ||
     27    introType === "Function" ||
     28    introType === "javascriptURL" ||
     29    introType === "eventHandler" ||
     30    introType === "domTimer"
     31  ) {
     32    return null;
     33  }
     34  // When using <iframe srcdoc="<script> js source </script>"/>, we can't easily fetch the srcdoc
     35  // full html text content. So, consider each inline script as independant source with
     36  // their own URL. Thus the ID appended to each URL.
     37  if (source.url == "about:srcdoc") {
     38    return source.url + "#" + source.id;
     39  }
     40 
     41  return source.url;
     42 }
     43 
     44 exports.getDebuggerSourceURL = getDebuggerSourceURL;