Closed Bug 410192 Opened 17 years ago Closed 17 years ago

E4X: incorrect ([e4x.@x]).toSource()

Categories

(Core :: JavaScript Engine, defect, P3)

defect

Tracking

()

VERIFIED FIXED
mozilla1.9beta3

People

(Reporter: BijuMailList, Assigned: brendan)

References

Details

Attachments

(1 file)

var a = <a x="blah" />;
([a.@x]).toSource()

gives    ==>  [blah]

expected ==> ["blah"]


===== also ===
var a = <a>
            <a x="blah" />
            <a x="blah" />
            <a x="blah" />
        </a>;

([a..@x]).toSource()

gives    ==>
[blah
blah
blah]

expected  ==> ? (I dont know !!!)

may be    ==> ["blah\nblah\nblah"]
or may be ==> ["blahblahblah"]
Simplest testcase:

js> uneval(<x a="v"/>.@a)
v

Biju, is there anything else like an attribute value that should be quoted by uneval/toSource, but is not quoted by toXMLString? This bug is the result of making toSource an alias for toXMLString. Patch next.

/be
Assignee: general → brendan
Status: NEW → ASSIGNED
Attachment #294862 - Flags: review?(mrbkap)
OS: Windows XP → All
Priority: -- → P3
Hardware: PC → All
Target Milestone: --- → mozilla1.9 M11
Attachment #294862 - Flags: review?(mrbkap) → review+
(In reply to comment #1)
> Biju, is there anything else like an attribute value that should be quoted by
> uneval/toSource, but is not quoted by toXMLString? 

//with
  XML.ignoreComments = false;
  XML.ignoreProcessingInstructions = false;
  XML.ignoreWhitespace = false;

//following also gives invalid toSource
  [<>df</>].toSource();
  [<><![CDATA[df]]></>].toSource();
  [<><!--df--></>].toSource();
  [<><?mypi sds ?></>].toSource();
  [XML('df')].toSource();
  [XML('<![CDATA[df]]>')].toSource();
  [XML('<!--df-->')].toSource();
  [XML('<?mypi sds ?>')].toSource();

//along with
  [<><a>1</a><a>2</a></>].toSource();

// two more test cases

({a:(<x a="a"/>).@b}).toSource();     // XML Query result is null,
({a:XML('')}).toSource();             // blank XML
({a:XML()}).toSource();
also see bug 410263 ...
  [(<a a="&#xA;<>"/>).@a].toSource()  ==> [&#xA;&lt;>]
Biju: thanks for your help getting E4X bugs tracked down. One suggestion here: please simplify tests of the form |[expr].toSource() ==> bad| to avoid the array initialiser and toSource call: |uneval(expr) ==> bad|.

I'm not going to linger fixing E4X bugs, given higher priorities, so I will commit the patch mrbkap reviewed shortly. Remaining problems go in new bugs. Thanks!

/be 
Attachment #294862 - Flags: approval1.9+
Last E4X non-crasher I'll fix for 1.9, I swear!

/be
Flags: blocking1.9+
Fixed.

/be
Status: ASSIGNED → RESOLVED
Closed: 17 years ago
Resolution: --- → FIXED
Here is it....

With
   XML.ignoreComments = true;
   XML.ignoreProcessingInstructions = true;
   XML.ignoreWhitespace = true;

   |uneval(<>asdf</>)                ==> asdf|
   |uneval(<><![CDATA[asdf]]></>)    ==> asdf|
   |uneval(<><!--asdf--></>)         ==> |
   |uneval(<><?mypi asdf ?></>)      ==> |
   |uneval(<></>)                    ==> |
   |uneval(<x a="asdf"/>.@b)         ==> |
   |uneval(XML('asdf'))              ==> asdf|
   |uneval(XML('<![CDATA[asdf]]>'))  ==> asdf|
   |uneval(XML('<!--asdf-->'))       ==> |
   |uneval(XML('<?mypi asdf ?>'))    ==> |
   |uneval(XML(''))                  ==> |
   |uneval(XML())                    ==> |

also if needed
   |uneval({a:(<x a="asdf"/>).@b})   ==> ({a:})|
   |uneval({a:<></>})                ==> ({a:})|
   |uneval({a:<>asdf</>})            ==> ({a:asdf})|
   |uneval({a:XML('')})              ==> ({a:})|
   |uneval({a:XML()})                ==> ({a:})|


My bad actually following are GOOD, but I dont know what fix has done, 
so I am adding them also
   XML.ignoreComments = false;
   XML.ignoreProcessingInstructions = false;
   XML.ignoreWhitespace = false;

   |uneval(<><!--asdf--></>)         ==> <!--asdf-->|
   |uneval(<><?mypi asdf ?></>)      ==> <?mypi asdf ?>|
   |uneval(XML('<!--asdf-->'))       ==> <!--asdf-->|
   |uneval(XML('<?mypi asdf ?>'))    ==> <?mypi asdf ?>|


(In reply to comment #6)
> please simplify tests of the form |[expr].toSource() ==> bad| to avoid the
> array initialiser and toSource call: |uneval(expr) ==> bad|.

Why uneval is prefered over toSource?
uneval works for all values, toSource does not for null and undefined (general reason, doesn't apply here of course). Also, uneval is two characters shorter ;-).

Not wrapping in an array initialiser avoids confounding variable to-do with array init and toSource.

Please file followups for uncovered buggy cases. Thanks,

/be
(In reply to comment #10)
> Please file followups for uncovered buggy cases. Thanks,

Sure, thanks...
/cvsroot/mozilla/js/tests/public-failures.txt
new revision: 1.20; previous revision: 1.19

/cvsroot/mozilla/js/tests/e4x/extensions/regress-410192.js
initial revision: 1.1
Flags: in-testsuite+
Flags: in-litmus-
v
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: