8037572: Add more test cases to check static types
authormnunez
Mon, 05 May 2014 14:17:20 +0200
changeset 24750 01ea334ab39a
parent 24749 1549c85f8200
child 24751 ccbd9cd3f720
8037572: Add more test cases to check static types Reviewed-by: attila, lagergren
nashorn/test/script/basic/optimistic_arithmetic_check_type.js
nashorn/test/script/basic/optimistic_arithmetic_check_type.js.EXPECTED
nashorn/test/script/basic/optimistic_assignment_check_type.js
nashorn/test/script/basic/optimistic_assignment_check_type.js.EXPECTED
nashorn/test/script/basic/optimistic_check_type.js
nashorn/test/script/basic/optimistic_check_type.js.EXPECTED
nashorn/test/script/basic/optimistic_logical_check_type.js
nashorn/test/script/basic/optimistic_logical_check_type.js.EXPECTED
nashorn/test/script/currently-failing/optimistic_check_type_cases.js
nashorn/test/script/currently-failing/optimistic_check_type_cases.js.EXPECTED
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/optimistic_arithmetic_check_type.js	Mon May 05 14:17:20 2014 +0200
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2014, 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.
+ */
+
+/**
+ * @test
+ * @bug 8036987, 8037572 
+ * @summary Implement tests that checks static types in the compiled code 
+ * @run
+ */
+
+var inspect = Java.type("jdk.nashorn.test.tools.StaticTypeInspector").inspect
+var a = 3, b, c;
+var x = { a: 2, b:1, c: 7, d: -1}
+var y = { a: Number.MAX_VALUE, b: Number.POSITIVE_INFINITY, c: "Hello", d: undefined}
+
+// Testing arithmetic operators
+//-- Local variable
+print(inspect(x.a*x.b, "local int multiplication by local int"))
+print(inspect(x.a/x.b, "local int division by local int without remainder"))
+print(inspect(x.c/x.a, "local int division by local int with remainder"))
+print(inspect(x.c%x.a, "local int modulo by local int"))
+print(inspect(x.a+x.b, "local int addition local int"))
+print(inspect(x.a-x.b, "local int substraction local int"))
+print(inspect(y.a*y.a, "max value multiplication by max value"))
+print(inspect(y.b*y.b, "infinity multiplication by infinity"))
+print(inspect(x.d/y.b, "-1 division by infinity"))
+print(inspect(y.b/x.e, "infinity division by zero"))
+print(inspect(y.b/y.c, "infinity division by String"))
+print(inspect(y.d/y.d, "local undefined division by local undefined"))
+print(inspect(y.d*y.d, "local undefined multiplication by local undefined"))
+print(inspect(y.d+x.a, "local undefined addition local int"))
+print(inspect(y.d--, "local undefined decrement postfix"))
+print(inspect(--y.d, "local undefined decrement prefix"))
+print(inspect(x.a++, "local int increment postfix"))
+print(inspect(++x.a, "local int increment prefix"))
+print(inspect(x.a--, "local int decrement postfix"))
+print(inspect(--x.a, "local int decrement prefix"))
+print(inspect(+x.a, "local int unary plus"))
+print(inspect(-x.a, "local int unary minus"))
+//-- Global variable
+print(inspect(b*c, "undefined multiplication by undefined"))
+print(inspect(b/c, "undefined division by undefined"))
+print(inspect(a+a, "global int addition global int"))
+print(inspect(a-a, "global int substraction global int"))
+print(inspect(a*a, "global int multiplication by global int"))
+print(inspect(a++, "global int increment postfix"))
+print(inspect(++a, "global int increment prefix"))
+print(inspect(a--, "global int decrement postfix"))
+print(inspect(--a, "global int decrement prefix"))
+print(inspect(+a, "global int unary plus"))
+print(inspect(-a, "global int unary minus"))
+print(inspect(b--, "global undefined decrement postfix"))
+print(inspect(--b, "global undefined decrement prefix"))
+print(inspect(x, "object"))
+print(inspect(x/x, "object division by object"))
+print(inspect(x/y, "object division by object"))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/optimistic_arithmetic_check_type.js.EXPECTED	Mon May 05 14:17:20 2014 +0200
@@ -0,0 +1,38 @@
+local int multiplication by local int: int
+local int division by local int without remainder: int
+local int division by local int with remainder: double
+local int modulo by local int: int
+local int addition local int: int
+local int substraction local int: int
+max value multiplication by max value: double
+infinity multiplication by infinity: double
+-1 division by infinity: double
+infinity division by zero: double
+infinity division by String: double
+local undefined division by local undefined: double
+local undefined multiplication by local undefined: double
+local undefined addition local int: double
+local undefined decrement postfix: double
+local undefined decrement prefix: double
+local int increment postfix: int
+local int increment prefix: int
+local int decrement postfix: int
+local int decrement prefix: int
+local int unary plus: int
+local int unary minus: int
+undefined multiplication by undefined: double
+undefined division by undefined: double
+global int addition global int: int
+global int substraction global int: int
+global int multiplication by global int: int
+global int increment postfix: int
+global int increment prefix: int
+global int decrement postfix: int
+global int decrement prefix: int
+global int unary plus: int
+global int unary minus: int
+global undefined decrement postfix: double
+global undefined decrement prefix: double
+object: object
+object division by object: double
+object division by object: double
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/optimistic_assignment_check_type.js	Mon May 05 14:17:20 2014 +0200
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2014, 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.
+ */
+
+/**
+ * @test
+ * @bug 8036987, 8037572
+ * @summary Implement tests that checks static types in the compiled code
+ * @run
+ */
+
+var inspect = Java.type("jdk.nashorn.test.tools.StaticTypeInspector").inspect
+var a = b = 3;
+var c;
+var x = { a: 2, b:1, c: 7, d: -1, e: 1}
+var y = { a: undefined, b: undefined}
+
+// Testing assignment operators
+//-- Global variable
+print(inspect(a=c, "global int assignment to global variable"))
+print(inspect(a=b, "undefined assignment to global int"))
+print(inspect(a=y.a, "global int assignment to undefined"))
+print(inspect(a+=b, "undefined addition assignment to global int"))
+print(inspect(b=b+b, "global int addition global int"))
+print(inspect(b+= y.a, "global int addition assignment undefined"))
+//--Local variable
+print(inspect(x.a+= y.a, "local int addition assignment local undefined"))
+print(inspect(x.b=y.a, "local int assignment to undefined"))
+print(inspect(y.a+=y.a, "local undefined addition assignment local undefined"))
+print(inspect(x.c-=x.d, "local int substraction assignment local int"))
+print(inspect(x.c*=x.d, "local int multiplication assignment local int"))
+print(inspect(x.c/=x.d, "local int division assignment local int"))
+print(inspect(y.b=x.c, "local undefined assignment to local int"))
+print(inspect(y.c=x.c, "local boolean assignment to local int"))
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/optimistic_assignment_check_type.js.EXPECTED	Mon May 05 14:17:20 2014 +0200
@@ -0,0 +1,14 @@
+global int assignment to global variable: undefined
+undefined assignment to global int: int
+global int assignment to undefined: undefined
+undefined addition assignment to global int: double
+global int addition global int: int
+global int addition assignment undefined: double
+local int addition assignment local undefined: double
+local int assignment to undefined: undefined
+local undefined addition assignment local undefined: double
+local int substraction assignment local int: int
+local int multiplication assignment local int: int
+local int division assignment local int: int
+local undefined assignment to local int: int
+local boolean assignment to local int: int
\ No newline at end of file
--- a/nashorn/test/script/basic/optimistic_check_type.js	Fri May 02 18:22:29 2014 +0200
+++ b/nashorn/test/script/basic/optimistic_check_type.js	Mon May 05 14:17:20 2014 +0200
@@ -22,72 +22,78 @@
  */
 
 /**
- * JDK-8036987 : Implement tests that checks static types in the compiled code
  * @test
+ * @bug 8036987, 8037572 
+ * @summary Implement tests that checks static types in the compiled code 
  * @run
  */
 
 var inspect = Java.type("jdk.nashorn.test.tools.StaticTypeInspector").inspect
