michael@0: // Destructuring assignment to eval or arguments in destructuring is a SyntaxError michael@0: michael@0: load(libdir + "asserts.js"); michael@0: michael@0: var patterns = [ michael@0: "[_]", michael@0: "[a, b, _]", michael@0: "[[_]]", michael@0: "[[], [{}, [_]]]", michael@0: "{x:_}", michael@0: "{x:y, z:_}", michael@0: "{0:_}", michael@0: "{_}", michael@0: //"[..._]" michael@0: ]; michael@0: michael@0: // If the assertion below fails, congratulations! It means you have added michael@0: // spread operator support to destructuring assignment. Simply uncomment the michael@0: // "[..._]" case above. Then delete this comment and assertion. michael@0: assertThrowsInstanceOf(() => Function("[...x] = [1]"), ReferenceError); michael@0: michael@0: for (var pattern of patterns) { michael@0: var stmt = pattern + " = obj"; michael@0: if (stmt[0] == "{") michael@0: stmt = "(" + stmt + ")"; michael@0: stmt += ";" michael@0: michael@0: // stmt is a legal statement... michael@0: Function(stmt); michael@0: michael@0: // ...but not if you replace _ with one of these two names. michael@0: for (var name of ["eval", "arguments"]) { michael@0: var s = stmt.replace("_", name); michael@0: assertThrowsInstanceOf(() => Function(s), SyntaxError); michael@0: assertThrowsInstanceOf(() => eval(s), SyntaxError); michael@0: assertThrowsInstanceOf(() => eval("'use strict'; " + s), SyntaxError); michael@0: } michael@0: }