diff options
-rw-r--r-- | src/jsifier.js | 4 | ||||
-rwxr-xr-x | tests/runner.py | 34 | ||||
-rw-r--r-- | tools/eliminator/node_modules/uglify-js/lib/process.js | 14 |
3 files changed, 50 insertions, 2 deletions
diff --git a/src/jsifier.js b/src/jsifier.js index 88b9d9f6..7264b0e9 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -693,7 +693,9 @@ function JSify(data, functionsOnly, givenFunctions) { } } i++; - return JS + (Debugging.on ? Debugging.getComment(line.lineNum) : ''); + // invoke instructions span two lines, and the debug info is located + // on the second line, hence the +1 + return JS + (Debugging.on ? Debugging.getComment(line.lineNum + (line.intertype === 'invoke' ? 1 : 0)) : ''); }) .join('\n') .split('\n') // some lines include line breaks diff --git a/tests/runner.py b/tests/runner.py index 156e2bda..479f4824 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -9625,6 +9625,40 @@ def process(filename): self.build(src, dirname, src_filename, post_build=(None,post)) + def test_exception_source_map(self): + if Settings.USE_TYPED_ARRAYS != 2: return self.skip("doesn't pass without typed arrays") + if '--map' not in Building.COMPILER_TEST_OPTS: Building.COMPILER_TEST_OPTS.append('--map') + + src = ''' + #include <stdio.h> + + __attribute__((noinline)) void foo(int i) { + if (i < 10) throw i; // line 5 + } + + int main() { + int i; + scanf("%d", &i); + foo(i); + return 0; + } + ''' + + def post(filename): + import json + map_filename = filename + '.map' + mappings = json.loads(jsrun.run_js( + path_from_root('tools', 'source-maps', 'sourcemap2json.js'), + tools.shared.NODE_JS, [map_filename])) + with open(filename) as f: lines = f.readlines() + for m in mappings: + if m['originalLine'] == 5 and '__cxa_throw' in lines[m['generatedLine']]: + return + assert False, 'Must label throw statements with line numbers' + + dirname = self.get_dir() + self.build(src, dirname, os.path.join(dirname, 'src.cpp'), post_build=(None, post)) + def test_linespecific(self): if Settings.ASM_JS: return self.skip('asm always has corrections on') diff --git a/tools/eliminator/node_modules/uglify-js/lib/process.js b/tools/eliminator/node_modules/uglify-js/lib/process.js index 39ccde37..88ce490f 100644 --- a/tools/eliminator/node_modules/uglify-js/lib/process.js +++ b/tools/eliminator/node_modules/uglify-js/lib/process.js @@ -412,7 +412,19 @@ function gen_code(ast, options) { }; function add_commas(a) { - return a.join("," + space); + var str = a.join("," + space); + if (options.debug) { + // if a line contains more than one comma-separated segment, assign it the + // original line number of the first NodeWithLine segment + for (var i = 0, l = a.length; i < l; i ++) { + var v = a[i]; + if (v instanceof NodeWithLine) { + v.str = str; + return v + } + } + } + return str; }; function parenthesize(expr) { |