Path: blob/aarch64-shenandoah-jdk8u272-b10/nashorn/test/script/trusted/NASHORN-653.js
32284 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* NASHORN-653 : Various problems with isTerminal and dead code generation from ASM25*26* @test27* @run28*/2930var script = " \31function a() { \32return true; \33} \34\35function b() { \36while (x) { \37return true; \38} \39} \40\41function c() { \42while (true) { \43return true; \44} \45} \46\47function d() { \48do { \49return true; \50} while (x); \51} \52\53function f() { \54for (;;) { \55return true; \56} \57} \58\59function e() { \60for (;;) { \61return true; \62} \63} \64\65function g() { \66for(;;) { \67print('goes on and on and on ... '); \68} \69print('x'); \70} \71";7273function runScriptEngine(opts, code) {74var imports = new JavaImporter(75Packages.jdk.nashorn.api.scripting,76java.io, java.lang, java.util);7778with(imports) {79var fac = new NashornScriptEngineFactory();80// get current System.err81var oldErr = System.err;82var baos = new ByteArrayOutputStream();83var newErr = new PrintStream(baos);84try {85// set new standard err86System.setErr(newErr);87var engine = fac.getScriptEngine(Java.to(opts, "java.lang.String[]"));88engine.eval(code);89newErr.flush();90return new java.lang.String(baos.toByteArray());91} finally {92// restore System.err to old value93System.setErr(oldErr);94}95}96}9798var result = runScriptEngine([ "--print-code" ], script);99100if (result.indexOf("NOP") != -1) {101fail("ASM genenerates NOP*/ATHROW sequences - dead code is still in the script");102}103104105