Closed Bug 150859 Opened 22 years ago Closed 22 years ago

setting property named propertyName on function object fails

Categories

(Core :: JavaScript Engine, defect)

x86
Windows XP
defect
Not set
normal

Tracking

()

VERIFIED DUPLICATE of bug 137000

People

(Reporter: martin.honnen, Assigned: rogerl)

Details

Attachments

(2 files, 2 obsolete files)

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.
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.
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
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
Attachment #87218 - Attachment mime type: application/x-javascript → text/plain
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
Closed: 22 years ago
Resolution: --- → DUPLICATE
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.

Attachment

General

Creator:
Created:
Updated:
Size: