Skip to content

Commit

Permalink
Added test case to consider rest ordering (#1242)
Browse files Browse the repository at this point in the history
  • Loading branch information
caiolima authored and rwaldron committed Sep 26, 2017
1 parent c969153 commit d41eb5d
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/dstr-assignment/obj-rest-order.case
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (C) 2017 Caio Lima. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Rest operation follows [[OwnPropertyKeys]] order
template: default
esid: pending
includes: [compareArray.js]
features: [Symbol, object-rest]
---*/

//- setup
var rest;
var calls = [];
var o = { get z() { calls.push('z') }, get a() { calls.push('a') } };
Object.defineProperty(o, 1, { get: () => { calls.push(1) }, enumerable: true });
Object.defineProperty(o, Symbol('foo'), { get: () => { calls.push("Symbol(foo)") }, enumerable: true });
//- elems
{...rest}
//- vals
o
//- body
assert(compareArray(calls, [1, 'z', 'a', "Symbol(foo)"]));
assert.sameValue(Object.keys(rest).length, 3);
34 changes: 34 additions & 0 deletions test/language/expressions/assignment/dstr-obj-rest-order.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// This file was procedurally generated from the following sources:
// - src/dstr-assignment/obj-rest-order.case
// - src/dstr-assignment/default/assignment-expr.template
/*---
description: Rest operation follows [[OwnPropertyKeys]] order (AssignmentExpression)
esid: sec-variable-statement-runtime-semantics-evaluation
es6id: 13.3.2.4
features: [Symbol, object-rest, destructuring-binding]
flags: [generated]
includes: [compareArray.js]
info: |
VariableDeclaration : BindingPattern Initializer
1. Let rhs be the result of evaluating Initializer.
2. Let rval be GetValue(rhs).
3. ReturnIfAbrupt(rval).
4. Return the result of performing BindingInitialization for
BindingPattern passing rval and undefined as arguments.
---*/
var rest;
var calls = [];
var o = { get z() { calls.push('z') }, get a() { calls.push('a') } };
Object.defineProperty(o, 1, { get: () => { calls.push(1) }, enumerable: true });
Object.defineProperty(o, Symbol('foo'), { get: () => { calls.push("Symbol(foo)") }, enumerable: true });

var result;
var vals = o;

result = {...rest} = vals;

assert(compareArray(calls, [1, 'z', 'a', "Symbol(foo)"]));
assert.sameValue(Object.keys(rest).length, 3);

assert.sameValue(result, vals);
43 changes: 43 additions & 0 deletions test/language/statements/for-of/dstr-obj-rest-order.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// This file was procedurally generated from the following sources:
// - src/dstr-assignment/obj-rest-order.case
// - src/dstr-assignment/default/for-of.template
/*---
description: Rest operation follows [[OwnPropertyKeys]] order (For..of statement)
esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation
es6id: 13.7.5.11
features: [Symbol, object-rest, destructuring-binding]
flags: [generated]
includes: [compareArray.js]
info: |
IterationStatement :
for ( LeftHandSideExpression of AssignmentExpression ) Statement
1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« »,
AssignmentExpression, iterate).
2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement,
keyResult, assignment, labelSet).
13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation
[...]
4. If destructuring is true and if lhsKind is assignment, then
a. Assert: lhs is a LeftHandSideExpression.
b. Let assignmentPattern be the parse of the source text corresponding to
lhs using AssignmentPattern as the goal symbol.
[...]
---*/
var rest;
var calls = [];
var o = { get z() { calls.push('z') }, get a() { calls.push('a') } };
Object.defineProperty(o, 1, { get: () => { calls.push(1) }, enumerable: true });
Object.defineProperty(o, Symbol('foo'), { get: () => { calls.push("Symbol(foo)") }, enumerable: true });

var counter = 0;

for ({...rest} of [o]) {
assert(compareArray(calls, [1, 'z', 'a', "Symbol(foo)"]));
assert.sameValue(Object.keys(rest).length, 3);
counter += 1;
}

assert.sameValue(counter, 1);

0 comments on commit d41eb5d

Please sign in to comment.