mirror of https://github.com/tc39/test262.git
Add replacement tests for destructuring evaluation order with property reference as target
This commit is contained in:
parent
58111fff7b
commit
87e259c6e5
|
@ -0,0 +1,80 @@
|
||||||
|
// Copyright (C) 2017 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-runtime-semantics-iteratordestructuringassignmentevaluation
|
||||||
|
description: >
|
||||||
|
Ensure correct evaluation order when destructuring target is property reference.
|
||||||
|
info: |
|
||||||
|
12.15.5.3 Runtime Semantics: IteratorDestructuringAssignmentEvaluation
|
||||||
|
|
||||||
|
AssignmentElement : DestructuringAssignmentTarget Initializer
|
||||||
|
|
||||||
|
1. If DestructuringAssignmentTarget is neither an ObjectLiteral nor an ArrayLiteral, then
|
||||||
|
a. Let lref be the result of evaluating DestructuringAssignmentTarget.
|
||||||
|
b. ReturnIfAbrupt(lref).
|
||||||
|
2. If iteratorRecord.[[Done]] is false, then
|
||||||
|
a. Let next be IteratorStep(iteratorRecord.[[Iterator]]).
|
||||||
|
...
|
||||||
|
3. If iteratorRecord.[[Done]] is true, let value be undefined.
|
||||||
|
...
|
||||||
|
5. Else, let v be value.
|
||||||
|
...
|
||||||
|
8. Return ? PutValue(lref, v).
|
||||||
|
features: [Symbol.iterator]
|
||||||
|
includes: [compareArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
|
||||||
|
var log = [];
|
||||||
|
|
||||||
|
function source() {
|
||||||
|
log.push("source");
|
||||||
|
var iterator = {
|
||||||
|
next: function() {
|
||||||
|
log.push("iterator-step");
|
||||||
|
return {
|
||||||
|
get done() {
|
||||||
|
log.push("iterator-done");
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
get value() {
|
||||||
|
// Note: This getter shouldn't be called.
|
||||||
|
log.push("iterator-value");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var source = {};
|
||||||
|
source[Symbol.iterator] = function() {
|
||||||
|
log.push("iterator");
|
||||||
|
return iterator;
|
||||||
|
};
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
function target() {
|
||||||
|
log.push("target");
|
||||||
|
return target = {
|
||||||
|
set q(v) {
|
||||||
|
log.push("set");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function targetKey() {
|
||||||
|
log.push("target-key");
|
||||||
|
return {
|
||||||
|
toString: function() {
|
||||||
|
log.push("target-key-tostring");
|
||||||
|
return "q";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
([target()[targetKey()]] = source());
|
||||||
|
|
||||||
|
assert.compareArray(log, [
|
||||||
|
"source", "iterator",
|
||||||
|
"target", "target-key", "target-key-tostring",
|
||||||
|
"iterator-step", "iterator-done",
|
||||||
|
"set",
|
||||||
|
]);
|
|
@ -0,0 +1,75 @@
|
||||||
|
// Copyright (C) 2017 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-runtime-semantics-keyeddestructuringassignmentevaluation
|
||||||
|
description: >
|
||||||
|
Ensure correct evaluation order when destructuring target is property reference.
|
||||||
|
info: |
|
||||||
|
12.15.5.2 Runtime Semantics: DestructuringAssignmentEvaluation
|
||||||
|
|
||||||
|
AssignmentProperty : PropertyName : AssignmentElement
|
||||||
|
|
||||||
|
1. Let name be the result of evaluating PropertyName.
|
||||||
|
2. ReturnIfAbrupt(name).
|
||||||
|
3. Return the result of performing KeyedDestructuringAssignmentEvaluation of
|
||||||
|
AssignmentElement with value and name as the arguments.
|
||||||
|
|
||||||
|
12.15.5.4 Runtime Semantics: KeyedDestructuringAssignmentEvaluation
|
||||||
|
|
||||||
|
1. If DestructuringAssignmentTarget is neither an ObjectLiteral nor an ArrayLiteral, then
|
||||||
|
a. Let lref be the result of evaluating DestructuringAssignmentTarget.
|
||||||
|
b. ReturnIfAbrupt(lref).
|
||||||
|
2. Let v be ? GetV(value, propertyName).
|
||||||
|
...
|
||||||
|
4. Else, let rhsValue be v.
|
||||||
|
...
|
||||||
|
7. Return ? PutValue(lref, rhsValue).
|
||||||
|
includes: [compareArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
|
||||||
|
var log = [];
|
||||||
|
|
||||||
|
function source() {
|
||||||
|
log.push("source");
|
||||||
|
return {
|
||||||
|
get p() {
|
||||||
|
log.push("get");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function target() {
|
||||||
|
log.push("target");
|
||||||
|
return {
|
||||||
|
set q(v) {
|
||||||
|
log.push("set");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function sourceKey() {
|
||||||
|
log.push("source-key");
|
||||||
|
return {
|
||||||
|
toString: function() {
|
||||||
|
log.push("source-key-tostring");
|
||||||
|
return "p";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function targetKey() {
|
||||||
|
log.push("target-key");
|
||||||
|
return {
|
||||||
|
toString: function() {
|
||||||
|
log.push("target-key-tostring");
|
||||||
|
return "q";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
({[sourceKey()]: target()[targetKey()]} = source());
|
||||||
|
|
||||||
|
assert.compareArray(log, [
|
||||||
|
"source", "source-key", "source-key-tostring",
|
||||||
|
"target", "target-key", "target-key-tostring",
|
||||||
|
"get", "set",
|
||||||
|
]);
|
Loading…
Reference in New Issue