Open
Bug 647484
Opened 14 years ago
Updated 2 years ago
Object.defineProperty error message is confusing when writable: false is included in an accessor property descriptor
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
NEW
People
(Reporter: mozilla, Unassigned)
References
(Blocks 1 open bug)
Details
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0) Gecko/20100101 Firefox/4.0
Build Identifier: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0) Gecko/20100101 Firefox/4.0
This snippet:
"use strict";
var obj = {};
Object.defineProperty(obj, "a", {
writable : false,
set : function () {},
get: function () {return 3}
});
console.log(obj.a);
creates this error:
TypeError: property descriptors must not specify a value or be writable when a getter or setter has been specified
Well, writable is set to false, means it is *not* writable. If one ommits the writable property, it is working fine. Nevertheless, the error should only be shown when the writable is explicitely set to true.
Reproducible: Always
Comment 1•14 years ago
|
||
I believe the relevant spec here is ECMA-262 edition 5 section 8.10.5, which defines "ToPropertyDescriptor ( Obj )".
Step 9 there says:
9. If either desc.[[Get]] or desc.[[Set]] are present, then
a. If either desc.[[Value]] or desc.[[Writable]] are present, then throw a
TypeError exception.
Note that it says to throw if those fields of the descriptor are _present_, no matter what value they're set to.
Or put another way, it doesn't make any sense to set "writable" to either false or true if you have a getter or setter, since either value will be ignored.
So I believe this is invalid. I do think the error message should be changed to say "property descriptors must not specify a value or set writable when ...."
Comment 2•14 years ago
|
||
Morphing to keep this useful and fix the diagnostic.
/be
Assignee: general → jwalden+bmo
Status: UNCONFIRMED → NEW
Ever confirmed: true
Summary: Object.defineProperty throws an error, when writable false and getter/setter are available → Object.defineProperty error message is confusing when writable: false is included in an accessor property descriptor
Comment 3•2 years ago
|
||
The bug assignee is inactive on Bugzilla, so the assignee is being reset.
Assignee: jwalden → nobody
Updated•2 years ago
|
Severity: normal → S3
You need to log in
before you can comment on or make changes to this bug.
Description
•