Closed
Bug 301574
Opened 20 years ago
Closed 20 years ago
Bogus error message when calling XML constructor with E4X disabled
Categories
(Core :: JavaScript Engine, defect)
Core
JavaScript Engine
Tracking
()
VERIFIED
FIXED
People
(Reporter: jwkbugzilla, Assigned: mrbkap)
Details
Attachments
(2 files, 1 obsolete file)
157 bytes,
text/html
|
Details | |
3.52 KB,
patch
|
brendan
:
review+
brendan
:
approval1.8b4+
|
Details | Diff | Splinter Review |
Try the following simple code:
var xml = XML('<xml/>');
On an HTML page (E4X disabled by default) it will produce an exception: "invalid
XML markup". This is obviously not the case, same code works fine with E4X
enabled. I see two solutions. One would be changing the error message to
describe the problem properly. The other would be allowing the XML constructor
even if E4X is not enabled. I would actually prefer the latter, as there is no
reason to forbid the explicit XML constructor - is doesn't suffer from backwards
compatibility issues like the XML initialiser.
Reporter | ||
Comment 1•20 years ago
|
||
This testcase currently displays the message: "Got an exception: SyntaxError:
invalid XML markup". Instead it should either say "XML object created" (XML
constructor works despite E4X initialisers being deactivated) or display some
proper error message.
Assignee | ||
Comment 2•20 years ago
|
||
Something like this would fix this, I think.
Assignee | ||
Comment 3•20 years ago
|
||
Comment on attachment 190068 [details] [diff] [review]
throw an error
Better fix coming.
Attachment #190068 -
Attachment is obsolete: true
Attachment #190068 -
Flags: review?(brendan)
Assignee | ||
Comment 4•20 years ago
|
||
Attachment #190144 -
Flags: review?(brendan)
Comment 5•20 years ago
|
||
Comment on attachment 190144 [details] [diff] [review]
enable XML parsing for the XML constructor
Style nites only:
> #if JS_HAS_XML_SUPPORT
>- if (JS_HAS_XML_OPTION(cx) &&
>- pn2->pn_type == TOK_DOT &&
>+ if (pn2->pn_type == TOK_DOT &&
> pn2->pn_op != JSOP_GETMETHOD) {
Pull that second operand of && up onto the same line, so it doesn't feel all
depressed and draggy, ok?
> static JSBool
> XML(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
> {
> jsval v;
> JSXML *xml, *copy;
> JSObject *xobj, *vobj;
> JSClass *clasp;
>+ uint32 oldopts;
Put right after v's decl, to match order of use/set?
> 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;
Too much vertical space is as bad as too little. I'd crunch at least the if
(!xobj) with the JS_SetOptions call before it, and perhaps move the empty line
to after the return JS_FALSE. Tradition would crunch that way *and* eliminate
the blank lines around the xobj = ToXML(cx, v), but maybe it's time for a
change.
> *rval = OBJECT_TO_JSVAL(xobj);
> xml = (JSXML *) JS_GetPrivate(cx, xobj);
>
> if ((cx->fp->flags & JSFRAME_CONSTRUCTING) && !JSVAL_IS_PRIMITIVE(v)) {
> vobj = JSVAL_TO_OBJECT(v);
> clasp = OBJ_GET_CLASS(cx, vobj);
> if (clasp == &js_XMLClass ||
> (clasp->flags & JSCLASS_DOCUMENT_OBSERVER)) {
r+a=me with those nits picked, thanks.
/be
Attachment #190144 -
Flags: review?(brendan)
Attachment #190144 -
Flags: review+
Attachment #190144 -
Flags: approval1.8b4+
Assignee | ||
Comment 6•20 years ago
|
||
Fix checked in.
Status: ASSIGNED → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
Updated•20 years ago
|
Flags: testcase?
Comment 7•20 years ago
|
||
Checking in regress-301574.js;
/cvsroot/mozilla/js/tests/js1_6/Regress/regress-301574.js,v <-- regress-301574.js
initial revision: 1.1
done
Flags: testcase? → testcase+
You need to log in
before you can comment on or make changes to this bug.
Description
•