Merge
authorlana
Thu, 22 Sep 2016 18:32:42 +0000
changeset 41144 44c67c27002d
parent 41141 e188c189245a (current diff)
parent 41143 7a3195db5d86 (diff)
child 41145 b9a1cb9ed1d3
Merge
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/resources/Functions.properties	Thu Sep 22 16:41:15 2016 +0000
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/resources/Functions.properties	Thu Sep 22 18:32:42 2016 +0000
@@ -190,3 +190,105 @@
 
 Number.prototype.toPrecision=returns a string representing the number to a specified precision in fixed-point or exponential notation
 
+Date.parse=returns a number, the UTC time value corresponding to the date and time interpreted from the given string argument, returns NAN if the argument is not recognized
+
+Date.UTC=returns the number of milliseconds in the given date object since January 1, 1970, 00:00:00 universal time
+
+Date.now=returns the number of milliseconds elapsed since January 1, 1970, 00:00:00 UTC
+
+Date.prototype.toString=returns the string value representing the given date object
+
+Date.prototype.toDateString=returns the string value representing the date portion of the given date object
+
+Date.prototype.toTimeString=returns the string value representing the time portion of the given date object
+
+Date.prototype.toLocaleString=returns the string value representing the date according to language specific conventions
+
+Date.prototype.toLocaleDateString=returns the string value representing the date portion of the given date object according to language specific conventions
+
+Date.prototype.toLocaleTimeString=returns the string value representing the time portion of the given date object according to language specific conventions
+
+Date.prototype.valueOf=returns the number of milliseconds between January 1, 1970, 00:00:00 UTC and the given date
+
+Date.prototype.getTime=returns the number representing milliseconds elapsed between January 1, 1970, 00:00:00 UTC and the given date
+
+Date.prototype.getFullYear=returns the year of the given date according to local time
+
+Date.prototype.getUTCFullYear=returns the year of the given date according to universal time
+
+Date.prototype.getMonth=returns the month between 0 to 11 of the given date according to local time
+
+Date.prototype.getUTCMonth=returns the month between 0 and 11 of the given date according to universal time
+
+Date.prototype.getDate=returns the day of the month for the given date according to local time
+
+Date.prototype.getUTCDate=returns the day of the month for the given date according to universal time
+
+Date.prototype.getDay=returns the day of the week for the given date according to local time, 0 represents Sunday
+
+Date.prototype.getUTCDay=returns the day of the week for the given date according to universal time, 0 represents Sunday
+
+Date.prototype.getHours=returns the hour in the given date, according to local time
+
+Date.prototype.getUTCHours=returns the hour in the given date, according to universal time
+
+Date.prototype.getMinutes=returns the minutes in the given date, according to local time
+
+Date.prototype.getUTCMinutes=returns the minutes in the given date, according to universal time
+
+Date.prototype.getSeconds=returns the seconds in the given date, according to local time
+
+Date.prototype.getUTCSeconds=returns the seconds in the given date, according to universal time
+
+Date.prototype.getMilliseconds=returns the milliseconds in the given date, according to local time
+
+Date.prototype.getUTCMilliseconds=returns the milliseconds in the given date, according to universal time
+
+Date.prototype.getTimezoneOffset=returns the difference between local time and UTC time in minutes
+
+Date.prototype.setTime=sets the date object to the time given, which is represented by the number of milliseconds since January 1, 1970, 00:00:00 UTC
+
+Date.prototype.setMilliseconds=sets the milliseconds for the given date according to local time
+
+Date.prototype.setUTCMilliseconds=sets the milliseconds for the given date according to universal time
+
+Date.prototype.setSeconds=sets the seconds for the given date according to local time
+
+Date.prototype.setUTCSeconds=sets the seconds for the given date according to universal time
+
+Date.prototype.setMinutes=sets the minutes for the given date according to local time
+
+Date.prototype.setUTCMinutes=sets the minutes for the given date according to universal time
+
+Date.prototype.setHours=sets the hours for the given date according to local time
+
+Date.prototype.setUTCHours=sets the hours for the given date according to universal time
+
+Date.prototype.setDate=sets the day of the month for the given date according to local time
+
+Date.prototype.setUTCDate=sets the day of the month for the given date according to universal time
+
+Date.prototype.setMonth=sets the month for the given date according to the currently set year
+
+Date.prototype.setUTCMonth=sets the month for the given date according to the universal time
+
+Date.prototype.setFullYear=sets the full year for the given date according to local time
+
+Date.prototype.toUTCString=converts the given date to a string using UTC time zone
+
+Date.prototype.toISOString=returns the string value in ISO 8601 format for the given date according to universal time
+
+Date.prototype.toJSON=returns the string representation of the given date
+
+RegExp.prototype.exec=returns an array object containing the results of match of given string against regular expression, null if no match found
+
+RegExp.prototype.test=returns true if match of given string against regular expression found, else returns false
+
+RegExp.prototype.toString=returns string representation of regular expression
+
+Error.prototype.toString=returns string representation of error object
+
+JSON.parse=returns an object by parsing given string as JSON
+
+JSON.stringify=returns a JSON string corresponding to the given ECMAScript value
+
--- a/nashorn/test/script/trusted/JDK-8006529.js	Thu Sep 22 16:41:15 2016 +0000
+++ b/nashorn/test/script/trusted/JDK-8006529.js	Thu Sep 22 18:32:42 2016 +0000
@@ -38,7 +38,7 @@
  * We cannot use direct Java class (via dynalink bean linker) to Compiler
  * and FunctionNode because of package-access check and so reflective calls.
  */
