js/src/jit-test/tests/parser/bug-889628.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit-test/tests/parser/bug-889628.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,38 @@
     1.4 +// Destructuring assignment to eval or arguments in destructuring is a SyntaxError
     1.5 +
     1.6 +load(libdir + "asserts.js");
     1.7 +
     1.8 +var patterns = [
     1.9 +    "[_]",
    1.10 +    "[a, b, _]",
    1.11 +    "[[_]]",
    1.12 +    "[[], [{}, [_]]]",
    1.13 +    "{x:_}",
    1.14 +    "{x:y, z:_}",
    1.15 +    "{0:_}",
    1.16 +    "{_}",
    1.17 +    //"[..._]"
    1.18 +];
    1.19 +
    1.20 +// If the assertion below fails, congratulations! It means you have added
    1.21 +// spread operator support to destructuring assignment. Simply uncomment the
    1.22 +// "[..._]" case above. Then delete this comment and assertion.
    1.23 +assertThrowsInstanceOf(() => Function("[...x] = [1]"), ReferenceError);
    1.24 +
    1.25 +for (var pattern of patterns) {
    1.26 +    var stmt = pattern + " = obj";
    1.27 +    if (stmt[0] == "{")
    1.28 +        stmt = "(" + stmt + ")";
    1.29 +    stmt += ";"
    1.30 +
    1.31 +    // stmt is a legal statement...
    1.32 +    Function(stmt);
    1.33 +
    1.34 +    // ...but not if you replace _ with one of these two names.
    1.35 +    for (var name of ["eval", "arguments"]) {
    1.36 +        var s = stmt.replace("_", name);
    1.37 +        assertThrowsInstanceOf(() => Function(s), SyntaxError);
    1.38 +        assertThrowsInstanceOf(() => eval(s), SyntaxError);
    1.39 +        assertThrowsInstanceOf(() => eval("'use strict'; " + s), SyntaxError);
    1.40 +    }
    1.41 +}

mercurial