eval-spread.js (1202B)
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-function-calls-runtime-semantics-evaluation 6 description: > 7 Direct eval call with spread. 8 info: | 9 12.3.4.1 Runtime Semantics: Evaluation 10 ... 11 3. If Type(ref) is Reference and IsPropertyReference(ref) is false and GetReferencedName(ref) is "eval", then 12 a. If SameValue(func, %eval%) is true, then 13 i. Let argList be ? ArgumentListEvaluation(Arguments). 14 ii. If argList has no elements, return undefined. 15 iii. Let evalText be the first element of argList. 16 ... 17 18 features: [Symbol.iterator] 19 ---*/ 20 21 var elements = [ 22 "x = 1;", 23 "x = 2;", 24 ]; 25 26 var nextCount = 0; 27 var iter = {}; 28 iter[Symbol.iterator] = function() { 29 return { 30 next: function() { 31 var i = nextCount++; 32 if (i < elements.length) { 33 return {done: false, value: elements[i]}; 34 } 35 return {done: true, value: undefined}; 36 } 37 }; 38 }; 39 40 var x = "global"; 41 42 (function() { 43 var x = "local"; 44 eval(...iter); 45 assert.sameValue(x, 1); 46 })(); 47 48 assert.sameValue(x, "global"); 49 assert.sameValue(nextCount, 3); 50 51 reportCompare(0, 0);