-
+var Reflector           = Java.type("jdk.nashorn.test.models.Reflector");
 var forName             = java.lang.Class["forName(String)"];
 var Parser              = forName("jdk.nashorn.internal.parser.Parser").static
 var Compiler            = forName("jdk.nashorn.internal.codegen.Compiler").static
@@ -69,7 +69,11 @@
 var lhsMethod = BinaryNode.class.getMethod("lhs")
 var binaryRhsMethod = BinaryNode.class.getMethod("rhs")
 var debugIdMethod = Debug.class.getMethod("id", java.lang.Object.class)
-var compilePhases = CompilationPhases.class.getField("COMPILE_UPTO_BYTECODE").get(null);
+var compilePhases = Reflector.get(CompilationPhases.class.getField("COMPILE_UPTO_BYTECODE"), null);
+
+function invoke(m, obj) {
+    return Reflector.invoke(m, obj);
+}
 
 // These are method names of methods in FunctionNode class
 var allAssertionList = ['isVarArg', 'needsParentScope', 'needsCallee', 'hasScopeBlock', 'usesSelfSymbol', 'isSplit', 'hasEval', 'allVarsInScope', 'isStrict']
@@ -86,7 +90,7 @@
 
 // returns functionNode.getBody().getStatements().get(0)
 function getFirstFunction(functionNode) {
-    var f = findFunction(getBodyMethod.invoke(functionNode))
+    var f = findFunction(invoke(getBodyMethod, functionNode))
     if (f == null) {
         throw new Error();
     }
@@ -95,7 +99,7 @@
 
 function findFunction(node) {
     if(node instanceof Block) {
-        var stmts = getStatementsMethod.invoke(node)
+        var stmts = invoke(getStatementsMethod, node)
         for(var i = 0; i < stmts.size(); ++i) {
             var retval = findFunction(stmts.get(i))
             if(retval != null) {
@@ -103,13 +107,13 @@
             }
         }
     } else if(node instanceof VarNode) {
-        return findFunction(getInitMethod.invoke(node))
+        return findFunction(invoke(getInitMethod, node))
     } else if(node instanceof UnaryNode) {
-        return findFunction(rhsMethod.invoke(node))
+        return findFunction(invoke(rhsMethod, node))
     } else if(node instanceof BinaryNode) {
-        return findFunction(lhsMethod.invoke(node)) || findFunction(binaryRhsMethod.invoke(node))
+        return findFunction(invoke(lhsMethod, node)) || findFunction(invoke(binaryRhsMethod, node))
     } else if(node instanceof ExpressionStatement) {
-        return findFunction(getExpressionMethod.invoke(node))
+        return findFunction(invoke(getExpressionMethod, node))
     } else if(node instanceof FunctionNode) {
         return node
     }
@@ -131,12 +135,12 @@
     var ctxt = getContextMethod.invoke(null);
     var env = getEnvMethod.invoke(ctxt);
 
-    var parser   = ParserConstructor.newInstance(env, source, ThrowErrorManager.class.newInstance());
-    var func     = parseMethod.invoke(parser);
+    var parser   = Reflector.newInstance(ParserConstructor, env, source, ThrowErrorManager.class.newInstance());
+    var func     = invoke(parseMethod, parser);
 
-    var compiler = CompilerConstructor.invoke(null, ctxt, source, false);
+    var compiler = Reflector.invoke(CompilerConstructor, null, ctxt, source, false);
 
-    return compileMethod.invoke(compiler, func, phases);
+    return Reflector.invoke(compileMethod, compiler, func, phases);
 };
 
 var allAssertions = (function() {
@@ -161,9 +165,10 @@
     }
     for(var assertion in allAssertions) {
         var expectedValue = !!assertions[assertion]
-        var actualValue = functionNodeMethods[assertion].invoke(f)
+        var actualValue = invoke(functionNodeMethods[assertion], f)
         if(actualValue !== expectedValue) {
-            throw "Expected " + assertion + " === " + expectedValue + ", got " + actualValue + " for " + f + ":" + debugIdMethod.invoke(null, f);
+            throw "Expected " + assertion + " === " + expectedValue + ", got " + actualValue + " for " + f + ":" 
+                + invoke(debugIdMethod, null, f);
         }
     }
 }
--- a/nashorn/test/script/trusted/event_queue.js	Thu Sep 22 16:41:15 2016 +0000
+++ b/nashorn/test/script/trusted/event_queue.js	Thu Sep 22 18:32:42 2016 +0000
@@ -36,6 +36,7 @@
 print(Debug);
 print();
 
+var Reflector     = Java.type("jdk.nashorn.test.models.Reflector");
 var forName       = java.lang.Class["forName(String)"];
 var RuntimeEvent  = forName("jdk.nashorn.internal.runtime.events.RuntimeEvent").static;
 var getValue      = RuntimeEvent.class.getMethod("getValue");
@@ -84,19 +85,19 @@
     var e = events[i];
     print("event #" + i);
     print("\tevent class=" + e.getClass());
-    print("\tvalueClass in event=" + getValueClass.invoke(e));
-    var v = getValue.invoke(e);
+    print("\tvalueClass in event=" + Reflector.invoke(getValueClass, e));
+    var v = Reflector.invoke(getValue, e);
     print("\tclass of value=" + v.getClass());
-    print("\treturn type=" + getReturnType.invoke(v));
+    print("\treturn type=" + Reflector.invoke(getReturnType, v));
     lastInLoop = events[i];
 }
 
 print();
 print("in loop last class = " + lastInLoop.getClass());
