Path: blob/aarch64-shenandoah-jdk8u272-b10/nashorn/test/script/basic/JDK-8006983.js
32281 views
/*1* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* 8006983: Introduce a command line option to switch off syntactic extensions of nashorn25*26* @test27* @option -scripting28* @option --no-syntax-extensions29* @run30*/3132try {33eval("var r = new java.lang.Runnable() { run: function(){} }");34fail("should have thrown error for anon-class-style new");35} catch (e) {36if (! (e instanceof SyntaxError)) {37fail("SyntaxError expected, got " + e);38}39}4041try {42eval("var sqr = function(x) x*x ");43fail("should have thrown error for expression closures");44} catch (e) {45if (! (e instanceof SyntaxError)) {46fail("SyntaxError expected, got " + e);47}48}4950try {51eval("function() {};");52fail("should have thrown error for anonymous function statement");53} catch (e) {54if (! (e instanceof SyntaxError)) {55fail("SyntaxError expected, got " + e);56}57}5859try {60eval("for each (i in [22, 33, 33]) { print(i) }");61fail("should have thrown error for-each statement");62} catch (e) {63if (! (e instanceof SyntaxError)) {64fail("SyntaxError expected, got " + e);65}66}6768try {69eval("# shell style comment");70fail("should have thrown error for shell style comment");71} catch (e) {72if (! (e instanceof SyntaxError)) {73fail("SyntaxError expected, got " + e);74}75}7677try {78eval("print(<<EOF);\nhello\nworld\nEOF\n");79fail("should have thrown error heredoc");80} catch (e) {81if (! (e instanceof SyntaxError)) {82fail("SyntaxError expected, got " + e);83}84}858687