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)
Core
DOM: Core & HTML
Tracking
()
RESOLVED
FIXED
People
(Reporter: paol1976, Assigned: caillon)
Details
Attachments
(2 files)
338 bytes,
text/html
|
Details | |
2.07 KB,
patch
|
bzbarsky
:
review+
jst
:
superreview+
asa
:
approval1.4b+
|
Details | Diff | Splinter Review |
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);
Reporter | ||
Comment 1•23 years ago
|
||
Comment 2•23 years ago
|
||
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.
Reporter | ||
Comment 3•23 years ago
|
||
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.
Comment 4•23 years ago
|
||
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.
Comment 5•23 years ago
|
||
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
Comment 7•23 years ago
|
||
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
Assignee | ||
Comment 9•23 years ago
|
||
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 10•23 years ago
|
||
Comment on attachment 90275 [details] [diff] [review]
Proposed patch v.1.0
r=bzbarsky
Attachment #90275 -
Flags: review+
Comment 11•23 years ago
|
||
Comment on attachment 90275 [details] [diff] [review]
Proposed patch v.1.0
sr=jst
Attachment #90275 -
Flags: superreview+
Assignee | ||
Comment 12•23 years ago
|
||
Checked in
Status: NEW → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
Assignee | ||
Comment 14•22 years ago
|
||
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 → ---
Assignee | ||
Updated•22 years ago
|
Attachment #90275 -
Flags: approval1.4b?
Comment 15•22 years ago
|
||
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+
Assignee | ||
Comment 16•22 years ago
|
||
Checked in again. Let's hope it stays there this time :-)
Status: REOPENED → RESOLVED
Closed: 23 years ago → 22 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•