Closed Bug 153830 Opened 22 years ago Closed 20 years ago

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

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla1.7final

People

(Reporter: shaohz, Assigned: jst)

Details

(Whiteboard: [HAVE FIX])

Attachments

(2 files)

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.
Confirmed on build: 2002062008 (win2k)
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
Status: UNCONFIRMED → NEW
Ever confirmed: true
Status: NEW → ASSIGNED
OS: Windows 2000 → All
Hardware: PC → All
Whiteboard: [HAVE FIX]
Target Milestone: --- → mozilla1.1beta
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 ''.)
You'll find this same difference in most methods that take string arguments. See
bug 69468 for more details on this.
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+
Target Milestone: mozilla1.3alpha → mozilla1.3final
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
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+
Status: NEW → ASSIGNED
Target Milestone: mozilla1.3final → mozilla1.7final
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 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+
Fix checked in.
Status: ASSIGNED → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: