Closed Bug 182614 Opened 22 years ago Closed 22 years ago

JavaScript seems to be ignoring global variables

Categories

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

x86
Windows 2000
defect
Not set
major

Tracking

()

RESOLVED DUPLICATE of bug 114461

People

(Reporter: madbobsemporium, Assigned: jst)

Details

(Keywords: testcase)

Attachments

(1 file)

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.1) Gecko/20020826 Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.1) Gecko/20020826 Using the following example, I get a JavaScript error of array_length is not defined. <html> <head> <title>Untitled</title> </head> <script language="JavaScript"> var array_length = 10; var numbers_array = new Array (array_length); function create_numbers () { var i = 0; while (i < array_length) { numbers_array[i] = Math.round (Math.random() * 100); i++; } show_numbers(); } function show_numbers () { var i = 0; while (i < array_length) { document.write ("<br> numbers_array [" + i + "] = " + numbers_array[i]); i++; } } </script> <body onLoad="create_numbers()"> </body> </html> I have reported this as a major bug as I think (apparently) not supporting global variables after first use is *very* odd. Reproducible: Always Steps to Reproduce: 1.run the above html page 2.read the error (usually occurs with reference to the second function show_numbers() 3. Actual Results: numbers_array [0] = 42 plus error mentioned above Expected Results: display something like the following: numbers_array [0] = 47 numbers_array [1] = 14 numbers_array [2] = 17 numbers_array [3] = 89 numbers_array [4] = 99 numbers_array [5] = 91 numbers_array [6] = 49 numbers_array [7] = 95 numbers_array [8] = 70 numbers_array [9] = 16
It works for me if I move the function call into the body instead calling from onLoad. ... <body> <script language="JavaScript"> create_numbers(); </script> </body> </html> Tested with Mozilla/5.0 (Windows; U; WinNT4.0; en-US; rv:1.2) Gecko/20021126 Mozilla/5.0 (Windows; U; WinNT4.0; en-US; rv:1.2b) Gecko/20021029 Phoenix/0.4
Confirming bug with Mozilla trunk binary 2002112711. Reassigning to DOM Level 0 and cc'ing Boris. I believe this bug is may be a duplicate of bug 114461, "document.open() clobbers JS context", or may be invalid. When you do document.write() in an onload handler, Mozilla implicitly does a document.open(). I will let Boris or others comment further. What I do know is that if you change the document.write() in your example to an alert() instead, the testcase works fine. On the other hand, IE6 is able to run your testcase as is, so...
Assignee: rogerl → jst
Status: UNCONFIRMED → NEW
Component: JavaScript Engine → DOM Level 0
Ever confirmed: true
QA Contact: pschwartau → desale
Attached file Reporters testcase (deleted) —
Note that this does not work in NS4 either
Keywords: testcase
Yep, it's a dupe. *** This bug has been marked as a duplicate of 114461 ***
Status: NEW → RESOLVED
Closed: 22 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: