author | lana |
Thu, 12 Feb 2015 16:36:53 -0800 | |
changeset 28888 | 2815ad059e8d |
parent 27826 | 605a589e33ca |
child 30698 | 2d50f5564f7b |
permissions | -rw-r--r-- |
26063
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
1 |
/* |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
26067
b32ccc3a76c9
8055199: Tidy up Nashorn codebase for code standards (August 2014)
attila
parents:
26063
diff
changeset
|
4 |
* |
26063
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
26067
b32ccc3a76c9
8055199: Tidy up Nashorn codebase for code standards (August 2014)
attila
parents:
26063
diff
changeset
|
8 |
* |
26063
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
13 |
* accompanied this code). |
26067
b32ccc3a76c9
8055199: Tidy up Nashorn codebase for code standards (August 2014)
attila
parents:
26063
diff
changeset
|
14 |
* |
26063
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
26067
b32ccc3a76c9
8055199: Tidy up Nashorn codebase for code standards (August 2014)
attila
parents:
26063
diff
changeset
|
18 |
* |
26063
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
21 |
* questions. |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
22 |
*/ |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
23 |
|
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
24 |
/** |
26067
b32ccc3a76c9
8055199: Tidy up Nashorn codebase for code standards (August 2014)
attila
parents:
26063
diff
changeset
|
25 |
* JDK-8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression |
26063
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
26 |
* |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
27 |
* @test |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
28 |
* @option -scripting |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
29 |
* @run |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
30 |
*/ |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
31 |
|
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
32 |
// assume that this script is run with "nashorn.jar" System |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
33 |
// property set to relative or absolute path of nashorn.jar |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
34 |
|
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
35 |
if (typeof fail != 'function') { |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
36 |
fail = print; |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
37 |
} |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
38 |
|
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
39 |
var System = java.lang.System; |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
40 |
var File = java.io.File; |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
41 |
var javahome = System.getProperty("java.home"); |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
42 |
var nashornJar = new File(System.getProperty("nashorn.jar")); |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
43 |
if (! nashornJar.isAbsolute()) { |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
44 |
nashornJar = new File(".", nashornJar); |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
45 |
} |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
46 |
|
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
47 |
// we want to use nashorn.jar passed and not the one that comes with JRE |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
48 |
var jjsCmd = javahome + "/../bin/jjs"; |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
49 |
jjsCmd = jjsCmd.toString().replaceAll(/\//g, File.separater); |
27571 | 50 |
if (! new File(jjsCmd).isFile()) { |
51 |
jjsCmd = javahome + "/bin/jjs"; |
|
52 |
jjsCmd = jjsCmd.toString().replaceAll(/\//g, File.separater); |
|
53 |
} |
|
27826
605a589e33ca
8066696: test/script/nosecurity/JDK-8055034.js -Xbootclasspath option is wrong
sundar
parents:
27824
diff
changeset
|
54 |
jjsCmd += " -J-Xbootclasspath/p:" + nashornJar; |
26063
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
55 |
|
27811
e415087c78aa
8062638: RuntimeException when run command from js with -scripting on Cygwin
slugovoy
parents:
26067
diff
changeset
|
56 |
$ENV.PWD=System.getProperty("user.dir") // to avoid RE on Cygwin |
26063
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
57 |
$EXEC(jjsCmd, "var x = Object.create(null);\nx;\nprint('PASSED');\nexit(0)"); |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
58 |
|
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
59 |
// $ERR has all interactions including prompts! Just check for error substring. |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
60 |
var err = $ERR.trim(); |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
61 |
if (! err.contains("TypeError: Cannot get default string value")) { |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
62 |
fail("Error stream does not contain expected error message"); |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
63 |
} |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
64 |
|
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
65 |
// should print "PASSED" |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
66 |
print($OUT.trim()); |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
67 |
// exit code should be 0 |
98eee061a92a
8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff
changeset
|
68 |
print("exit code = " + $EXIT); |