Bug 1883449 - [wpt-sync] Update web-platform-tests to bb67daef8e6a384ead5da4c991c12f8...
[gecko.git] / devtools / shared / path.js
blob759311fdee7c227bedac99eba42536e0e001b5b3
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/. */
5 "use strict";
7 /*
8  * Join all the arguments together and normalize the resulting URI.
9  * The initial path must be an full URI with a protocol (i.e. http://).
10  */
11 exports.joinURI = (initialPath, ...paths) => {
12   let url;
14   try {
15     url = new URL(initialPath);
16   } catch (e) {
17     return null;
18   }
20   for (const path of paths) {
21     if (path) {
22       url = new URL(path, url);
23     }
24   }
26   return url.href;