destructuring.js revision 1812:4a68dd740be8
1127128Snectar/*
2127128Snectar * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3127128Snectar * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4127128Snectar *
5127128Snectar * This code is free software; you can redistribute it and/or modify it
6127128Snectar * under the terms of the GNU General Public License version 2 only, as
7127128Snectar * published by the Free Software Foundation.
8127128Snectar *
9127128Snectar * This code is distributed in the hope that it will be useful, but WITHOUT
10127128Snectar * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11127128Snectar * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12127128Snectar * version 2 for more details (a copy is included in the LICENSE file that
13127128Snectar * accompanied this code).
14127128Snectar *
15127128Snectar * You should have received a copy of the GNU General Public License version
16127128Snectar * 2 along with this work; if not, write to the Free Software Foundation,
17127128Snectar * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18127128Snectar *
19127128Snectar * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20127128Snectar * or visit www.oracle.com if you need additional information or have any
21127128Snectar * questions.
22127128Snectar */
23127128Snectar
24127128Snectar/**
25127128Snectar * Destructuring is not implemented
26127128Snectar *
27127128Snectar * @test
28127128Snectar * @run
29127128Snectar * @option --language=es6
30127128Snectar */
31127128Snectar
32127128Snectar
33127128Snectarfunction check(code) {
34127128Snectar   try {
35127128Snectar      eval(code);
36127128Snectar   } catch (e) {
37127128Snectar      print(String(e).replace(/\\/g, "/"))
38127128Snectar   }
39127128Snectar}
40127128Snectar
41127128Snectarcheck("var { x: y } = obj;");
42127128Snectarcheck("let { x: y } = obj;");
43127128Snectarcheck("const { x: y } = obj;");
44127128Snectarcheck("({ x: y }) = obj;");
45127128Snectarcheck("for (var { x: y } of obj) ;");
46127128Snectarcheck("for (let { x: y } of obj) ;");
47127128Snectarcheck("var { x, y } = obj;");
48127128Snectarcheck("let { x, y } = obj;");
49127128Snectarcheck("const { x, y } = obj;");
50127128Snectarcheck("({ x, y }) = obj;");
51127128Snectarcheck("for (var { x, y } of obj) ;");
52127128Snectarcheck("for (let { x, y } of obj) ;");
53127128Snectarcheck("var [a, b] = obj;");
54279264Sdelphijcheck("let [a, b] = obj;");
55127128Snectarcheck("const [a, b] = obj;");
56127128Snectarcheck("[a, b] = obj;");
57127128Snectarcheck("for ([a, b] of obj) ;");
58127128Snectarcheck("for (var [a, b] of obj) ;");
59127128Snectarcheck("for (let [a, b] of obj) ;");
60127128Snectarcheck("(function({ x: y }) { return x; })()");
61check("(function({ x }) { return x; })()");
62check("(function([x]) { return x; })()");
63check("for (var [[x, y, z] = [4, 5, 6]] = [7, 8, 9]; iterCount < 1; ) ;");
64check("for ([ arrow = () => {} ] of [[]]) ;");
65check("try { throw null;} catch({}) { }");
66check("try { throw {} } catch ({}) { }");
67check("try { throw [] } catch ([,]) { }");
68check("try { throw { w: [7, undefined, ] }} catch ({ w: [x, y, z] = [4, 5, 6] }) { }");
69check("try { throw { a: 2, b: 3} } catch ({a, b}) { }");
70check("try { throw [null] } catch ([[x]]) { }");
71check("try { throw { w: undefined } } catch ({ w: { x, y, z } = { x: 4, y: 5, z: 6 } }) { }");
72
73