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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Destructuring assignment to eval or arguments in destructuring is a SyntaxError
michael@0 2
michael@0 3 load(libdir + "asserts.js");
michael@0 4
michael@0 5 var patterns = [
michael@0 6 "[_]",
michael@0 7 "[a, b, _]",
michael@0 8 "[[_]]",
michael@0 9 "[[], [{}, [_]]]",
michael@0 10 "{x:_}",
michael@0 11 "{x:y, z:_}",
michael@0 12 "{0:_}",
michael@0 13 "{_}",
michael@0 14 //"[..._]"
michael@0 15 ];
michael@0 16
michael@0 17 // If the assertion below fails, congratulations! It means you have added
michael@0 18 // spread operator support to destructuring assignment. Simply uncomment the
michael@0 19 // "[..._]" case above. Then delete this comment and assertion.
michael@0 20 assertThrowsInstanceOf(() => Function("[...x] = [1]"), ReferenceError);
michael@0 21
michael@0 22 for (var pattern of patterns) {
michael@0 23 var stmt = pattern + " = obj";
michael@0 24 if (stmt[0] == "{")
michael@0 25 stmt = "(" + stmt + ")";
michael@0 26 stmt += ";"
michael@0 27
michael@0 28 // stmt is a legal statement...
michael@0 29 Function(stmt);
michael@0 30
michael@0 31 // ...but not if you replace _ with one of these two names.
michael@0 32 for (var name of ["eval", "arguments"]) {
michael@0 33 var s = stmt.replace("_", name);
michael@0 34 assertThrowsInstanceOf(() => Function(s), SyntaxError);
michael@0 35 assertThrowsInstanceOf(() => eval(s), SyntaxError);
michael@0 36 assertThrowsInstanceOf(() => eval("'use strict'; " + s), SyntaxError);
michael@0 37 }
michael@0 38 }

mercurial