From d0e1ff2c6e755d1b19787be8874a2a6be79194ef Mon Sep 17 00:00:00 2001 From: Chris Leary Date: Sat, 18 Sep 2010 00:31:36 -0700 Subject: [PATCH] Bug 596502: unbreak XML parsing on JS1.6 and onwards. (r=brendan) --- js/src/jscntxt.h | 19 +++++++++++----- js/src/jsscan.cpp | 2 +- .../tests/basic/bug596502-version.js | 22 +++++++++++++++++++ 3 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 js/src/trace-test/tests/basic/bug596502-version.js diff --git a/js/src/jscntxt.h b/js/src/jscntxt.h index bac10a0b23e1..e31fa46af9d4 100644 --- a/js/src/jscntxt.h +++ b/js/src/jscntxt.h @@ -1949,12 +1949,25 @@ static const uint32 HAS_XML = 0x1000; /* flag induced by XML option */ static const uint32 ANONFUNFIX = 0x2000; /* see jsapi.h comment on JSOPTION_ANONFUNFIX */ } +static inline JSVersion +VersionNumber(JSVersion version) +{ + return JSVersion(uint32(version) & VersionFlags::MASK); +} + static inline bool VersionHasXML(JSVersion version) { return !!(version & VersionFlags::HAS_XML); } +/* @warning This is a distinct condition from having the XML flag set. */ +static inline bool +VersionShouldParseXML(JSVersion version) +{ + return VersionHasXML(version) || VersionNumber(version) >= JSVERSION_1_6; +} + static inline bool VersionHasAnonFunFix(JSVersion version) { @@ -1991,12 +2004,6 @@ VersionHasFlags(JSVersion version) return !!VersionExtractFlags(version); } -static inline JSVersion -VersionNumber(JSVersion version) -{ - return JSVersion(uint32(version) & VersionFlags::MASK); -} - static inline bool VersionIsKnown(JSVersion version) { diff --git a/js/src/jsscan.cpp b/js/src/jsscan.cpp index e7bc7ac1cf5d..f5c7c3318518 100644 --- a/js/src/jsscan.cpp +++ b/js/src/jsscan.cpp @@ -1438,7 +1438,7 @@ TokenStream::getTokenInternal() * The check for this is in jsparse.cpp, Compiler::compileScript. */ if ((flags & TSF_OPERAND) && - (VersionHasXML(version) || peekChar() != '!')) { + (VersionShouldParseXML(version) || peekChar() != '!')) { /* Check for XML comment or CDATA section. */ if (matchChar('!')) { tokenbuf.clear(); diff --git a/js/src/trace-test/tests/basic/bug596502-version.js b/js/src/trace-test/tests/basic/bug596502-version.js new file mode 100644 index 000000000000..c6edc690511c --- /dev/null +++ b/js/src/trace-test/tests/basic/bug596502-version.js @@ -0,0 +1,22 @@ +/* All versions >= 1.6. */ + +function syntaxErrorFromXML() { + try { + var f = new Function('var text = .toString();'); + return false; + } catch (e if e instanceof SyntaxError) { + return true; + } +} + +version(150); +assertEq(syntaxErrorFromXML(), true); +revertVersion(); + +for (vno in {150: null, 160: null, 170: null, 180: null}) { + version(vno); + assertEq(syntaxErrorFromXML(), false); + revertVersion(); +} + +print('PASS!')