Web Inspector: implement reverse mapping for compiler source maps.
[WebKit.git] / LayoutTests / inspector / debugger / compiler-source-mapping.html
1 <html>
2 <head>
3 <script src="../../http/tests/inspector/inspector-test.js"></script>
4
5 <script>
6
7 function test()
8 {
9     function checkMapping(compiledLineNumber, compiledColumnNumber, sourceURL, sourceLineNumber, sourceColumnNumber, mapping)
10     {
11         var sourceLocation = mapping.compiledLocationToSourceLocation(compiledLineNumber, compiledColumnNumber);
12         InspectorTest.assertEquals(sourceURL, sourceLocation.sourceURL);
13         InspectorTest.assertEquals(sourceLineNumber, sourceLocation.lineNumber);
14         InspectorTest.assertEquals(sourceColumnNumber, sourceLocation.columnNumber);
15     }
16
17     function checkReverseMapping(compiledLineNumber, compiledColumnNumber, sourceURL, sourceLineNumber, mapping)
18     {
19         var compiledLocation = mapping.sourceLocationToCompiledLocation(sourceURL, sourceLineNumber);
20         InspectorTest.assertEquals(compiledLineNumber, compiledLocation.lineNumber);
21         InspectorTest.assertEquals(compiledColumnNumber, compiledLocation.columnNumber);
22     }
23
24     InspectorTest.runTestSuite([
25         function testSimpleMapping(next)
26         {
27             /*
28                 example.js:
29                 0         1         2         3
30                 012345678901234567890123456789012345
31                 function add(variable_x, variable_y)
32                 {
33                     return variable_x + variable_y;
34                 }
35
36                 var global = "foo";
37                 ----------------------------------------
38                 example-compiled.js:
39                 0         1         2         3
40                 012345678901234567890123456789012345
41                 function add(a,b){return a+b}var global="foo";
42             */
43             var mappingPayload = {
44                 "mappings":"AAASA,QAAAA,IAAG,CAACC,CAAD,CAAaC,CAAb,CACZ,CACI,MAAOD,EAAP,CAAoBC,CADxB,CAIA,IAAIC,OAAS;",
45                 "sources":["example.js"]
46             };
47             var mapping = new WebInspector.ClosureCompilerSourceMapping(mappingPayload);
48
49             checkMapping(0, 9, "example.js", 0, 9, mapping);
50             checkMapping(0, 13, "example.js", 0, 13, mapping);
51             checkMapping(0, 15, "example.js", 0, 25, mapping);
52             checkMapping(0, 18, "example.js", 2, 4, mapping);
53             checkMapping(0, 25, "example.js", 2, 11, mapping);
54             checkMapping(0, 27, "example.js", 2, 24, mapping);
55
56             checkReverseMapping(0, 0, "example.js", 0, mapping);
57             checkReverseMapping(0, 17, "example.js", 1, mapping);
58             checkReverseMapping(0, 18, "example.js", 2, mapping);
59             checkReverseMapping(0, 29, "example.js", 4, mapping);
60             checkReverseMapping(0, 29, "example.js", 5, mapping);
61             InspectorTest.assertTrue(!mapping.sourceLocationToCompiledLocation("example.js", 6));
62
63             next();
64         }
65     ]);
66 };
67
68 </script>
69
70 </head>
71
72 <body onload="runTest()">
73 <p>Tests ClosureCompilerSourceMapping.</p>
74 </body>
75 </html>