1 // Copyright 2014 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Flags: --min-preparse-length=0 6 7 function variadic(co, ...values) { 8 var sum = 0; 9 while (values.length) { 10 sum += co * values.pop(); 11 } 12 return sum; 13 } 14 15 var arrowVariadic = (co, ...values) => { 16 var sum = 0; 17 while (values.length) { 18 sum += co * values.pop(); 19 } 20 return sum; 21 } 22 23 assertEquals(1, variadic.length); 24 assertEquals(1, arrowVariadic.length); 25 26 assertEquals(90, variadic(2, 1, 2, 3, 4, 5, 6, 7, 8, 9)); 27 assertEquals(74, variadic(2, 1, 2, 3, 4, 5, 6, 7, 9)); 28 assertEquals(110, variadic(2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); 29 30 assertEquals(90, arrowVariadic(2, 1, 2, 3, 4, 5, 6, 7, 8, 9)); 31 assertEquals(74, arrowVariadic(2, 1, 2, 3, 4, 5, 6, 7, 9)); 32 assertEquals(110, arrowVariadic(2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); 33