NASHORN-214.js revision 2:da1e581c933b
1214117Sjamie/*
2214117Sjamie * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
3214117Sjamie * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4214117Sjamie *
5214117Sjamie * This code is free software; you can redistribute it and/or modify it
6214117Sjamie * under the terms of the GNU General Public License version 2 only, as
7214117Sjamie * published by the Free Software Foundation.
8214117Sjamie *
9214117Sjamie * This code is distributed in the hope that it will be useful, but WITHOUT
10214117Sjamie * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11214117Sjamie * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12214117Sjamie * version 2 for more details (a copy is included in the LICENSE file that
13214117Sjamie * accompanied this code).
14214117Sjamie *
15214117Sjamie * You should have received a copy of the GNU General Public License version
16214117Sjamie * 2 along with this work; if not, write to the Free Software Foundation,
17214117Sjamie * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18214117Sjamie *
19214117Sjamie * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20214117Sjamie * or visit www.oracle.com if you need additional information or have any
21214117Sjamie * questions.
22214117Sjamie */
23214117Sjamie
24214117Sjamie/**
25214117Sjamie * NASHORN-214 :  Syntax error thrown instead of ReferenceError when LHS is not assignable
26214117Sjamie *
27214117Sjamie * @test
28214117Sjamie * @option --early-lvalue-error=false
29214117Sjamie * @run
30214117Sjamie */
31214117Sjamie
32214117Sjamieprint('hello');
33214117Sjamietry {
34214117Sjamie    true = 334; // ReferenceError thrown when control reaches here
35214117Sjamie} catch (e) {
36214117Sjamie    print(e);
37214117Sjamie}
38214117Sjamie
39214117Sjamiex = 'hello';
40214117Sjamieif (typeof x === 'number') {
41214117Sjamie    true = 44; // not reached, so no error thrown
42214117Sjamie} else {
43214117Sjamie    print('x is not a number');
44214117Sjamie}
45214117Sjamie