-var a=3,b,c,z,y;
-
-// Testing arithmetic operators
-print(inspect(y*z, "undefined value multiplication by undefined value"))
-print(inspect(y/z, "undefined value division by undefined value"))
+var a=3, b=2.3, c=true, d;
+var x = { a: 2, b:0, c:undefined}
+var trees = new Array("redwood", "bay", "cedar", "oak");
 
-var x = { a: 2, b:1 }
-print(inspect(x.a*x.b, "int multiplication by int"))
-print(inspect(x.a/x.b, "int division by int without remainder"))
-
-x.a = 7;
-x.b = 2;
-print(inspect(x.a/x.b, "int division by int with remainder"))
-print(inspect(x.a%x.b, "int modulus by int"))
-print(inspect(x.a+x.b, "int plus int"))
+// Testing conditional operator         
+print(inspect("" ? b : x.a, "ternary operator"))
+print(inspect(x.b ? b : x.a, "ternary operator"))
+print(inspect(c ? b : a, "ternary operator"))                      
+print(inspect(!c ? b : a, "ternary operator"))
+print(inspect(d ? b : x.c, "ternary operator"))
+print(inspect(x.c ? a : c, "ternary operator"))
+print(inspect(c ? d : a, "ternary operator"))
+print(inspect(c ? +a : b, "ternary operator"))  
 
