Closed Bug 131311 Opened 22 years ago Closed 22 years ago

Can't assign to a variable named |scrollX|

Categories

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

defect

Tracking

()

VERIFIED FIXED
mozilla1.0

People

(Reporter: phil_walden, Assigned: jst)

Details

(Whiteboard: [HAVE FIX])

Attachments

(2 files)

We are getting a javascript error and no display on a page that loads fine in
NS4.75.

The engine seems overly fussy.


<BODY topmargin=0 bottommargin=0  marginheight=0 marginwidth=0 >
<script LANGUAGE="JavaScript">
//each node in the tree is an Array with 4+n positions
//  node[0] is 0/1 when the node is closed/open
//  node[1] is 0/1 when the folder is closed/open
//  node[2] is 1 if the children of the node are documents
//  node[3] is the name of the folder
//  node[4]...node[4+n] are the n children nodes
var scrollX = 0;
^^^^^^^^^^^^^^
Reports error here: setting a property without any accessors


var scrollY = 0;
function getScrollPosition() {
  if(document.layers) {
    scrollX = top.treeFrame.window.pageXOffset;
    scrollY = top.treeFrame.window.pageYOffset;
  }else if (document.all) {
    scrollX = top.treeFrame.window.document.body.scrollLeft;
    scrollY = top.treeFrame.window.document.body.scrollTop;
  }
}
function setScrollPosition() {
  top.treeFrame.window.scrollTo(scrollX, scrollY);
}
This was detected on 0.9.8
Attached file Reduced HTML testcase
The reduced testcase is simply this:

<html><title>Bug 131311</title><head><body>

<script LANGUAGE="JavaScript">
var scrollX = 0;
var scrollY = 0;
</script>

</body></html>


When I load this in Mozilla, I get an error in the JavaScript Console:

  Error: setting a property that has only a getter
  Source File: http://bugzilla.mozilla.org/showattachment.cgi?attach_id=74450
  Line: 4


This is a DOM issue, reassigning. I assume this is because there already
exists a window.scrollX property, and it is read-only.

Note that Mozilla differs from Nav4 and earlier because it catches syntax
errors before binding functions, or even compiling code for them.  This is 
within the spec (ECMA-262). Any syntax error causes execution to stop.
Because of the ECMA3 standard, any malformed syntax means we can't generate 
code, because we generate the code from a complete parse tree.
Assignee: rogerl → jst
Component: JavaScript Engine → DOM Level 0
QA Contact: pschwartau → desale
Summary: javascript error with MatrixOne engineering central → Can't assign to a variable named |scrollX|
Status: UNCONFIRMED → NEW
Ever confirmed: true
If comment #3 is confusing, remember that any global variable 
is a property of the global object, i.e. the window object. 

So your global variable |scrollX| is equivalent to window.scrollX.
But it happens that window.scrollX already exists in the DOM.

And apparently it is a read-only property, as well -
This is a trivial problem where we just need to mark scrollX and scrollY
replaceable so that they can be overridden in JS, nothing new, we do that for
lots of properties allready. We should take this for mozilla1.0 for 4.x
compatibility.
Status: NEW → ASSIGNED
Keywords: mozilla1.0, nsbeta1
OS: HP-UX → All
Priority: -- → P2
Hardware: HP → All
Whiteboard: [HAVE FIX]
Target Milestone: --- → mozilla1.0
Comment on attachment 74466 [details] [diff] [review]
Proposed fix, make scrollX and scrollY replaceable

jband says sr=jband
Attachment #74466 - Flags: superreview+
Comment on attachment 74466 [details] [diff] [review]
Proposed fix, make scrollX and scrollY replaceable

r=fabian
perhaps there should be a general mechanism to implement replaceable
properties, in the future...
Attachment #74466 - Flags: review+
Comment on attachment 74466 [details] [diff] [review]
Proposed fix, make scrollX and scrollY replaceable

a=dbaron for trunk checkin
Attachment #74466 - Flags: approval+
Fixed.
Status: ASSIGNED → RESOLVED
Closed: 22 years ago
Resolution: --- → FIXED
Verified with builds 2002-04-12-10 on WinNT.
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: