syntax-parsed-arrow-then-sourcemap-directive.js (1749B)
1 // |reftest| skip-if(!xulRuntime.shell) -- needs Debugger 2 /* 3 * Any copyright is dedicated to the Public Domain. 4 * http://creativecommons.org/licenses/publicdomain/ 5 */ 6 7 //----------------------------------------------------------------------------- 8 var BUGNUMBER = 1596706; 9 var summary = 10 "Properly apply a source map directive that's only tokenized by a syntax " + 11 "parser (because the directive comment appears immediately after an arrow " + 12 "function with expression body)"; 13 14 print(BUGNUMBER + ": " + summary); 15 16 /************** 17 * BEGIN TEST * 18 **************/ 19 20 var g = newGlobal({newCompartment: true}); 21 var dbg = new Debugger(g); 22 23 var script; 24 dbg.onDebuggerStatement = function (frame) 25 { 26 script = frame.script; 27 }; 28 29 function checkSourceMapFor(arrowFunc, sourceMap) 30 { 31 g.evaluate(`${arrowFunc} 32 //# sourceMappingURL=${sourceMap} 33 debugger;`); 34 35 assertEq(script instanceof Debugger.Script, true, 36 "expected a Debugger.Script for " + arrowFunc); 37 38 var source = script.source; 39 assertEq(source instanceof Debugger.Source, true, 40 "expected a Debugger.Source for " + arrowFunc); 41 42 assertEq(source.sourceMapURL, sourceMap, 43 "unexpected source map for " + arrowFunc); 44 } 45 46 // block followed by semicolon 47 checkSourceMapFor("x=>{};", "http://example.com/foo.js"); 48 49 // block not followed by semicolon 50 checkSourceMapFor("x=>{}", "http://example.com/bar.js"); 51 52 // expr followed by semicolon 53 checkSourceMapFor("x=>y;", "http://example.com/baz.js"); 54 55 // expr not followed by semicolon 56 checkSourceMapFor("x=>y", "http://example.com/bar.js"); 57 58 /******************************************************************************/ 59 60 if (typeof reportCompare === "function") 61 reportCompare(true, true); 62 63 print("Tests complete");