diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-01-10 18:41:38 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-01-10 18:41:38 -0800 |
commit | ed02667266b2bb5d11db9c9639427beaa8ee5c88 (patch) | |
tree | b88cc7e5a6cb60e3a6799f3683fdfff9f296ee25 | |
parent | f4e239ed21d9f6ea79693f003f2d595143937108 (diff) |
fix fix_closure bug with the relevant line being split over several lines
-rw-r--r-- | tests/runner.py | 2 | ||||
-rwxr-xr-x | tools/fix_closure.py | 54 |
2 files changed, 27 insertions, 29 deletions
diff --git a/tests/runner.py b/tests/runner.py index 86162476..507a422d 100644 --- a/tests/runner.py +++ b/tests/runner.py @@ -5473,7 +5473,7 @@ f.close() expected = path_from_root('tests', 'test-fix-closure.out.js') Popen(['python', path_from_root('tools', 'fix_closure.py'), input, 'out.js']).communicate(input) output = open('out.js').read() - assert '0,uninline_Q_269,0' in output + assert '0,uninline_Q_14782,0' in output assert 'function(a,c)' not in output # should be uninlined, so it gets a name assert run_js(input) == run_js('out.js') diff --git a/tools/fix_closure.py b/tools/fix_closure.py index 086dddfa..d6a64b22 100755 --- a/tools/fix_closure.py +++ b/tools/fix_closure.py @@ -48,35 +48,33 @@ class ObjectParser: string = 0 i += 1 -lines = infile.readlines() -i = 0 -while i < len(lines): - line = lines[i] - curr = line.find('=[0,0,') - if curr > 0: - # a suspect - target = line[curr-1] - curr += 5 - parser = ObjectParser() - add = [] - while line[curr] != ']': - assert line[curr] == ',' +line = infile.read() +curr = 0 +while True: + curr = line.find('=[0,0,', curr) + if curr < 0: break + # a suspect + target = line[curr-1] + curr += 5 + parser = ObjectParser() + add = [] + while line[curr] != ']': + assert line[curr] == ',' + curr += 1 + next, is_func = parser.read(curr, line) + if is_func: + text = line[curr:next] + assert text.startswith('function(') + ident = 'uninline_' + target + '_' + str(curr) # these idents should be unique, but might in theory collide with the rest of the JS code! XXX + line = line[:curr] + ident + line[next:] + add += 'function ' + ident + '(' + text[len('function('):] + while line[curr] != ',' and line[curr] != ']': curr += 1 - next, is_func = parser.read(curr, line) - if is_func: - text = line[curr:next] - assert text.startswith('function(') - ident = 'uninline_' + target + '_' + str(curr) # these idents should be unique, but might in theory collide with the rest of the JS code! XXX - line = line[:curr] + ident + line[next:] - add += 'function ' + ident + '(' + text[len('function('):] - while line[curr] != ',' and line[curr] != ']': - curr += 1 - lines[i] = line - lines = lines[:i] + add + lines[i:] - i += len(add) - i += 1 + curr += 1 + assert line[curr] == ';' + curr += 1 + line = line[:curr] + ''.join(add) + line[curr:] -for line in lines: - outfile.write(line) +outfile.write(line) outfile.close() |