Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: scripts/astDecompile.js

Issue 29354754: Issue 4467 - Fixed hex encoding of characters in string literal and adjusted tests for newer Spider… (Closed) Base URL: https://hg.adblockplus.org/jshydra
Left Patch Set: Created Sept. 23, 2016, 10:50 a.m.
Right Patch Set: Better approach Created Sept. 23, 2016, 10:57 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « autotest/test_abprewrite_module.js.expected ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 let global = this; 1 let global = this;
2 function decompileAST(ast) { 2 function decompileAST(ast) {
3 let func = global["decompile" + ast.type]; 3 let func = global["decompile" + ast.type];
4 if (!func) 4 if (!func)
5 throw "Unknown type " + ast.type; 5 throw "Unknown type " + ast.type;
6 return func(ast); 6 return func(ast);
7 } 7 }
8 8
9 function decompileProgram(ast) { 9 function decompileProgram(ast) {
10 return ast.body.map(decompileAST).join('\n'); 10 return ast.body.map(decompileAST).join('\n');
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 function replace(x) { 380 function replace(x) {
381 if (x == q) return '\\' + q; 381 if (x == q) return '\\' + q;
382 if (x == '\\') return '\\\\'; 382 if (x == '\\') return '\\\\';
383 if (x == '\b') return '\\b'; 383 if (x == '\b') return '\\b';
384 if (x == '\f') return '\\f'; 384 if (x == '\f') return '\\f';
385 if (x == '\n') return '\\n'; 385 if (x == '\n') return '\\n';
386 if (x == '\r') return '\\r'; 386 if (x == '\r') return '\\r';
387 if (x == '\t') return '\\t'; 387 if (x == '\t') return '\\t';
388 if (x == '\v') return '\\v'; 388 if (x == '\v') return '\\v';
389 let val = x.charCodeAt(0); 389 let val = x.charCodeAt(0);
390 if (x < ' ') return '\\x' + ((val - val % 16) / 16).toString(16) + (val % 16 ).toString(16); 390 if (x < ' ') return '\\x' + (val < 16 ? '0' : '') + val.toString(16);
391 return x; 391 return x;
392 } 392 }
393 let result = ""; 393 let result = "";
394 for (let char of str) 394 for (let char of str)
395 result += replace(char); 395 result += replace(char);
396 return result; 396 return result;
397 } 397 }
398 398
399 function decompileLiteral(ast) { 399 function decompileLiteral(ast) {
400 if (typeof ast.value == "string") 400 if (typeof ast.value == "string")
401 return '"' + sanitize(ast.value, '"') + '"'; 401 return '"' + sanitize(ast.value, '"') + '"';
402 if (ast.value === null) 402 if (ast.value === null)
403 return "null"; 403 return "null";
404 return ast.value; 404 return ast.value;
405 } 405 }
406 406
407 function process_js(ast) { 407 function process_js(ast) {
408 _print(decompileAST(ast)); 408 _print(decompileAST(ast));
409 } 409 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld