NASHORN-376.js revision 2:da1e581c933b
1129202Scognet/*
2129202Scognet * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
3129202Scognet * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4129202Scognet *
5129202Scognet * This code is free software; you can redistribute it and/or modify it
6129202Scognet * under the terms of the GNU General Public License version 2 only, as
7129202Scognet * published by the Free Software Foundation.
8129202Scognet *
9129202Scognet * This code is distributed in the hope that it will be useful, but WITHOUT
10129202Scognet * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11129202Scognet * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12129202Scognet * version 2 for more details (a copy is included in the LICENSE file that
13129202Scognet * accompanied this code).
14129202Scognet *
15129202Scognet * You should have received a copy of the GNU General Public License version
16129202Scognet * 2 along with this work; if not, write to the Free Software Foundation,
17129202Scognet * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18129202Scognet *
19129202Scognet * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20129202Scognet * or visit www.oracle.com if you need additional information or have any
21129202Scognet * questions.
22129202Scognet */
23129202Scognet
24129202Scognet/**
25129202Scognet * NASHORN-376 : using 'this' keyword as operand for ++ or -- or as L-value of assignment operator should result in error
26129202Scognet *
27129202Scognet * @test
28129202Scognet * @run
29129202Scognet */
30129202Scognet
31129202Scognetfunction check(code) {
32129202Scognet    try {
33129202Scognet        eval(code);
34129202Scognet        fail("should have result in error " + code);
35129202Scognet    } catch (e) {
36129202Scognet        if (! (e instanceof ReferenceError)) {
37129202Scognet            fail("ReferenceError expected for '" + code + "' , got " + e);
38129202Scognet        }
39129202Scognet    }
40129202Scognet}
41129202Scognet
42129202Scognetcheck("this = 4;");
43check("this++");
44check("++this");
45check("this--");
46check("--this");
47