| 1 |
// Copyright (C) 2017 André Bargull. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
|
| 4 |
/*--- |
| 5 |
esid: sec-runtime-semantics-keyeddestructuringassignmentevaluation |
| 6 |
description: > |
| 7 |
Ensure correct evaluation order when destructuring target is property reference. |
| 8 |
info: | |
| 9 |
12.15.5.2 Runtime Semantics: DestructuringAssignmentEvaluation |
| 10 |
|
| 11 |
AssignmentProperty : PropertyName : AssignmentElement |
| 12 |
|
| 13 |
1. Let name be the result of evaluating PropertyName. |
| 14 |
2. ReturnIfAbrupt(name). |
| 15 |
3. Return the result of performing KeyedDestructuringAssignmentEvaluation of |
| 16 |
AssignmentElement with value and name as the arguments. |
| 17 |
|
| 18 |
12.15.5.4 Runtime Semantics: KeyedDestructuringAssignmentEvaluation |
| 19 |
|
| 20 |
1. If DestructuringAssignmentTarget is neither an ObjectLiteral nor an ArrayLiteral, then |
| 21 |
a. Let lref be the result of evaluating DestructuringAssignmentTarget. |
| 22 |
b. ReturnIfAbrupt(lref). |
| 23 |
2. Let v be ? GetV(value, propertyName). |
| 24 |
... |
| 25 |
4. Else, let rhsValue be v. |
| 26 |
... |
| 27 |
7. Return ? PutValue(lref, rhsValue). |
| 28 |
includes: [compareArray.js] |
| 29 |
---*/ |
| 30 |
|
| 31 |
|
| 32 |
var log = []; |
| 33 |
|
| 34 |
function source() { |
| 35 |
log.push("source"); |
| 36 |
return { |
| 37 |
get p() { |
| 38 |
log.push("get"); |
| 39 |
} |
| 40 |
}; |
| 41 |
} |
| 42 |
function target() { |
| 43 |
log.push("target"); |
| 44 |
return { |
| 45 |
set q(v) { |
| 46 |
log.push("set"); |
| 47 |
} |
| 48 |
}; |
| 49 |
} |
| 50 |
function sourceKey() { |
| 51 |
log.push("source-key"); |
| 52 |
return { |
| 53 |
toString: function() { |
| 54 |
log.push("source-key-tostring"); |
| 55 |
return "p"; |
| 56 |
} |
| 57 |
}; |
| 58 |
} |
| 59 |
function targetKey() { |
| 60 |
log.push("target-key"); |
| 61 |
return { |
| 62 |
toString: function() { |
| 63 |
log.push("target-key-tostring"); |
| 64 |
return "q"; |
| 65 |
} |
| 66 |
}; |
| 67 |
} |
| 68 |
|
| 69 |
({[sourceKey()]: target()[targetKey()]} = source()); |
| 70 |
|
| 71 |
assert.compareArray(log, [ |
| 72 |
"source", "source-key", "source-key-tostring", |
| 73 |
"target", "target-key", "target-key-tostring", |
| 74 |
"get", "set", |
| 75 |
]); |