Bug 1883449 - [wpt-sync] Update web-platform-tests to bb67daef8e6a384ead5da4c991c12f8...
[gecko.git] / devtools / shared / validate-breakpoint.jsm
blobb065ead7aaa8e89cb55c9e13053bfb8e2b5653e9
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 // Because this function is used from SessionDataHelpers.jsm,
8 // this has to be a JSM.
10 var EXPORTED_SYMBOLS = ["validateBreakpointLocation"];
12 /**
13  * Given a breakpoint location object, throws if the breakpoint look invalid
14  */
15 function validateBreakpointLocation({ sourceUrl, sourceId, line, column }) {
16   if (!sourceUrl && !sourceId) {
17     throw new Error(
18       `Breakpoints expect to have either a sourceUrl or a sourceId.`
19     );
20   }
21   if (sourceUrl && typeof sourceUrl != "string") {
22     throw new Error(
23       `Breakpoints expect to have sourceUrl string, got ${typeof sourceUrl} instead.`
24     );
25   }
26   // sourceId may be undefined for some sources keyed by URL
27   if (sourceId && typeof sourceId != "string") {
28     throw new Error(
29       `Breakpoints expect to have sourceId string, got ${typeof sourceId} instead.`
30     );
31   }
32   if (typeof line != "number") {
33     throw new Error(
34       `Breakpoints expect to have line number, got ${typeof line} instead.`
35     );
36   }
37   if (typeof column != "number") {
38     throw new Error(
39       `Breakpoints expect to have column number, got ${typeof column} instead.`
40     );
41   }
44 // Allow this JSM to also be loaded as a CommonJS module
45 // Because this module is used from the worker thread,
46 // and workers can't load JSMs.
47 if (typeof module == "object") {
48   module.exports.validateBreakpointLocation = validateBreakpointLocation;