-print("in loop last value class = " + getValueClass.invoke(lastInLoop));
-var rexInLoop = getValue.invoke(lastInLoop);
+print("in loop last value class = " + Reflector.invoke(getValueClass, lastInLoop));
+var rexInLoop = Reflector.invoke(getValue, lastInLoop);
 print("in loop rex class = " + rexInLoop.getClass());
-print("in loop rex return type = " + getReturnType.invoke(rexInLoop));
+print("in loop rex return type = " + Reflector.invoke(getReturnType, rexInLoop));
 
 //try last runtime events
 var last = Debug.getLastRuntimeEvent();
@@ -106,10 +107,10 @@
 print();
 
 print("last class = " + last.getClass());
-print("last value class = " + getValueClass.invoke(last));
-var rex = getValue.invoke(last);
+print("last value class = " + Reflector.invoke(getValueClass, last));
+var rex = Reflector.invoke(getValue, last);
 print("rex class = " + rex.getClass());
-print("rex return type = " + getReturnType.invoke(rex));
+print("rex return type = " + Reflector.invoke(getReturnType, rex));
 
 //try the capacity setter
 print();
--- a/nashorn/test/script/trusted/optimistic_recompilation.js	Thu Sep 22 16:41:15 2016 +0000
+++ b/nashorn/test/script/trusted/optimistic_recompilation.js	Thu Sep 22 18:32:42 2016 +0000
@@ -32,6 +32,7 @@
  * @run
  */
 
