setting property named propertyName on function object fails

VERIFIED DUPLICATE of bug 137000

Status

()

Core
JavaScript Engine
VERIFIED DUPLICATE of bug 137000
16 years ago
16 years ago

People

(Reporter: Martin Honnen, Assigned: rogerl (gone))

Tracking

Trunk
x86
Windows XP
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(2 attachments, 2 obsolete attachments)

(Reporter)

Description

16 years ago
I had some client side JavaScript code which failed to set a property named
propertyName on a function object. I have now reduced that code to not use any
DOM objects and I still have the problem, even when I load the pure JavaScript
code in the XPCOM shell, therefore I file the bug on the JavaScript engine.
The test case code is still somehow convoluted, however when I try to reduce it
further the bug vanishes.

The test case I am going to upload tries to set
  compareOptionsAsNumber.propertyName = propertyName
where compareOptionsAsNumber is a function object created by a function
declaration and propertyName is a function parameter which is passed the string
'text'. However the property is not set, any access to it still returns
undefined while an "in" check returns true.
(Reporter)

Comment 1

16 years ago
Created attachment 87210 [details]
test case (sets property and dumps value which is undefined but should be 'text')
(Reporter)

Comment 2

16 years ago
Created attachment 87212 [details]
test case to be run in browser (works with IE6, Opera 6, shows problem with Mozilla)

I upload this HTML page as it includes the first attachment with a script src
element and therefore allows comparing the Mozilla JavaScript engine behaviour
to that of IE6 and Opera 6.
With Mozilla the output is

compareOptionsAsNumber.propertyName: undefined; "propertyName" in
compareOptionsAsNumber: true; result: text

while with IE6 and Opera 6 the output is

compareOptionsAsNumber.propertyName: text; "propertyName" in
compareOptionsAsNumber: true; result: text

meaning IE and Opera's engine has no problems to set the property named
propertyName while Mozilla's engine fails.
(Reporter)

Comment 3

16 years ago
Created attachment 87218 [details]
simplified test case 

I was able to reproduce the bug with a simplified test case which I attach. I
have also run that attachment with the Rhino engine and the problem doesn't
occur, the property is correctly set to 'text'.
Attachment #87210 - Attachment is obsolete: true
(Reporter)

Comment 4

16 years ago
Created attachment 87219 [details]
HTML wrapper to load JavaScript test case 87218 in a browser

The HTML page loads the JavaScript file 87218 and works fine with IE6 and Opera
6 while it shows the problem with Mozilla
Attachment #87212 - Attachment is obsolete: true

Updated

16 years ago
Attachment #87218 - Attachment mime type: application/x-javascript → text/plain

Comment 5

16 years ago
Martin: thank you for such an excellent report. We can reduce the
testcase to this:

<SCRIPT>
function setFProperty(val)
{
  F.propA = val;
}

function F()
{
 var propA = 'local var';
}

setFProperty('Hello');
document.write(F.propA);
</SCRIPT>


OUTPUT:                IE6         Mozilla trunk 2002070108
                     'Hello'             'undefined'



This turns out to be a duplicate of bug 137000, 
"object member variables not set correctly from parameters passed to parent"

Other duplicates of this bug are:

bug 138708 
"Cannot write to a property"
bug 150032 
"Conflict between function members and vars"


The key point in all of these bugs is that the same name is being
used both for a property name of |F| as an object, and also as
a parameter to F or as a local variable declared inside F.

I have added your testcase to the existing testcase for this:

          mozilla/js/tests/js1_5/Object/regress-137000.js

*** This bug has been marked as a duplicate of 137000 ***
Status: NEW → RESOLVED
Last Resolved: 16 years ago
Resolution: --- → DUPLICATE

Comment 6

16 years ago
Marking Verified Duplicate.

The test, including the new section, fails in the current JS shell.
However, the patch for bug 151066 makes all sections of the test pass.

Note that the patch in bug 151066 is simply the patch for bug 137000
plus optimization considerations. I preferred to mark this as a 
duplicate of bug 137000 because the two other bugs above were.

Martin, I have cc'ed you on bug 151066 so that when it is fixed,
you can verify that your tests pass -
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.