fix fix_closure bug with newlines

This commit is contained in:
Alon Zakai 2012-01-11 11:38:46 -08:00
Родитель 7b7f8f4d66
Коммит 20c28230c1
2 изменённых файлов: 12 добавлений и 3 удалений

Просмотреть файл

@ -32,5 +32,6 @@ function ya(a,b){var d=D[X>>2],c=Va(a,b),e=r.T();var i=O(c,"i8",na),c=1*c.length
(function(a,b,d){if(!Ta){Ta=l;Ra();a||(a=function(){if(!a.j||!a.j.length){var b;"undefined"!=typeof window&&"function"==typeof window.prompt?b=window.prompt("Input: "):"function"==typeof readline&&(b=readline());b||(b="");a.j=S(b+"\n",l)}return a.j.shift()});b||(b=function(a){a===m||10===a?(b.v(b.buffer.join("")),b.buffer=[]):b.buffer.push(String.fromCharCode(a))});b.v||(b.v=print);b.buffer||(b.buffer=[]);d||(d=b);Sa("tmp",l);var c=Sa("dev",n),e=$(c,"stdin",a),i=$(c,"stdout",m,b),d=$(c,"stderr",m,
d);$(c,"tty",a,b);Y[1]={path:"/dev/stdin",object:e,position:0,r:l,h:n,q:n,error:n,n:n,A:[]};Y[2]={path:"/dev/stdout",object:i,position:0,r:n,h:l,q:n,error:n,n:n,A:[]};Y[3]={path:"/dev/stderr",object:d,position:0,r:n,h:l,q:n,error:n,n:n,A:[]};Ka=O([1],"void*",N);X=O([2],"void*",N);La=O([3],"void*",N);Y[Ka]=Y[1];Y[X]=Y[2];Y[La]=Y[3];O([O([0,0,0,0,Ka,0,0,0,X,0,0,0,La,0,0,0],"void*",N)],"void*",N)}})();
ia.push({I:function(){Ta&&(0<Y[2].object.d.buffer.length&&Y[2].object.d(10),0<Y[3].object.d.buffer.length&&Y[3].object.d(10))}});W(0);var Wa=O([0],"i8",N);Module.G=function(a){function b(){for(var a=0;3>a;a++)c.push(0)}var d=a.length+1,c=[O(S("/bin/this.program"),"i8",N)];b();for(var e=0;e<d-1;e+=1)c.push(O(S(a[e]),"i8",N)),b();c.push(0);c=O(c,"i32",N);return va()};var wa,xa,za,Aa,Ba,Ca,Da;wa=O([2],["i32 ()*",0,0,0,0],N);xa=O([4],["i32 ()*",0,0,0,0],N);
za=O([42,37,100,44,37,100,44,37,100,44,37,100,44,37,100,44,37,100,42,10,0],"i8",N);Aa=O([42,37,100,44,37,100,0],"i8",N);Ba=O([44,37,100,44,37,100,42,10,0],"i8",N);Ca=O([42,104,101,108,108,111,33,42,0],"i8",N);Da=O([42,103,111,111,100,98,121,101,33,42,0],"i8",N);Q=[0,0,function(){return 26},0,function(){return 90},0,function(){return 0},0,function(a){var b=D[X>>2],a=Ua(b,a,sa(a));if(0>a)b=a;else{var d=U(10);B[Wa]=d;-1==Ua(b,Wa,1)?(b in Y&&(Y[b].error=l),b=-1):b=d;b=0>b?-1:a+1}return b},0,function(a,c){},0];
za=O([42,37,100,44,37,100,44,37,100,44,37,100,44,37,100,44,37,100,42,10,0],"i8",N);Aa=O([42,37,100,44,37,100,0],"i8",N);Ba=O([44,37,100,44,37,100,42,10,0],"i8",N);Ca=O([42,104,101,108,108,111,33,42,0],"i8",N);Da=O([42,103,111,111,100,98,121,101,33,42,0],"i8",N);Q=[0,0,function(){return 26},0,function(){return 90},0,function(){return 0},0,function(a){var b=D[X>>2],a=Ua(b,a,sa(a));if(0>a)b=a;else{var d=U(10);B[Wa]=d;-1==Ua(b,Wa,1)?(b in Y&&(Y[b].error=l),b=-1):b=d;b=0>b?-1:a+1}return b},0,function(a,c){},0,
function(a,c,d,e){J[u[u[a>>2]+72>>2]](a,c,d,e)},0,function(a,c){var d=u[a+12>>2];J[u[u[d>>2]+24>>2]](d,c)},0];
Module.FUNCTION_TABLE=Q;function Xa(a){var a=a||Module.arguments,b=m;if(Module._main)for(b=Module.G(a);0<ia.length;){var a=ia.pop(),d=a.I;"number"===typeof d&&(d=Q[d]);d(a.D===k?m:a.D)}return b}Module.run=Xa;try{Na=n}catch(Ya){}Module.noInitialRun||Xa();

Просмотреть файл

@ -20,7 +20,7 @@ class ObjectParser:
'''
Read an element of the FUNCTION_TABLE until the end (a comma or the end of FUNCTION_TABLE), returning that location
'''
assert line[s-1] == ',' # we are a new element, after a comma
#print 'zz start parsing!', line[s-1:s+100]
curly = 0
paren = 0
string = 0
@ -28,6 +28,7 @@ class ObjectParser:
i = s
while True:
c = line[i]
#print 'parsing! CPSF', c, curly, paren, string, is_func
if not string:
if c == '"' or c == "'":
string = 1
@ -42,6 +43,7 @@ class ObjectParser:
paren -= 1
elif not curly and not paren:
if c in [',', ']']:
#print 'zz done,', line[s:i], line[s:i].startswith('function(')
return (i, is_func and line[s:i].startswith('function('))
else:
if c == '"' or c == "'":
@ -54,6 +56,7 @@ while True:
curr = line.find('=[0,0,', curr)
if curr < 0: break
# a suspect
#print 'zz suspect!', curr, line[curr-10:curr+10]
target = line[curr-1]
curr += 5
parser = ObjectParser()
@ -61,17 +64,22 @@ while True:
while line[curr] != ']':
assert line[curr] == ','
curr += 1
while line[curr] in ['\n', ' ']:
curr += 1
next, is_func = parser.read(curr, line)
if is_func:
text = line[curr:next]
#print 'zz func!', text
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('):]
#print 'zz after func fix:', line[curr:curr+100]
while line[curr] != ',' and line[curr] != ']':
curr += 1
#print 'zz exited:', line[curr:curr+100]
curr += 1
assert line[curr] == ';'
assert line[curr] == ';', 'odd char: ' + str([line[curr], line[curr-10:curr+10]])
curr += 1
line = line[:curr] + ''.join(add) + line[curr:]