Path: blob/aarch64-shenandoah-jdk8u272-b10/nashorn/test/script/nosecurity/JDK-8055034.js
32281 views
/*1* Copyright (c) 2014, 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* JDK-8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression25*26* @test27* @option -scripting28* @run29*/3031// assume that this script is run with "nashorn.jar" System32// property set to relative or absolute path of nashorn.jar3334if (typeof fail != 'function') {35fail = print;36}3738var System = java.lang.System;39var File = java.io.File;40var javahome = System.getProperty("java.home");41var nashornJar = new File(System.getProperty("nashorn.jar"));42if (! nashornJar.isAbsolute()) {43nashornJar = new File(".", nashornJar);44}45var nashornJarDir = nashornJar.parentFile.absolutePath;4647// we want to use nashorn.jar passed and not the one that comes with JRE48var jjsCmd = javahome + "/../bin/jjs";49jjsCmd += " -J-Djava.ext.dirs=" + nashornJarDir;50jjsCmd = jjsCmd.toString().replace(/\//g, File.separator);51$ENV.PWD=System.getProperty("user.dir") // to avoid RE on Cygwin52$EXEC(jjsCmd, "var x = Object.create(null);\nx;\nprint('PASSED');\nexit(0)");5354// $ERR has all interactions including prompts! Just check for error substring.55var err = $ERR.trim();56if (! err.contains("TypeError: Cannot get default string value")) {57fail("Error stream does not contain expected error message");58}5960// should print "PASSED"61print($OUT.trim());62// exit code should be 063print("exit code = " + $EXIT);646566