Closed Bug 313570 Opened 20 years ago Closed 20 years ago

length property of objects whose prototype chain includes a function is undefined

Categories

(Core :: JavaScript Engine, defect, P3)

defect

Tracking

()

VERIFIED FIXED
mozilla1.9alpha1

People

(Reporter: stryker330, Assigned: brendan)

Details

Attachments

(1 file)

While trying to develop a workaround for bug 313568, I discovered that an object whose prototype chain has a function object is undefined and can't be changed. For ex: function tmp() {} tmp.prototype = function(a, b, c) {}; var obj = new tmp(); //obj.length is undefined obj.length = 10; //obj.length is still undefined Also, obj.hasOwnProperty('length') returns true. IE always outputs the original function's length, which would be 3 in this case and is also immutable. Opera allows obj.length to be changed.
Taking. JSPROP_SHARED is deep when used with JSPROP_PERMANENT, which makes hasOwnProperty true all the way down the delegation chain (it's meant to apply only to function instances, so they each seem to have a 'length' direct property even though they are all delegating to Function.prototype). The inability to get o.length and see the prototype's arity (3 in your example) is a somewhat separate (or separable) bug. It might be the thing to fix first. /be
Assignee: general → brendan
OS: Windows XP → All
Priority: -- → P3
Hardware: PC → All
Target Milestone: --- → mozilla1.9alpha
Actually, the length property being immutable may be part of the spec. [[Put]] calls [[CanPut]] as its first step and [[CanPut]] seems to say that if any property in the prototype chain is ReadOnly, return false.
(In reply to comment #2) > Actually, the length property being immutable may be part of the spec. [[Put]] > calls [[CanPut]] as its first step and [[CanPut]] seems to say that if any > property in the prototype chain is ReadOnly, return false. Right, so bug 313568 is invalid, and the part of this bug that wants to set obj.length = 10 is invalid too -- but the bits about obj.length being undefined, and obj.hasOwnProperty('length') being true are valid. /be
Summary: length property of objects whose prototype chain includes a function is undefined and immutable → length property of objects whose prototype chain includes a function is undefined
Checking in regress-313570.js; /cvsroot/mozilla/js/tests/ecma_3/Function/regress-313570.js,v <-- regress-313570.js initial revision: 1.1 done
Flags: testcase+
Attached patch proposed fixSplinter Review
Note the lack of fun_setProperty -- all the built-in properties are readonly, so we know that if fun_getProperty is being called, there is no shadowing property in a more direct object along the prototype chain, therefore we should find the first function object on the chain. /be
Attachment #205451 - Flags: superreview?(shaver)
Attachment #205451 - Flags: review?(mrbkap)
Comment on attachment 205451 [details] [diff] [review] proposed fix r=mrbkap
Attachment #205451 - Flags: review?(mrbkap) → review+
Comment on attachment 205451 [details] [diff] [review] proposed fix sr=shaver. silly special function objects!
Attachment #205451 - Flags: superreview?(shaver) → superreview+
Fixed. /be
Status: NEW → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
with 20051217 builds on win/mac/linux <http://test.bclary.com/tests/mozilla.org/js/js-test-driver-standards.html?test=ecma_3/Function/regress-313570.js;language=language;javascript> BUGNUMBER: 313570 STATUS: length of objects whose prototype chain includes a function FAILED!: length of objects whose prototype chain includes a function: inherited FAILED!: Expected value 'false', Actual value 'true' FAILED!:
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Restoring FIXED mark -- Bob, the hasOwnProperty result is expected given the design of SpiderMonkey, and it's independent of this bug or its fix. Could you please spin out a new bug? Thanks, /be
Status: REOPENED → RESOLVED
Closed: 20 years ago20 years ago
Resolution: --- → FIXED
verified on trunk windows/linux/mac
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: