nashorn/test/script/nosecurity/JDK-8055034.js
author chegar
Wed, 03 Dec 2014 17:55:36 +0000
changeset 27824 ab74da77b5a2
parent 27571 08ef93eaca80
parent 27811 e415087c78aa
child 27826 605a589e33ca
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
var nashornJarDir = nashornJar.parentFile.absolutePath;
98eee061a92a 8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff changeset
    47
98eee061a92a 8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff changeset
    48
// 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
    49
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
    50
jjsCmd = jjsCmd.toString().replaceAll(/\//g, File.separater);
27571
08ef93eaca80 8049367: Modular Run-Time Images
chegar
parents: 26067
diff changeset
    51
if (! new File(jjsCmd).isFile()) {
08ef93eaca80 8049367: Modular Run-Time Images
chegar
parents: 26067
diff changeset
    52
    jjsCmd = javahome + "/bin/jjs";
08ef93eaca80 8049367: Modular Run-Time Images
chegar
parents: 26067
diff changeset
    53
    jjsCmd = jjsCmd.toString().replaceAll(/\//g, File.separater);
08ef93eaca80 8049367: Modular Run-Time Images
chegar
parents: 26067
diff changeset
    54
}
08ef93eaca80 8049367: Modular Run-Time Images
chegar
parents: 26067
diff changeset
    55
jjsCmd += " -J-Xbootclasspath/a:" + nashornJarDir;
26063
98eee061a92a 8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff changeset
    56
27811
e415087c78aa 8062638: RuntimeException when run command from js with -scripting on Cygwin
slugovoy
parents: 26067
diff changeset
    57
$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
    58
$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
    59
98eee061a92a 8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff changeset
    60
// $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
    61
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
    62
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
    63
    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
    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
98eee061a92a 8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression
sundar
parents:
diff changeset
    66
// 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
    67
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
    68
// 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
    69
print("exit code = " + $EXIT);