mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8190391: nashorn "!!" of nonzero even integer var becomes false when returned
Reviewed-by: sundar, hannesw
This commit is contained in:
parent
2245db7522
commit
c9944644fd
4 changed files with 55 additions and 1 deletions
|
@ -138,7 +138,7 @@ class IntType extends BitwiseType {
|
|||
} else if (to.isLong()) {
|
||||
method.visitInsn(I2L);
|
||||
} else if (to.isBoolean()) {
|
||||
//nop
|
||||
invokestatic(method, JSType.TO_BOOLEAN_I);
|
||||
} else if (to.isString()) {
|
||||
invokestatic(method, TO_STRING);
|
||||
} else if (to.isObject()) {
|
||||
|
|
|
@ -89,6 +89,9 @@ public enum JSType {
|
|||
/** JavaScript compliant conversion function from number to boolean */
|
||||
public static final Call TO_BOOLEAN_D = staticCall(JSTYPE_LOOKUP, JSType.class, "toBoolean", boolean.class, double.class);
|
||||
|
||||
/** JavaScript compliant conversion function from int to boolean */
|
||||
public static final Call TO_BOOLEAN_I = staticCall(JSTYPE_LOOKUP, JSType.class, "toBoolean", boolean.class, int.class);
|
||||
|
||||
/** JavaScript compliant conversion function from Object to integer */
|
||||
public static final Call TO_INTEGER = staticCall(JSTYPE_LOOKUP, JSType.class, "toInteger", int.class, Object.class);
|
||||
|
||||
|
@ -547,6 +550,17 @@ public enum JSType {
|
|||
return num != 0 && !Double.isNaN(num);
|
||||
}
|
||||
|
||||
/**
|
||||
* JavaScript compliant conversion of int to boolean
|
||||
*
|
||||
* @param num an int
|
||||
*
|
||||
* @return a boolean
|
||||
*/
|
||||
public static boolean toBoolean(final int num) {
|
||||
return num != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* JavaScript compliant conversion of Object to boolean
|
||||
* See ECMA 9.2 ToBoolean
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue