diff --git a/js/src/jsopcode.cpp b/js/src/jsopcode.cpp index b5279e6ef78..218421f01ba 100644 --- a/js/src/jsopcode.cpp +++ b/js/src/jsopcode.cpp @@ -756,7 +756,12 @@ QuoteString(Sprinter *sp, JSString *str, uint32 quote) ? Sprint(sp, "%c", (char)c) >= 0 : Sprint(sp, "\\%c", e[1]) >= 0; } else { - ok = Sprint(sp, (c >> 8) ? "\\u%04X" : "\\x%02X", c) >= 0; + /* + * Use \x only if the high byte is 0 and we're in a quoted string, + * because ECMA-262 allows only \u, not \x, in Unicode identifiers + * (see bug 621814). + */ + ok = Sprint(sp, (qc && !(c >> 8)) ? "\\x%02X" : "\\u%04X", c) >= 0; } if (!ok) return NULL; diff --git a/js/src/tests/js1_8_5/regress/jstests.list b/js/src/tests/js1_8_5/regress/jstests.list index 5e72b82a587..03973c2e733 100644 --- a/js/src/tests/js1_8_5/regress/jstests.list +++ b/js/src/tests/js1_8_5/regress/jstests.list @@ -64,3 +64,4 @@ script regress-619003-1.js script regress-619003-2.js script regress-620376-1.js script regress-620376-2.js +script regress-621814.js diff --git a/js/src/tests/js1_8_5/regress/regress-621814.js b/js/src/tests/js1_8_5/regress/regress-621814.js new file mode 100644 index 00000000000..146a2f3edad --- /dev/null +++ b/js/src/tests/js1_8_5/regress/regress-621814.js @@ -0,0 +1,13 @@ +/* + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/licenses/publicdomain/ + */ +var expect = 'pass'; +var actual = expect; +function f({"\xF51F": x}) {} +try { + eval(uneval(f)); +} catch (e) { + actual = '' + e; +} +reportCompare(expect, actual, "");