browser_source-map.js (4016B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Cover the high level API of these modules: 7 // getOriginalURLs getGeneratedRangesForOriginal functions 8 9 async function assertFixtureOriginalURLs( 10 fixtureName, 11 expectedUrls, 12 testMessage 13 ) { 14 const originalSources = await fetchFixtureSourceMap(fixtureName); 15 const urls = originalSources.map(s => s.url); 16 Assert.deepEqual(urls, expectedUrls, testMessage); 17 } 18 19 add_task(async function testGetOriginalURLs() { 20 await assertFixtureOriginalURLs( 21 "absolute", 22 ["https://example.com/cheese/heart.js"], 23 "Test absolute URL" 24 ); 25 26 await assertFixtureOriginalURLs( 27 "bundle", 28 [ 29 "webpack:///webpack/bootstrap%204ef8c7ec7c1df790781e", 30 "webpack:///entry.js", 31 "webpack:///times2.js", 32 "webpack:///output.js", 33 "webpack:///opts.js", 34 ], 35 "Test source with a url" 36 ); 37 38 await assertFixtureOriginalURLs( 39 "empty", 40 [`${URL_ROOT_SSL}fixtures/heart.js`], 41 "Test empty sourceRoot resolution" 42 ); 43 44 await assertFixtureOriginalURLs( 45 "noroot", 46 [`${URL_ROOT_SSL}fixtures/heart.js`], 47 "Test Non-existing sourceRoot resolution" 48 ); 49 50 await assertFixtureOriginalURLs( 51 "noroot2", 52 [`${URL_ROOT_SSL}fixtures/heart.js`], 53 "Test Non-existing sourceRoot resolution with relative URLs" 54 ); 55 }); 56 57 add_task(async function testGetGeneratedRangesForOriginal() { 58 const originals = await fetchFixtureSourceMap("intermingled-sources"); 59 60 const ranges = await gSourceMapLoader.getGeneratedRangesForOriginal( 61 originals[0].id 62 ); 63 64 Assert.deepEqual( 65 ranges, 66 [ 67 { 68 start: { 69 line: 4, 70 column: 69, 71 }, 72 end: { 73 line: 9, 74 column: Infinity, 75 }, 76 }, 77 { 78 start: { 79 line: 11, 80 column: 0, 81 }, 82 end: { 83 line: 17, 84 column: 3, 85 }, 86 }, 87 { 88 start: { 89 line: 19, 90 column: 18, 91 }, 92 end: { 93 line: 19, 94 column: 22, 95 }, 96 }, 97 { 98 start: { 99 line: 26, 100 column: 0, 101 }, 102 end: { 103 line: 26, 104 column: Infinity, 105 }, 106 }, 107 { 108 start: { 109 line: 28, 110 column: 0, 111 }, 112 end: { 113 line: 28, 114 column: Infinity, 115 }, 116 }, 117 ], 118 "Test the overall generated ranges on the source" 119 ); 120 121 { 122 // Note that we have to clear the source map in order to get the merged ranges, 123 // otherwise we are still fetching the previous unmerged ones! 124 const secondOriginals = await fetchFixtureSourceMap("intermingled-sources"); 125 const mergedRanges = await gSourceMapLoader.getGeneratedRangesForOriginal( 126 secondOriginals[0].id, 127 true 128 ); 129 130 Assert.deepEqual( 131 mergedRanges, 132 [ 133 { 134 start: { 135 line: 4, 136 column: 69, 137 }, 138 end: { 139 line: 28, 140 column: Infinity, 141 }, 142 }, 143 ], 144 "Test the merged generated ranges on the source" 145 ); 146 } 147 }); 148 149 add_task(async function testBaseURLErrorHandling() { 150 const source = { 151 id: "missingmap.js", 152 sourceMapURL: "missingmap.js.map", 153 // Notice the duplicated ":" which cause the error here 154 sourceMapBaseURL: "http:://example.com/", 155 }; 156 157 try { 158 await gSourceMapLoader.getOriginalURLs(source); 159 ok(false, "Should throw"); 160 } catch (e) { 161 // We have to use startsWith as the rest of the message will be the stack trace in the worker thread 162 ok( 163 e.message.startsWith( 164 "URL constructor: http:://example.com/ is not a valid URL." 165 ), 166 "the worker thrown with the right error message" 167 ); 168 ok( 169 e.message.includes( 170 "getOriginalURLs@resource://devtools/client/shared/source-map-loader/source-map.js" 171 ), 172 "Found at least one frame of the stack" 173 ); 174 } 175 });