Mozilla 1.0's handling of null is different from IE, Netscape 4 and Netscape 6.

RESOLVED FIXED in mozilla1.7final

Status

()

Core
DOM: Core & HTML
RESOLVED FIXED
16 years ago
14 years ago

People

(Reporter: Huazhang Shao, Assigned: jst)

Tracking

Trunk
mozilla1.7final
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [HAVE FIX])

Attachments

(2 attachments)

(Reporter)

Description

16 years ago
Try the following JS code on IE, Netscape 4, Netscape 6 and Mozilla 1.0 {Build
ID: 2002053012}
	var a=null;
	alert(a);
	var b="a="+a;
	alert(b);

There are two alert boxes.

On IE, Netscape 4 and Netscape 6
1) The first alert box shows
	null
2) The second alert box shows
	a=null

On Mozilla 1.0
1) The first alert box shows NOTHING.
2) The second alert box shows
	a=null

The difference has already caused errors in my code.

Comment 1

16 years ago
Confirmed on build: 2002062008 (win2k)

Comment 2

16 years ago
Reassigning to DOM Level 0, as this seems to be an issue with 
the alert() function itself. There is no such problem with the
print() function in the standalone JS shell:

js> var a = null;
js> print(a);
null

js> var b="a="+a;
js> print(b);
a=null
Assignee: rogerl → jst
Component: JavaScript Engine → DOM Level 0
QA Contact: pschwartau → desale

Updated

16 years ago
Status: UNCONFIRMED → NEW
Ever confirmed: true

Comment 3

16 years ago
Created attachment 88967 [details]
Reporter's HTML testcase
(Assignee)

Comment 4

16 years ago
Created attachment 89037 [details] [diff] [review]
Special handling of alert(null) to make it show "null" in the alert
(Assignee)

Updated

16 years ago
Status: NEW → ASSIGNED
OS: Windows 2000 → All
Hardware: PC → All
Whiteboard: [HAVE FIX]
Target Milestone: --- → mozilla1.1beta
(Reporter)

Comment 5

16 years ago
I found a similar null-related incompatibility problem in escape().

Try the following JS code on IE, Netscape 4, Netscape 6 and Mozilla 1.0
	alert(typeof(escape(null))+'\n'+escape(null).length);

On IE, Netscape 4 and Netscape 6, the alert box shows
	string
	4
(escape(null) is 'null'.)

But on Mozilla 1.0, the alert box shows
	string
	0
(escape(null) is ''.)
(Assignee)

Comment 6

16 years ago
You'll find this same difference in most methods that take string arguments. See
bug 69468 for more details on this.
(Assignee)

Updated

16 years ago
Target Milestone: mozilla1.1beta → mozilla1.3alpha
Comment on attachment 89037 [details] [diff] [review]
Special handling of alert(null) to make it show "null" in the alert

>-  // XXX: Concatenation of optional args?
>+  // This should be done with a const nsAString&, but compilers suck
>+  // and can't deal with that :-(
>+  const nsAString *str = DOMStringIsNull(aString) ? &null_str : &aString;

I think you could do

  const nsAString& str = DOMStringIsNull(aString) ? NS_STATIC_CAST(const
nsAString&, null_str) : aString;

>@@ -5651,7 +5653,6 @@
>       STRING_TO_JSVAL(::JS_InternString(cx, "preferenceinternal"));
>   }
> 
>-  NS_ENSURE_SUCCESS(rv, rv);
>   PRUint32 action;
>   if (argc == 1) {
>       action = nsIXPCSecurityManager::ACCESS_GET_PROPERTY;

This change is obsolete I think.
Attachment #89037 - Flags: superreview+
(Assignee)

Updated

15 years ago
Target Milestone: mozilla1.3alpha → mozilla1.3final
(Assignee)

Comment 8

15 years ago
Mass-reassigning bugs to dom_bugs@netscape.com
Assignee: jst → dom_bugs
Status: ASSIGNED → NEW
You have a patch and I sr'ed it with comments. Maybe you should check in? :-)
Assignee: general → jst
(Assignee)

Comment 10

14 years ago
Comment on attachment 89037 [details] [diff] [review]
Special handling of alert(null) to make it show "null" in the alert

Hmm, yeah, I think I should :-)

I've heard casting to references is potentially bad on some compilers (can
cause copy ctors to be called n' what not), so I'll stay away from that. I just
removed the comment where I was whining about it in stead :-)
Attachment #89037 - Flags: review?(caillon)
Attachment #89037 - Flags: review?(caillon) → review+
(Assignee)

Updated

14 years ago
Status: NEW → ASSIGNED
Target Milestone: mozilla1.3final → mozilla1.7final
(Assignee)

Comment 11

14 years ago
Comment on attachment 89037 [details] [diff] [review]
Special handling of alert(null) to make it show "null" in the alert

Trivial, and can help developers figure out what's going on. Requesting 1.7
approval.
Attachment #89037 - Flags: approval1.7?

Comment 12

14 years ago
Comment on attachment 89037 [details] [diff] [review]
Special handling of alert(null) to make it show "null" in the alert

a=asa (on behalf of drivers) for checkin to 1.7
Attachment #89037 - Flags: approval1.7? → approval1.7+
(Assignee)

Comment 13

14 years ago
Fix checked in.
Status: ASSIGNED → RESOLVED
Last Resolved: 14 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.