Closed Bug 621119 Opened 14 years ago Closed 13 years ago

Decompilation creates an invalid string literal

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: jruderman, Unassigned)

Details

(Keywords: testcase)

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
(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).
It should generate "\x00" in that case, I guess.
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
js> function f() { "use strict"; return "\u00007" }
js> print(f);
function f() {
    "use strict";
    return "\x007";
}
js> print(eval(uneval(f)));
undefined
OS: Mac OS X → All
Hardware: x86 → All
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.
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
Flags: in-testsuite?
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";
}
You need to log in before you can comment on or make changes to this bug.