Closed
Bug 301692
Opened 20 years ago
Closed 20 years ago
E4X: Function.prototype.toString quotes XML literals
Categories
(Core :: JavaScript Engine, defect, P2)
Core
JavaScript Engine
Tracking
()
VERIFIED
FIXED
mozilla1.8beta4
People
(Reporter: Seno.Aiko, Assigned: mrbkap)
Details
(Keywords: js1.5, Whiteboard: [partial patch, being worked on])
Attachments
(3 files, 1 obsolete file)
|
12.80 KB,
patch
|
shaver
:
review+
shaver
:
approval1.8b4+
|
Details | Diff | Splinter Review |
|
449 bytes,
patch
|
Details | Diff | Splinter Review | |
|
3.21 KB,
patch
|
Details | Diff | Splinter Review |
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8b3) Gecko/20050712 Firefox/1.0+
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8b3) Gecko/20050712 Firefox/1.0+
Calling a function's toString or toSource method doesn't generate the right
result, XML literals are quoted.
Reproducible: Always
Steps to Reproduce:
1. Evaluate String(function() { <xml/> })
Actual Results:
function () {
"<xml/>";
}
Expected Results:
function () {
<xml/>;
}
Comment 1•20 years ago
|
||
I confess that I got sleepy at some point and didn't test the decompiler fully.
Shaver, mrbkap: want to have some decompiler+E4X phun?
/be
Status: UNCONFIRMED → NEW
Ever confirmed: true
Flags: blocking1.8b4+
Keywords: js1.5
Priority: -- → P2
Target Milestone: --- → mozilla1.8beta4
| Assignee | ||
Comment 2•20 years ago
|
||
Shaver and I talked about this on IRC. I suspect he could fix this faster, but
he has other stuff to do, so I get this. The current plan is to generate source
notes for the decompiler to use.
Assignee: general → mrbkap
Comment 3•20 years ago
|
||
Or not, where bytecode is unambiguous. We're full up on srcnotes, so you'd have
to use an existing one that can unambiguous annotate an overloaded bytecode such
as JSOP_ADD.
/be
Comment 4•20 years ago
|
||
(In reply to comment #3)
> Or not, where bytecode is unambiguous. We're full up on srcnotes, so you'd have
> to use an existing one that can unambiguousLY annotate an overloaded bytecode
> such as JSOP_ADD.
In the JSOP_ADD example, SRC_HIDDEN might do well.
Even better would be if the decompiler could tell from some local state that the
JSOP_ADD was for an XML literal. Worth looking into.
/be
| Assignee | ||
Comment 5•20 years ago
|
||
Without an extra opcode, I don't think that's possible, unfortunately. The first
opcode the decompiler sees is the 'string' opcode and there are no other hints
that we're in XML until we see the 'toxml'. Is there some other source of info
that I'm missing?
Comment 6•20 years ago
|
||
Sure, there's always a way. In the decompiler's JSOP_STRING case, you could
peek ahead (if there is another bytecode after the string op and its immediate)
for the JSOP_TOXML op, or another XML-only op that might be adjacent (followed
at some point by JSOP_ADD).
/be
| Assignee | ||
Comment 7•20 years ago
|
||
My concern with this is that the 'toxml' opcode might be very far down the tree
(consider (function f(k) { return <{k}>{k}</{k}>; })) and it feels fragile to
have to scan forward (e.g., figuring out (function f() { return "haha" + <xml/>;
}) seems like it might be an ambiguous case, though I'm not quite certain yet).
Comment 8•20 years ago
|
||
mrbkap and I talked more and poked around; new specialized no-ops are the best
way to fix this, and he's on the case.
/be
| Assignee | ||
Comment 9•20 years ago
|
||
This isn't ready. I haven't touched jsinterp.c, and <k k={k}/> asserts. Feel
free to make comments, but I'll work on it more over the weekend.
| Assignee | ||
Updated•20 years ago
|
Status: NEW → ASSIGNED
Updated•20 years ago
|
Whiteboard: [partial patch, being worked on]
| Assignee | ||
Comment 10•20 years ago
|
||
Attachment #190202 -
Attachment is obsolete: true
Attachment #190417 -
Flags: review?(shaver)
| Assignee | ||
Comment 11•20 years ago
|
||
Here are some testcases. Note that they show another bug (that I'll file in a
second) where <a b={c}> is output as <a b="{c}">, note the quotes.
| Assignee | ||
Updated•20 years ago
|
Flags: testcase?
Comment 12•20 years ago
|
||
Comment on attachment 190417 [details] [diff] [review]
full patch, v1
r=shaver
I don't think the ETAGO case can happen, but I'm not confident enough to ask
you to turn it into an assertion. Nice work.
Attachment #190417 -
Flags: review?(shaver)
Attachment #190417 -
Flags: review+
Attachment #190417 -
Flags: approval1.8b4+
| Assignee | ||
Comment 13•20 years ago
|
||
Fix checked in.
Status: ASSIGNED → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
| Assignee | ||
Comment 14•20 years ago
|
||
...And for the record, I filed bug 302097 on the attribute quoting problem.
Comment 15•20 years ago
|
||
Comment on attachment 190417 [details] [diff] [review]
full patch, v1
>+ JSOp op, nextop;
[snip]
>+ nextop = pn->pn_head->pn_type;
That's not a JSOp right-hand side, it's of JSTokenType.
Also, is it worth another frame slot for a temporary? js_EmitTree is
recursive, and a bit portly -- let's put it on a diet. The following:
>+ if (nextop != TOK_XMLPTAGC &&
>+ nextop != TOK_XMLSTAGO &&
>+ nextop != TOK_XMLETAGO && /* XXX can this happen? */
A switch on pn->pn_head->pn_type would be better. The cases enumerated would
break (the ETAGO case should JS_ASSERT(0); and fall through into the others'
break;) with the default: case handling the JSOP_STARTXML code generation.
JS_ASSERT before the if.
>+ if (pn2->pn_type == TOK_LC && js_Emit1(cx, cg, JSOP_JSEXPR) < 0)
>+ return JS_FALSE;
Nice layout -- one if, && well-used, < 0 tested correctly in second clause.
> for (pn2 = pn2->pn_next, i = 0; pn2; pn2 = pn2->pn_next, i++) {
>+ if (pn2->pn_type == TOK_LC) {
>+ if (!js_Emit1(cx, cg, JSOP_JSEXPR) < 0)
>+ return JS_FALSE;
>+ }
Oops. ! in front of js_Emit1 call, and if-if instead of if-&&.
Please fix the ! bug and the nits ASAP, r+a=me.
/be
Comment 16•20 years ago
|
||
(In reply to comment #15)
> > for (pn2 = pn2->pn_next, i = 0; pn2; pn2 = pn2->pn_next, i++) {
> >+ if (pn2->pn_type == TOK_LC) {
> >+ if (!js_Emit1(cx, cg, JSOP_JSEXPR) < 0)
> >+ return JS_FALSE;
> >+ }
>
> Oops. ! in front of js_Emit1 call, and if-if instead of if-&&.
Oh, and always brace then and else clauses if any of the if condition, then
clause, and else clause if present, are multiline (even if only due to a comment).
/be
| Assignee | ||
Comment 17•20 years ago
|
||
Comment 18•20 years ago
|
||
Checking in regress-301692.js;
/cvsroot/mozilla/js/tests/e4x/Regress/regress-301692.js,v <-- regress-301692.js
initial revision: 1.1
Flags: testcase? → testcase+
Updated•20 years ago
|
Flags: blocking1.8b5+ → blocking1.8b4+
You need to log in
before you can comment on or make changes to this bug.
Description
•