Skip to content

Commit 5459b35

Browse files
committed
Fix line numbering for invoke instructions.
Line numbering of exceptions now work (better) in optimized mode.
1 parent cfe4eb5 commit 5459b35

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

src/jsifier.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,9 @@ function JSify(data, functionsOnly, givenFunctions) {
693693
}
694694
}
695695
i++;
696-
return JS + (Debugging.on ? Debugging.getComment(line.lineNum) : '');
696+
// invoke instructions span two lines, and the debug info is located
697+
// on the second line, hence the +1
698+
return JS + (Debugging.on ? Debugging.getComment(line.lineNum + (line.intertype === 'invoke' ? 1 : 0)) : '');
697699
})
698700
.join('\n')
699701
.split('\n') // some lines include line breaks

tests/runner.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9625,6 +9625,40 @@ def post(filename):
96259625

96269626
self.build(src, dirname, src_filename, post_build=(None,post))
96279627

9628+
def test_exception_source_map(self):
9629+
if Settings.USE_TYPED_ARRAYS != 2: return self.skip("doesn't pass without typed arrays")
9630+
if '--map' not in Building.COMPILER_TEST_OPTS: Building.COMPILER_TEST_OPTS.append('--map')
9631+
9632+
src = '''
9633+
#include <stdio.h>
9634+
9635+
__attribute__((noinline)) void foo(int i) {
9636+
if (i < 10) throw i; // line 5
9637+
}
9638+
9639+
int main() {
9640+
int i;
9641+
scanf("%d", &i);
9642+
foo(i);
9643+
return 0;
9644+
}
9645+
'''
9646+
9647+
def post(filename):
9648+
import json
9649+
map_filename = filename + '.map'
9650+
mappings = json.loads(jsrun.run_js(
9651+
path_from_root('tools', 'source-maps', 'sourcemap2json.js'),
9652+
tools.shared.NODE_JS, [map_filename]))
9653+
with open(filename) as f: lines = f.readlines()
9654+
for m in mappings:
9655+
if m['originalLine'] == 5 and '__cxa_throw' in lines[m['generatedLine']]:
9656+
return
9657+
assert False, 'Must label throw statements with line numbers'
9658+
9659+
dirname = self.get_dir()
9660+
self.build(src, dirname, os.path.join(dirname, 'src.cpp'), post_build=(None, post))
9661+
96289662
def test_linespecific(self):
96299663
if Settings.ASM_JS: return self.skip('asm always has corrections on')
96309664

tools/eliminator/node_modules/uglify-js/lib/process.js

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)