Closed
Bug 394885
Opened 17 years ago
Closed 17 years ago
Return type of assignment expression using a setter
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
RESOLVED
DUPLICATE
of bug 312354
People
(Reporter: norrisboyd, Unassigned)
Details
Mail from Steve Yegge:
Case #1: setter returns a value - SpiderMonkey returns that value; Rhino returns the first parameter to the setter (i.e. makes it look like an assignment expression).
Rhino:
js> var foo = {get x(){return this.x_}, set x(val){this.x_ = val; return "done"}}
js> var result = (foo.x = 6);
js> result
6
SpiderMonkey:
js> var foo = {get x(){return this.x_}, set x(val){this.x_ = val; return "done"}}
js> var result = (foo.x = 6);
js> result
"done"
Case #2: setter doesn't return a value - SpiderMonkey returns undefined; Rhino
still returns the first parameter to the setter:
Rhino:
js> var bar = {get x(){return this.x_}, set x(val){this.x_ = val;}}
js> var result = (bar.x = 10)
js> result
10
SpiderMonkey:
js> var bar = {get x(){return this.x_}, set x(val){this.x_ = val;}}
js> var result = (bar.x = 10)
js> result
js> typeof result
undefined
I think Rhino's behavior actually makes more sense, but I've been assuming it
worked like SpiderMonkey and have been returning values (sometimes different
from the assignment parameter) from my setters and assuming it'll work.
---------------------
I'll change Rhino if you think SpiderMonkey's behavior is correct. However, I agree with Steve that the current SpiderMonkey behavior is at least counterintuitive. It's odd that if o.p is a setter then we get the result of o.p = v that can be neither v nor o.p after the assignment. This doesn't match the behavior of the non-setter case.
Comment 1•17 years ago
|
||
We're changing this in bug 312354, as far as I know, particularly since ES4 does the same.
Status: NEW → RESOLVED
Closed: 17 years ago
Resolution: --- → DUPLICATE
You need to log in
before you can comment on or make changes to this bug.
Description
•