Last Comment Bug 621119 - Decompilation creates an invalid string literal
: Decompilation creates an invalid string literal
Status: RESOLVED FIXED
: testcase
Product: Core
Classification: Components
Component: JavaScript Engine (show other bugs)
: Trunk
: All All
: -- normal (vote)
: ---
Assigned To: general
:
:
Mentors:
Depends on:
Blocks: jsfunfuzz
  Show dependency treegraph
 
Reported: 2010-12-23 01:27 PST by Jesse Ruderman
Modified: 2011-11-29 15:46 PST (History)
4 users (show)
ryanvm: in‑testsuite?
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments

Description Jesse Ruderman 2010-12-23 01:27:40 PST
function f() { "use strict"; return "\u00007" }
print(f);
print(eval(uneval(f)));

typein:4: SyntaxError: octal literals and octal escape sequences are deprecated:
typein:4: function f() {'use strict';return "\07";}
typein:4: ..................................^

The first bad revision is:
changeset:   43f456d9b632
user:        Jim Blandy
date:        Thu Nov 19 09:49:00 2009 -0800
summary:     Bug 514559: Forbid octal literals or escape sequences in strict mode. r=mrbkap
Comment 1 Jim Blandy :jimb 2010-12-23 11:42:46 PST
(In reply to comment #0)
> function f() { "use strict"; return "\u00007" }
> The first bad revision is:
> changeset:   43f456d9b632
> summary:     Bug 514559: Forbid octal literals or escape sequences in strict
> mode. r=mrbkap

This is the revision that introduced the check that caught the bug, not the revision that introduced the bug. The printer's generated string "\07", is not a valid literal in strict mode code (the rule for "\0" says that it can't be followed by a decimal digit).
Comment 2 Jim Blandy :jimb 2010-12-23 11:43:16 PST
It should generate "\x00" in that case, I guess.
Comment 3 Brendan Eich [:brendan] 2011-01-26 18:49:13 PST
Tricky. While "\0" is allowed in strict mode, we have to be careful about what follows being maximum-munched.

Or we could lose the '\0' -> '0' pair in js_EscapeMap.

/be
Comment 4 Ryan VanderMeulen [:RyanVM] 2011-11-27 18:06:07 PST
js> function f() { "use strict"; return "\u00007" }
js> print(f);
function f() {
    "use strict";
    return "\x007";
}
js> print(eval(uneval(f)));
undefined
Comment 5 Jeff Walden [:Waldo] (remove +bmo to email) 2011-11-27 18:18:44 PST
Comment 4 demonstrates correct behavior.  Recall that eval returns the result of evaluating a Program, not an Expression, and a function statement doesn't affect completion value, so |undefined| gets returned.

This got fixed by bug 430927.
Comment 6 Jesse Ruderman 2011-11-29 15:46:27 PST
Complete demo of the correct behavior (modulo bug 706305) :

js> function f() { "use strict"; return "\u00007" }
js> print(f);
function f() {
    "use strict";
    return "\x007";
}
js> print(eval( ("(" + uneval(f) + ")" )))
function f() {
    "use strict";
    return "\x007";
}

Note You need to log in before you can comment on or make changes to this bug.