-x.a = Number.MAX_VALUE;
-x.b = Number.MAX_VALUE;
-print(inspect(x.a*x.b, "max value multiplication by max value"))
-
-x.a = Number.POSITIVE_INFINITY;
-x.b = Number.POSITIVE_INFINITY;
-print(inspect(x.a*x.b, "infinity multiplication by infinity"))
+// Testing format methods                    
+print(inspect(b.toFixed(2), "global double toFixed()"))
+print(inspect(b.toPrecision(2)/1, "global double toPrecision() divided by 1"))
+print(inspect(b.toExponential(2), "global double toExponential()"))
 
-x.a = -1;
-x.b = Number.POSITIVE_INFINITY;
-print(inspect(x.a/x.b, "-1 division by infinity"))
-
-x.a = Number.POSITIVE_INFINITY;
-x.b = 0;
-print(inspect(x.a/x.b, "infinity division by zero"))
-
-x.a = Number.POSITIVE_INFINITY;
-x.b = 'Hello';
-print(inspect(x.a/x.b, "infinity division by String"))
+// Testing arrays
+print(inspect(trees[1], "member object"))
+trees[1] = undefined; 
+print(inspect(trees[1], "member undefined"))
+print(inspect(1 in trees ? b : a, "conditional on array member"))
+delete trees[2]
+print(inspect(2 in trees ? b : a, "conditional on array member"))
+print(inspect(3 in trees ? trees[2]="bay" : a, "conditional on array member"))
+print(inspect("oak" in trees ? b : a, "conditional on array member"))
 
 // Testing nested functions and return value 
