The default bug view has changed. See this FAQ.

Decompilation creates an invalid string literal

RESOLVED FIXED

Status

()

Core
JavaScript Engine
RESOLVED FIXED
6 years ago
5 years ago

People

(Reporter: Jesse Ruderman, Unassigned)

Tracking

(Blocks: 1 bug, {testcase})

Trunk
testcase
Points:
---
Bug Flags:
in-testsuite ?

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

6 years ago
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

6 years ago
(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

6 years ago
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
Last Resolved: 5 years ago
Resolution: --- → FIXED
Flags: in-testsuite?
(Reporter)

Comment 6

5 years ago
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.