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
This commit is contained in:
brendan%mozilla.org
2005-09-21 20:59:24 +00:00
parent cd9f1a140a
commit b2333ae146
5 changed files with 76 additions and 54 deletions

View File

@@ -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")

View File

@@ -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;

View File

@@ -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 <script> content,
* but possible.
*/
ts->flags &= ~(TSF_DIRTYINPUT | TSF_INHTMLCOMMENT);
goto skipline;
}
tt = TOK_DEC;
} else {
tp->t_op = JSOP_NEG;
tt = TOK_MINUS;
}
ts->flags |= TSF_DIRTYLINE;
break;
#if JS_HAS_SHARP_VARS
@@ -2040,6 +2052,10 @@ skipline:
}
out:
JS_ASSERT(tt != TOK_EOL);
ts->flags |= TSF_DIRTYLINE | TSF_DIRTYINPUT;
eol_out:
if (!STRING_BUFFER_OK(&ts->tokenbuf))
tt = TOK_ERROR;
JS_ASSERT(tt < TOK_LIMIT);

View File

@@ -251,6 +251,34 @@ struct JSTokenStream {
/* Flag indicating unexpected end of input, i.e. TOK_EOF not at top-level. */
#define TSF_UNEXPECTED_EOF 0x1000
/*
* Non-whitespace since start of input, or since end of last HTML end-comment.
* This is used to disambiguate an XML comment from the ancient Netscape-2-era
* HTML comment hiding hack.
*/
#define TSF_DIRTYINPUT 0x2000
/*
* To handle the hard case of contiguous HTML comments, we want to clear the
* TSF_DIRTYINPUT flag at the end of each such comment. But we'd rather not
* scan for --> within every //-style comment unless we have to. So we set
* the TSF_INHTMLCOMMENT flag when a <!-- is scanned as an HTML begin-comment,
* and clear it (and TSF_DIRTYINPUT) when we scan --> either on a clean line,
* or -- only if (ts->flags & TSF_INHTMLCOMMENT) -- in a //-style comment.
*
* This still works as before given a malformed comment hiding hack such as:
*
* <script>
* <!-- comment hiding hack #1
* code goes here
* // --> oops, markup for script-unaware browsers goes here!
* </script>
*
* 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

View File

@@ -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