Closed Bug 155748 Opened 23 years ago Closed 22 years ago

Can't use a global variable named "parent"

Categories

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

defect
Not set
minor

Tracking

()

RESOLVED FIXED

People

(Reporter: paol1976, Assigned: caillon)

Details

Attachments

(2 files)

If a global variable is declared with the name "parent" - (the same as a builtin variable), any attempt to refer to it will intead refer to the original (builtin) variable. This only happens with "parent". As far as I can tell, using other builtin variable's names works correctly. For example (this is from the attached testcase): // this works as expected var top; top = "this is a variable named top"; alert(top); // this fails in the assignment with "Error: setting a property that has only a getter" var parent; parent = "this is a variable named parent"; alert(parent);
Attached file simple testcase
parent and top are reserverd Javascript keywords. Reserved words have a specific meaning to the Javascript language. Using a reserved word causes a compilation error. This should be marked as INVALID.
No, no, that's completely wrong! :) When you declare a variable, it should "hide" a variable of the same name that was previously in scope. Run the test case in NS4 or IE to see the correct behaviour. Mozilla also does it right most of the time, it's just "parent" that fails for some reason.
If "parent" is a reserved word, then why couldn't I find it in the ECMAScript Language Specification Edition 3 (equiv to JS 1.5). See http://www.mozilla.org/js/language/ for more details.
This bug might actually apply to "top" instead of "parent". The inconsistent behavior is almost certainly a bug. It's certainly not a JSENG bug, because "top" and "parent" refer to windows. ECMAScript doesn't cover windows at all.
Status: UNCONFIRMED → NEW
Component: JavaScript Engine → DOM Level 0
Ever confirmed: true
.
Assignee: rogerl → jst
QA Contact: pschwartau → desale
parent is not reserved, and is not included in Netscape's JS/DOM 0 Reference (for v1.3) at http://developer.netscape.com/docs/manuals/js/client/jsref/index.htm. Both the top and parent property of a window are read only, but comment #3 is correct in that a more local variable should override a more global variable.
Severity: normal → minor
OS: Windows 2000 → All
Hardware: PC → All
I have a fix
Assignee: jst → caillon
I bet this patch probably has some fuzz in it from other unrelated changes to the same file (I manually removed those hunks) but is otherwise good for reviewing.
Comment on attachment 90275 [details] [diff] [review] Proposed patch v.1.0 r=bzbarsky
Attachment #90275 - Flags: review+
Comment on attachment 90275 [details] [diff] [review] Proposed patch v.1.0 sr=jst
Attachment #90275 - Flags: superreview+
Checked in
Status: NEW → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
It's working on build 2002070813
Status: RESOLVED → VERIFIED
Re-opening, just to get approval1.4b. This fix was checked in and working for about a month, but got inadvertently backed out on 2002-08-15. See bug 159236 comment 9 and later.
Status: VERIFIED → REOPENED
Resolution: FIXED → ---
Comment on attachment 90275 [details] [diff] [review] Proposed patch v.1.0 a=asa (on behalf of drivers) for checkin to 1.4b
Attachment #90275 - Flags: approval1.4b? → approval1.4b+
Checked in again. Let's hope it stays there this time :-)
Status: REOPENED → RESOLVED
Closed: 23 years ago22 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: