From b2333ae14689bbda1ef990c533052b50e8134197 Mon Sep 17 00:00:00 2001 From: "brendan%mozilla.org" Date: Wed, 21 Sep 2005 20:59:24 +0000 Subject: [PATCH] Patch for bug 309242 including all trunk changes landed for that fix (a=schrep). git-svn-id: svn://10.0.0.236/branches/MOZILLA_1_8_BRANCH@180769 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/js/src/js.msg | 2 +- mozilla/js/src/jsinterp.c | 15 +++--------- mozilla/js/src/jsscan.c | 48 ++++++++++++++++++++++++++------------- mozilla/js/src/jsscan.h | 28 +++++++++++++++++++++++ mozilla/js/src/jsxml.c | 37 ++++++++++-------------------- 5 files changed, 76 insertions(+), 54 deletions(-) diff --git a/mozilla/js/src/js.msg b/mozilla/js/src/js.msg index 0b92dfed3fb..e3b18ceffad 100644 --- a/mozilla/js/src/js.msg +++ b/mozilla/js/src/js.msg @@ -276,7 +276,7 @@ MSG_DEF(JSMSG_BAD_FOR_EACH_LOOP, 193, 0, JSEXN_SYNTAXERR, "invalid for each MSG_DEF(JSMSG_BAD_XMLLIST_PUT, 194, 1, JSEXN_TYPEERR, "can't set property {0} in XMLList") MSG_DEF(JSMSG_UNKNOWN_XML_ENTITY, 195, 1, JSEXN_TYPEERR, "unknown XML entity {0}") MSG_DEF(JSMSG_BAD_XML_NCR, 196, 1, JSEXN_TYPEERR, "malformed XML character {0}") -MSG_DEF(JSMSG_UNDEFINED_XML_NAME, 197, 1, JSEXN_TYPEERR, "reference to undefined XML name {0}") +MSG_DEF(JSMSG_UNDEFINED_XML_NAME, 197, 1, JSEXN_REFERENCEERR, "reference to undefined XML name {0}") MSG_DEF(JSMSG_DUPLICATE_XML_ATTR, 198, 1, JSEXN_TYPEERR, "duplicate XML attribute {0}") MSG_DEF(JSMSG_TOO_MANY_FUN_VARS, 199, 0, JSEXN_SYNTAXERR, "too many local variables") MSG_DEF(JSMSG_ARRAY_INIT_TOO_BIG, 200, 0, JSEXN_INTERNALERR, "array initialiser too large") diff --git a/mozilla/js/src/jsinterp.c b/mozilla/js/src/jsinterp.c index 905d4385a83..a726930256e 100644 --- a/mozilla/js/src/jsinterp.c +++ b/mozilla/js/src/jsinterp.c @@ -5011,13 +5011,6 @@ js_Interpret(JSContext *cx, jsbytecode *pc, jsval *result) ok = js_FindXMLProperty(cx, lval, &obj, &rval); if (!ok) goto out; - if (JSVAL_IS_VOID(rval)) { - const char *printable = js_ValueToPrintableString(cx, lval); - if (printable) - js_ReportIsNotDefined(cx, printable); - ok = JS_FALSE; - goto out; - } STORE_OPND(-1, OBJECT_TO_JSVAL(obj)); PUSH_OPND(rval); break; @@ -5040,11 +5033,9 @@ js_Interpret(JSContext *cx, jsbytecode *pc, jsval *result) ok = js_FindXMLProperty(cx, lval, &obj, &rval); if (!ok) goto out; - if (!JSVAL_IS_VOID(rval)) { - ok = js_GetXMLProperty(cx, obj, rval, &rval); - if (!ok) - goto out; - } + ok = js_GetXMLProperty(cx, obj, rval, &rval); + if (!ok) + goto out; STORE_OPND(-1, rval); break; diff --git a/mozilla/js/src/jsscan.c b/mozilla/js/src/jsscan.c index 6e51140247f..5c16e2a5b1f 100644 --- a/mozilla/js/src/jsscan.c +++ b/mozilla/js/src/jsscan.c @@ -1305,9 +1305,6 @@ retry: goto out; } - if (c != '-' && c != '\n') - ts->flags |= TSF_DIRTYLINE; - hadUnicodeEscape = JS_FALSE; if (JS_ISIDSTART(c) || (c == '\\' && @@ -1536,7 +1533,7 @@ retry: } switch (c) { - case '\n': tt = TOK_EOL; break; + case '\n': tt = TOK_EOL; goto eol_out; case ';': tt = TOK_SEMI; break; case '[': tt = TOK_LB; break; case ']': tt = TOK_RB; break; @@ -1558,7 +1555,7 @@ retry: case ':': #if JS_HAS_XML_SUPPORT - if (JS_HAS_XML_OPTION(cx) && MatchChar(ts, c)) { + if (MatchChar(ts, c)) { tt = TOK_DBLCOLON; break; } @@ -1632,16 +1629,14 @@ retry: #if JS_HAS_XML_SUPPORT case '@': - if (JS_HAS_XML_OPTION(cx)) { - tt = TOK_AT; - break; - } - goto badchar; + tt = TOK_AT; + break; #endif case '<': #if JS_HAS_XML_SUPPORT - if (JS_HAS_XML_OPTION(cx) && (ts->flags & TSF_OPERAND)) { + if ((ts->flags & TSF_OPERAND) && + (JS_HAS_XML_OPTION(cx) || (ts->flags & TSF_DIRTYINPUT))) { /* Check for XML comment or CDATA section. */ if (MatchChar(ts, '!')) { INIT_TOKENBUF(); @@ -1753,8 +1748,10 @@ retry: /* NB: treat HTML begin-comment as comment-till-end-of-line */ if (MatchChar(ts, '!')) { if (MatchChar(ts, '-')) { - if (MatchChar(ts, '-')) + if (MatchChar(ts, '-')) { + ts->flags |= TSF_INHTMLCOMMENT; goto skipline; + } UngetChar(ts, '-'); } UngetChar(ts, '!'); @@ -1852,8 +1849,16 @@ retry: } skipline: - while ((c = GetChar(ts)) != EOF && c != '\n') - continue; + /* Optimize line skipping if we are not in an HTML comment. */ + if (ts->flags & TSF_INHTMLCOMMENT) { + while ((c = GetChar(ts)) != EOF && c != '\n') { + if (c == '-' && MatchChar(ts, '-') && MatchChar(ts, '>')) + ts->flags &= ~(TSF_DIRTYINPUT | TSF_INHTMLCOMMENT); + } + } else { + while ((c = GetChar(ts)) != EOF && c != '\n') + continue; + } UngetChar(ts, c); ts->cursor = (ts->cursor - 1) & NTOKENS_MASK; goto retry; @@ -1972,14 +1977,21 @@ skipline: tp->t_op = JSOP_SUB; tt = TOK_ASSIGN; } else if (MatchChar(ts, c)) { - if (PeekChar(ts) == '>' && !(ts->flags & TSF_DIRTYLINE)) + if (PeekChar(ts) == '>' && !(ts->flags & TSF_DIRTYLINE)) { + /* + * Clear TSF_DIRTYINPUT as well as TSF_INHTMLCOMMENT, just + * in case another HTML comment hiding hack follows this one. + * It's unusual to have more than one per + * + * It does not cope with malformed comment hiding hacks where --> is hidden + * by C-style comments, or on a dirty line. Such cases are already broken. + */ +#define TSF_INHTMLCOMMENT 0x4000 + /* Unicode separators that are treated as line terminators, in addition to \n, \r */ #define LINE_SEPARATOR 0x2028 #define PARA_SEPARATOR 0x2029 diff --git a/mozilla/js/src/jsxml.c b/mozilla/js/src/jsxml.c index abba0b86d8c..9bc338f11a0 100644 --- a/mozilla/js/src/jsxml.c +++ b/mozilla/js/src/jsxml.c @@ -1889,6 +1889,7 @@ ParseXMLSource(JSContext *cx, JSString *src) uintN lineno; JSStackFrame *fp; JSOp op; + uint32 oldopts; JSParseNode *pn; JSXML *xml; JSXMLArray nsarray; @@ -1942,9 +1943,11 @@ ParseXMLSource(JSContext *cx, JSString *src) } } - xml = NULL; + /* Toggle on XML support since the script has explicitly requested it. */ + oldopts = JS_SetOptions(cx, cx->options | JSOPTION_XML); JS_KEEP_ATOMS(cx->runtime); pn = js_ParseXMLTokenStream(cx, cx->fp->scopeChain, ts, JS_FALSE); + xml = NULL; if (pn && XMLArrayInit(cx, &nsarray, 1)) { if (GetXMLSettingFlags(cx, &flags)) xml = ParseNodeToXML(cx, pn, &nsarray, flags); @@ -1952,6 +1955,7 @@ ParseXMLSource(JSContext *cx, JSString *src) XMLArrayFinish(cx, &nsarray); } JS_UNKEEP_ATOMS(cx->runtime); + JS_SetOptions(cx, oldopts); JS_ARENA_RELEASE(&cx->tempPool, mark); JS_free(cx, chars); @@ -6985,7 +6989,6 @@ static JSBool XML(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { jsval v; - uint32 oldopts; JSXML *xml, *copy; JSObject *xobj, *vobj; JSClass *clasp; @@ -6993,13 +6996,8 @@ XML(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) v = argv[0]; if (JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v)) v = STRING_TO_JSVAL(cx->runtime->emptyString); - /* Toggle on XML support since the script has explicitly requested it. */ - oldopts = cx->options; - JS_SetOptions(cx, oldopts | JSOPTION_XML); xobj = ToXML(cx, v); - - JS_SetOptions(cx, oldopts); if (!xobj) return JS_FALSE; *rval = OBJECT_TO_JSVAL(xobj); @@ -7028,7 +7026,6 @@ XMLList(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) jsval v; JSObject *vobj, *listobj; JSXML *xml, *list; - uint32 oldopts; v = argv[0]; if (JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v)) @@ -7053,10 +7050,7 @@ XMLList(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) } /* Toggle on XML support since the script has explicitly requested it. */ - oldopts = cx->options; - JS_SetOptions(cx, oldopts | JSOPTION_XML); listobj = ToXMLList(cx, v); - JS_SetOptions(cx, oldopts); if (!listobj) return JS_FALSE; @@ -7714,6 +7708,7 @@ js_FindXMLProperty(JSContext *cx, jsval name, JSObject **objp, jsval *namep) jsid funid, id; JSObject *obj, *pobj, *lastobj; JSProperty *prop; + const char *printable; qn = ToXMLName(cx, name, &funid); if (!qn) @@ -7742,21 +7737,13 @@ js_FindXMLProperty(JSContext *cx, jsval name, JSObject **objp, jsval *namep) lastobj = obj; } while ((obj = OBJ_GET_PARENT(cx, obj)) != NULL); - if (JS_HAS_STRICT_OPTION(cx)) { - JSString *str = js_ValueToString(cx, name); - if (!str || - !JS_ReportErrorFlagsAndNumber(cx, - JSREPORT_WARNING|JSREPORT_STRICT, - js_GetErrorMessage, NULL, - JSMSG_UNDEFINED_XML_NAME, - JS_GetStringBytes(str))) { - return JS_FALSE; - } + printable = js_ValueToPrintableString(cx, name); + if (printable) { + JS_ReportErrorFlagsAndNumber(cx, JSREPORT_ERROR, + js_GetErrorMessage, NULL, + JSMSG_UNDEFINED_XML_NAME, printable); } - - *objp = lastobj; - *namep = JSVAL_VOID; - return JS_TRUE; + return JS_FALSE; } JSBool