Merge
This commit is contained in:
commit
9814dee4e3
@ -20,5 +20,5 @@
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
nbjdk.active=JDK_1.8
|
||||
nbjdk.active=JDK_9
|
||||
|
||||
|
@ -34,6 +34,7 @@ import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.URI;
|
||||
@ -50,6 +51,7 @@ import jdk.nashorn.internal.runtime.NativeJavaPackage;
|
||||
import jdk.nashorn.internal.runtime.Property;
|
||||
import jdk.nashorn.internal.runtime.ScriptEnvironment;
|
||||
import jdk.nashorn.internal.runtime.ScriptFunction;
|
||||
import jdk.nashorn.internal.runtime.ScriptingFunctions;
|
||||
import jdk.nashorn.internal.runtime.ScriptObject;
|
||||
import jdk.nashorn.internal.runtime.ScriptRuntime;
|
||||
import jdk.nashorn.tools.Shell;
|
||||
@ -157,6 +159,15 @@ public final class Main extends Shell {
|
||||
|
||||
global.addShellBuiltins();
|
||||
|
||||
// redefine readLine to use jline Console's readLine!
|
||||
ScriptingFunctions.setReadLineHelper(str-> {
|
||||
try {
|
||||
return in.readLine(str);
|
||||
} catch (final IOException ioExp) {
|
||||
throw new UncheckedIOException(ioExp);
|
||||
}
|
||||
});
|
||||
|
||||
if (System.getSecurityManager() == null) {
|
||||
final Consumer<String> evaluator = str -> {
|
||||
// could be called from different thread (GUI), we need to handle Context set/reset
|
||||
|
@ -474,6 +474,8 @@ public enum JSType {
|
||||
return toPrimitive((ScriptObject)obj, hint);
|
||||
} else if (isPrimitive(obj)) {
|
||||
return obj;
|
||||
} else if (hint == Number.class && obj instanceof Number) {
|
||||
return ((Number) obj).doubleValue();
|
||||
} else if (obj instanceof JSObject) {
|
||||
return toPrimitive((JSObject)obj, hint);
|
||||
} else if (obj instanceof StaticClass) {
|
||||
|
@ -42,6 +42,8 @@ import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
import jdk.nashorn.internal.objects.NativeArray;
|
||||
import static jdk.nashorn.internal.runtime.ECMAErrors.rangeError;
|
||||
|
||||
@ -92,11 +94,7 @@ public final class ScriptingFunctions {
|
||||
* @throws IOException if an exception occurs
|
||||
*/
|
||||
public static Object readLine(final Object self, final Object prompt) throws IOException {
|
||||
if (prompt != UNDEFINED) {
|
||||
System.out.print(JSType.toString(prompt));
|
||||
}
|
||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
|
||||
return reader.readLine();
|
||||
return readLine(prompt);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -219,6 +217,30 @@ public final class ScriptingFunctions {
|
||||
return outString;
|
||||
}
|
||||
|
||||
// Implementation for pluggable "readLine" functionality
|
||||
// Used by jjs interactive mode
|
||||
|
||||
private static Function<String, String> readLineHelper;
|
||||
|
||||
public static void setReadLineHelper(Function<String, String> func) {
|
||||
readLineHelper = Objects.requireNonNull(func);
|
||||
}
|
||||
|
||||
public static Function<String, String> getReadLineHelper() {
|
||||
return readLineHelper;
|
||||
}
|
||||
|
||||
public static String readLine(final Object prompt) throws IOException {
|
||||
final String p = (prompt != UNDEFINED)? JSType.toString(prompt) : "";
|
||||
if (readLineHelper != null) {
|
||||
return readLineHelper.apply(p);
|
||||
} else {
|
||||
System.out.print(p);
|
||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
|
||||
return reader.readLine();
|
||||
}
|
||||
}
|
||||
|
||||
private static MethodHandle findOwnMH(final String name, final Class<?> rtype, final Class<?>... types) {
|
||||
return MH.findStatic(MethodHandles.lookup(), ScriptingFunctions.class, name, MH.type(rtype, types));
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ import java.io.InputStreamReader;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import jdk.nashorn.internal.runtime.JSType;
|
||||
import jdk.nashorn.internal.runtime.ScriptingFunctions;
|
||||
import jdk.nashorn.internal.objects.Global;
|
||||
|
||||
/**
|
||||
@ -66,11 +67,9 @@ public final class ShellFunctions {
|
||||
public static Object input(final Object self, final Object endMarker, final Object prompt) throws IOException {
|
||||
final String endMarkerStr = (endMarker != UNDEFINED)? JSType.toString(endMarker) : "";
|
||||
final String promptStr = (prompt != UNDEFINED)? JSType.toString(prompt) : ">> ";
|
||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
|
||||
final StringBuilder buf = new StringBuilder();
|
||||
while (true) {
|
||||
System.out.print(promptStr);
|
||||
final String line = reader.readLine();
|
||||
final String line = ScriptingFunctions.readLine(promptStr);
|
||||
if (line == null || line.equals(endMarkerStr)) {
|
||||
break;
|
||||
}
|
||||
|
48
nashorn/test/script/basic/JDK-8163945.js
Normal file
48
nashorn/test/script/basic/JDK-8163945.js
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* JDK-8163945: Honor Number type hint in toPrimitive on Numbers
|
||||
*
|
||||
* @test
|
||||
* @run
|
||||
*/
|
||||
|
||||
function assertLessThan(a, b) {
|
||||
Assert.assertTrue(a < b);
|
||||
Assert.assertTrue(a <= b);
|
||||
Assert.assertFalse(a >= b);
|
||||
Assert.assertFalse(a > b);
|
||||
}
|
||||
|
||||
assertLessThan(new java.lang.Long(2), new java.lang.Long(10));
|
||||
assertLessThan(new java.lang.Long(2), 10);
|
||||
assertLessThan(2, new java.lang.Long(10));
|
||||
|
||||
assertLessThan(new java.math.BigInteger(2), new java.math.BigInteger(10));
|
||||
assertLessThan(new java.math.BigInteger(2), 10);
|
||||
assertLessThan(2, new java.math.BigInteger(10));
|
||||
|
||||
assertLessThan(new java.util.concurrent.atomic.AtomicInteger(2), new java.util.concurrent.atomic.AtomicInteger(10));
|
||||
assertLessThan(new java.util.concurrent.atomic.AtomicInteger(2), 10);
|
||||
assertLessThan(2, new java.util.concurrent.atomic.AtomicInteger(10));
|
Loading…
Reference in New Issue
Block a user