-function f() {
+function f1() {
     var x = 2, y = 1;
     function g() {
         print(inspect(x, "outer local variable"));
         print(inspect(a, "global variable"));
-        print(inspect(x*y, "outer local variable multiplication by outer local variable"));
-        print(inspect(a*b, "global variable multiplication by global variable undefined"));
+        print(inspect(x*y, "outer local int multiplication by outer local int"));
+        print(inspect(a*d, "global int multiplication by global undefined"));
     }
     g()
 }
-f()
-
-function f1(a,b,c) {
-    d = (a+b) * c;
-    print(inspect(c, "c"));
-    print(inspect(a+b, "a+b"));
-    print(inspect(d, "d"));
-}
 f1()
 
+function f2(a,b,c) {
+    g = (a+b) * c;
+    print(inspect(c, "local undefined"));
+    print(inspect(a+b, "local undefined addition local undefined"));
+    print(inspect(g, "local undefined multiplication by undefined"));
+}
+f2()
 
-function f2(a,b) {
-    d = a && b;
-    print(inspect(d, "d"));
+function f3(a,b) {
+    g = a && b;
+    print(inspect(g, "local undefined AND local undefined"));
+    print(inspect(c||g, "global true OR local undefined"));
 }
-f2()
\ No newline at end of file
+f3()
+
+function f4() {
+    var x = true, y = 0;
+    function g() {
+        print(inspect(x+y, "outer local true addition local int"));
+        print(inspect(a+x, "global int addition outer local true"));
+        print(inspect(x*y, "outer local true multiplication by outer local int"));
+        print(inspect(y*d, "outer local int multiplication by global undefined"));
+    }
+    g()
+}
+f4()
\ No newline at end of file
--- a/nashorn/test/script/basic/optimistic_check_type.js.EXPECTED	Fri May 02 18:22:29 2014 +0200
+++ b/nashorn/test/script/basic/optimistic_check_type.js.EXPECTED	Mon May 05 14:17:20 2014 +0200
@@ -1,20 +1,30 @@
-undefined value multiplication by undefined value: double
-undefined value division by undefined value: double
-int multiplication by int: int
-int division by int without remainder: int
-int division by int with remainder: double
-int modulus by int: int
-int plus int: int
-max value multiplication by max value: double
-infinity multiplication by infinity: double
--1 division by infinity: double
-infinity division by zero: double
-infinity division by String: double
+ternary operator: int
+ternary operator: int
+ternary operator: double
+ternary operator: int
+ternary operator: undefined
+ternary operator: boolean
+ternary operator: undefined
+ternary operator: int
+global double toFixed(): object
+global double toPrecision() divided by 1: double
+global double toExponential(): object
+member object: object
+member undefined: undefined
+conditional on array member: double
+conditional on array member: int
+conditional on array member: object
+conditional on array member: int
 outer local variable: int
 global variable: int
-outer local variable multiplication by outer local variable: int
-global variable multiplication by global variable undefined: double
-c: undefined
-a+b: double
-d: double
-d: undefined
\ No newline at end of file
+outer local int multiplication by outer local int: int
+global int multiplication by global undefined: double
+local undefined: undefined
+local undefined addition local undefined: double
+local undefined multiplication by undefined: double
+local undefined AND local undefined: undefined
+global true OR local undefined: boolean
+outer local true addition local int: double
+global int addition outer local true: double
+outer local true multiplication by outer local int: double
+outer local int multiplication by global undefined: double
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/optimistic_logical_check_type.js	Mon May 05 14:17:20 2014 +0200
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2014, 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.
+ */
+
+/**
+ * @test
+ * @bug 8036987, 8037572 
+ * @summary Implement tests that checks static types in the compiled code
+ * @run
+ */
+
+var inspect = Java.type("jdk.nashorn.test.tools.StaticTypeInspector").inspect
+var a = 3, b = true, c = 0;
+var x = { a: 2, b: undefined, c: true}
+
+// Testing logical operators
+//-- Global variable
+print(inspect("cat" && "dog", "object AND object"))
+print(inspect(b && a, "true AND non-falsey global int"))
+print(inspect(a && b, "non-falsey global int AND true"))
+print(inspect(x && b, "non-falsey object AND true"))
+print(inspect(b && x, "true AND non-falsey object"))
+print(inspect("cat" || "dog", "object OR object"))
+print(inspect(b || a, "true OR non-falsey global int"))
+print(inspect(a || b, "non-falsey global int OR true"))
+print(inspect(x || b, "non-falsey object OR true"))
+print(inspect(b || x, "true OR non-falsey object"))
+print(inspect(!x.c || b, "false OR true"))
+print(inspect(c && b, "falsey global int AND true"))
+print(inspect(c || x.b, "falsey global int OR undefined"))
+print(inspect(!c || x.b, "logical not falsey global int OR undefined"))
+print(inspect(!b || x.b, "false OR undefined"))
+print(inspect(!b || c, "false OR falsey global int"))
+print(inspect(!c || c, "logical not falsey global int OR falsey global int"))
+ //--Local variable
+print(inspect(x.b && a, "local undefined AND non-falsey global int"))
+print(inspect(b && x.b, "true AND local undefined"))
+print(inspect(x.b && x.a, "local undefined AND non-falsey local int"))
+print(inspect(x.b || b, "local undefined OR true"))
+print(inspect(b || x.b, "true OR local undefined"))
+print(inspect(x.a && x.c, "non-falsey local int AND true"))
+print(inspect(x.c && x.a, "true AND non-falsey local int"))
+print(inspect(x.c && !!x.a, "true AND double logical not non-falsey local int "))
+print(inspect(!x.c && x.a, "false AND non-falsey local int"))
+print(inspect(x.a || x.c, "non-falsey local int OR true"))
+print(inspect(!x.c || x.c, "false OR true"))
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/optimistic_logical_check_type.js.EXPECTED	Mon May 05 14:17:20 2014 +0200
@@ -0,0 +1,28 @@
+object AND object: object
+true AND non-falsey global int: int
+non-falsey global int AND true: boolean
+non-falsey object AND true: boolean
+true AND non-falsey object: object
+object OR object: object
+true OR non-falsey global int: boolean
+non-falsey global int OR true: int
+non-falsey object OR true: object
+true OR non-falsey object: boolean
+false OR true: boolean
+falsey global int AND true: int
+falsey global int OR undefined: undefined
+logical not falsey global int OR undefined: boolean
+false OR undefined: undefined
+false OR falsey global int: int
+logical not falsey global int OR falsey global int: boolean
+local undefined AND non-falsey global int: undefined
+true AND local undefined: undefined
+local undefined AND non-falsey local int: undefined
+local undefined OR true: boolean
+true OR local undefined: boolean
+non-falsey local int AND true: boolean
+true AND non-falsey local int: int
+true AND double logical not non-falsey local int : boolean
+false AND non-falsey local int: boolean
+non-falsey local int OR true: int
+false OR true: boolean
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/currently-failing/optimistic_check_type_cases.js	Mon May 05 14:17:20 2014 +0200
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2014, 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.
+ */
+
+/**
+ * @test
+ * @bug 8035652,8037858
+ * @summary Implement tests that checks static types in the compiled code
+ * @run
+ */
+
+var inspect = Java.type("jdk.nashorn.test.tools.StaticTypeInspector").inspect
+var a = b = c = 3;
+
+//JDK-8035652
+print(inspect(a/a, "global int division by global int"))
+print(inspect(a%a, "global int modulus by global int"))
+print(inspect(b+=b, "global int addition assignment global int"))
+//JDK-8037858
+print(inspect(b-=b, "global int substraction assignment global int"))
+print(inspect(c*=a, "global int multiplication assignment global int"))
+print(inspect(a/=a, "global int division assignment global int"))
+print(inspect(c%=c, "global int modulo assignment global int"))
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/currently-failing/optimistic_check_type_cases.js.EXPECTED	Mon May 05 14:17:20 2014 +0200
@@ -0,0 +1,7 @@
+global int division by global int: int
+global int modulus by global int: int
+global int addition assignment global int: int
+global int substraction assignment global int: int
+global int multiplication assignment global int: int
+global int division assignment global int: int
+global int modulo assignment global int: int
\ No newline at end of file