+var Reflector     = Java.type("jdk.nashorn.test.models.Reflector");
 var forName       = java.lang.Class["forName(String)"];
 var RuntimeEvent  = forName("jdk.nashorn.internal.runtime.events.RuntimeEvent").static;
 var getValue      = RuntimeEvent.class.getMethod("getValue");
@@ -42,6 +43,10 @@
 var setReturnTypeAndValue = [];
 var expectedValues = [];
 
+function invoke(m, obj) {
+    return Reflector.invoke(m, obj);
+}
+
 function checkExpectedRecompilation(f, expectedValues, testCase) {
     Debug.clearRuntimeEvents();
     print(f());
@@ -51,12 +56,12 @@
     if (events.length ==  expectedValues.length) {
         for (var i in events) {
             var e = events[i];
-            var returnValue = getReturnValue.invoke(e);
+            var returnValue = invoke(getReturnValue, e);
             if (typeof returnValue != 'undefined') {
-            setReturnTypeAndValue[i] = [getReturnType.invoke(getValue.invoke(e)), returnValue];
+                setReturnTypeAndValue[i] = [invoke(getReturnType, invoke(getValue, e)), returnValue];
             } else {
                 returnValue = "undefined";
-                setReturnTypeAndValue[i] = [getReturnType.invoke(getValue.invoke(e)), returnValue];
+                setReturnTypeAndValue[i] = [invoke(getReturnType, invoke(getValue, e)), returnValue];
             }
             if (!setReturnTypeAndValue[i].toString().equals(expectedValues[i].toString())) {
                 fail("The return values are not as expected. Expected value: " + expectedValues[i] + " and got: " + setReturnTypeAndValue[i] + " in test case: " + f);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/src/jdk/nashorn/test/models/Reflector.java	Thu Sep 22 18:32:42 2016 +0000
@@ -0,0 +1,92 @@
+/*
+ * 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.
+ */
+
+package jdk.nashorn.test.models;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Module;
+import jdk.nashorn.internal.runtime.Context;
+
+/**
+ * Few tests reflectively invoke or read fields of Nashorn classes
+ * and objects - but of packages that are not exported to any module!
+ * But, those packages are qualified exported to test [java] code
+ * such as this class. So, test scripts can invoke the methods of this
+ * class instead.
+ */
+public final class Reflector {
+    private Reflector() {}
+    private static final Module NASHORN_MOD = Context.class.getModule();
+
+    public static Object invoke(Method m, Object self, Object...args) {
+        if (m.getDeclaringClass().getModule() != NASHORN_MOD) {
+            throw new RuntimeException(m + " is not from Nashorn module");
+        }
+
+        try {
+            return m.invoke(self, args);
+        } catch (final Exception e) {
+            if (e instanceof RuntimeException) {
+                throw (RuntimeException)e;
+            } else {
+                throw new RuntimeException(e);
+            }
+        }
+    }
+
+    public static Object newInstance(Constructor c, Object...args) {
+        if (c.getDeclaringClass().getModule() != NASHORN_MOD) {
+            throw new RuntimeException(c + " is not from Nashorn module");
+        }
+
+        try {
+            return c.newInstance(args);
+        } catch (final Exception e) {
+            if (e instanceof RuntimeException) {
+                throw (RuntimeException)e;
+            } else {
+                throw new RuntimeException(e);
+            }
+        }
+    }
+
+    public static Object get(Field f, Object self) {
+        if (f.getDeclaringClass().getModule() != NASHORN_MOD) {
+            throw new RuntimeException(f + " is not from Nashorn module");
+        }
+
+        try {
+            return f.get(self);
+        } catch (final Exception e) {
+            if (e instanceof RuntimeException) {
+                throw (RuntimeException)e;
+            } else {
+                throw new RuntimeException(e);
+            }
+        }
+    }
+}