Closed Bug 90325 Opened 23 years ago Closed 23 years ago

In the DOM , variable name 'prefix' causes problems in JavaScript with blocks

Categories

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

defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: deneen, Assigned: jst)

Details

Attachments

(3 files)

From Bugzilla Helper:
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:0.9.2+)
Gecko/20010711
BuildID:    2001071104

variables defined outside of with(...){} are not accessable inside of the
with(...){}.

Reproducible: Always
Steps to Reproduce:
test case shows it

Actual Results:  variable does not exist

Expected Results:  an the alert messages should be the same
Attached file test case for bug
Tested on solaris, confirming.
I tested this in xpcshell:
a=5;
with (Math) {a+random()};
which works, so it's not a general problem of with(), but maybe something 
related to xpconnect?

Axel
Status: UNCONFIRMED → NEW
Ever confirmed: true
OS: Windows 2000 → All
Hardware: PC → All
It appears to be DOM specific. If I take that same page place Math instead of
the DOM object. It also works.

I'll take a look and see what I can find. jst, brendan I copied you in case you
might know something off the top of your heads.
Status: NEW → ASSIGNED
Also did a test with a non-DOM wrapped native and it worked as expected.
Added testcase to JS test suite:

            mozilla/js/tests/js1_5/Scope/scope-004.js

This testcase passes in the standalone JS shell on all platforms.
Seeing no problems with this in the JS shell - 
The problem turns out to be the use of the variable name 'prefix' !!!

I will attach an HTML testcase showing this. It contains two links.
One runs a reduced version of deneen@bucknell.edu's testcase above, 
which used the variable name 'prefix'. This link shows the problem.

The other link runs the same testcase using the variable name 'prefi'
instead of 'prefix'. There is NO PROBLEM in this case -
In ECMA-262, I do not see the word 'prefix' marked as a reserved word 
or as a future reserved word. Additionally, I see no problems in the 
standalone JS shell using it as an identifier in the testcases above.

Therefore reassigning this to DOM Level 0; it is not a JS Engine bug.
Is 'prefix' a reserved word in the DOM?
Assignee: rogerl → jst
Status: ASSIGNED → NEW
Component: Javascript Engine → DOM Level 0
QA Contact: pschwartau → desale
Resummarizing - 
Summary: javascript with() scope problem → In the DOM , variable name 'prefix' causes problems in JavaScript with blocks
"prefix" is a property of all DOM nodes, it's the namespace prefix of a node
(i.e. the element "<foo:bar>" would have prefix="foo"), you'll haveto use a
different variable name. INVALID.
Status: NEW → RESOLVED
Closed: 23 years ago
Resolution: --- → INVALID
This is yet another reason why with statements are to be avoided in JS.  I'm
sorry I added the silly thing to the language.

/be
sorry about this....

prefix is a very common word, and had it not worked outside the with(), I would 
have figured it was a reserved word.

Is there no default value for prefix?  (so an alert(element.prefix) would say 
something other than undefined)
well, the prefix is the prefix, so as long as you're in the default namespace
(which is what mozilla assumes for HTML), your prefix is "".
It's just the way it is.

And of course a lol to brendan ;-)

Axel
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: