JDK-8055034.js revision 1375:6cb5cb0a4ec9
1169689Skan/*
2169689Skan * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
3169689Skan * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4169689Skan *
5169689Skan * This code is free software; you can redistribute it and/or modify it
6169689Skan * under the terms of the GNU General Public License version 2 only, as
7169689Skan * published by the Free Software Foundation.
8169689Skan *
9169689Skan * This code is distributed in the hope that it will be useful, but WITHOUT
10169689Skan * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11169689Skan * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12169689Skan * version 2 for more details (a copy is included in the LICENSE file that
13169689Skan * accompanied this code).
14169689Skan *
15169689Skan * You should have received a copy of the GNU General Public License version
16169689Skan * 2 along with this work; if not, write to the Free Software Foundation,
17169689Skan * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18169689Skan *
19169689Skan * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20169689Skan * or visit www.oracle.com if you need additional information or have any
21169689Skan * questions.
22169689Skan */
23169689Skan
24169689Skan/**
25169689Skan * JDK-8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
26169689Skan *
27169689Skan * @test
28169689Skan * @option -scripting
29169689Skan * @run
30169689Skan */
31169689Skan
32169689Skan// assume that this script is run with "nashorn.jar" System
33169689Skan// property set to relative or absolute path of nashorn.jar
34169689Skan
35169689Skanif (typeof fail != 'function') {
36169689Skan    fail = print;
37169689Skan}
38169689Skan
39169689Skanvar System = java.lang.System;
40169689Skanvar File = java.io.File;
41169689Skanvar javahome = System.getProperty("java.home");
42169689Skanvar nashornJar = new File(System.getProperty("nashorn.jar"));
43169689Skanif (! nashornJar.isAbsolute()) {
44169689Skan    nashornJar = new File(".", nashornJar);
45169689Skan}
46169689Skan
47169689Skan// we want to use nashorn.jar passed and not the one that comes with JRE
48169689Skanvar jjsCmd = javahome + "/../bin/jjs";
49169689SkanjjsCmd = jjsCmd.toString().replace(/\//g, File.separator);
50169689Skanif (! new File(jjsCmd).isFile()) {
51169689Skan    jjsCmd = javahome + "/bin/jjs";
52169689Skan    jjsCmd = jjsCmd.toString().replace(/\//g, File.separator);
53169689Skan}
54169689SkanjjsCmd += " -J-Xbootclasspath/p:" + nashornJar;
55169689Skan
56169689Skan$ENV.PWD=System.getProperty("user.dir") // to avoid RE on Cygwin
57169689Skan$EXEC(jjsCmd, "var x = Object.create(null);\nx;\nprint('PASSED');\nexit(0)");
58169689Skan
59169689Skan// $ERR has all interactions including prompts! Just check for error substring.
60169689Skanvar err = $ERR.trim();
61169689Skanif (! err.contains("TypeError: Cannot get default string value")) {
62169689Skan    fail("Error stream does not contain expected error message");
63169689Skan}
64169689Skan
65169689Skan// should print "PASSED"
66169689Skanprint($OUT.trim());
67169689Skan// exit code should be 0
68169689Skanprint("exit code = " + $EXIT);
69169689Skan