Merge
authorlana
Tue, 01 Apr 2014 17:28:17 -0700
changeset 23765 0c4a328645ef
parent 23420 c826d05f1fb0 (current diff)
parent 23764 1feafd50182e (diff)
child 23766 a3ef17770bab
Merge
--- a/nashorn/README	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/README	Tue Apr 01 17:28:17 2014 -0700
@@ -81,13 +81,13 @@
     
 After that, you can run the tests using:
     cd make
-    ant test
+    ant clean test
     
 You can also run the ECMA-262 test suite with Nashorn. In order to do
 that, you will need to get a copy of it and put it in
 test/script/external/test262 directory. A convenient way to do it is:
 
-   hg clone http://hg.ecmascript.org/tests/test262/ test/script/external/test262
+   git clone https://github.com/tc39/test262 test/script/external/test262
     
 Alternatively, you can check it out elsewhere and make
 test/script/external/test262 a symbolic link to that directory. After
@@ -95,6 +95,11 @@
 
     cd nashorn~jdk8/nashorn/make
     ant test262
+
+Ant target to get/update external test suites:
+
+    ant externals
+    ant update-externals
     
 These tests take time, so we have a parallelized runner for them that
 takes advantage of all processor cores on the computer:
--- a/nashorn/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/MemberInfo.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/MemberInfo.java	Tue Apr 01 17:28:17 2014 -0700
@@ -22,40 +22,62 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
-
 package jdk.nashorn.internal.tools.nasgen;
 
 import static jdk.nashorn.internal.tools.nasgen.StringConstants.OBJECT_ARRAY_DESC;
 import static jdk.nashorn.internal.tools.nasgen.StringConstants.OBJECT_DESC;
+import static jdk.nashorn.internal.tools.nasgen.StringConstants.SCRIPTOBJECT_DESC;
+import static jdk.nashorn.internal.tools.nasgen.StringConstants.STRING_DESC;
 
 import jdk.internal.org.objectweb.asm.Opcodes;
 import jdk.internal.org.objectweb.asm.Type;
 import jdk.nashorn.internal.objects.annotations.Where;
+import jdk.nashorn.internal.runtime.ScriptObject;
 
 /**
  * Details about a Java method or field annotated with any of the field/method
  * annotations from the jdk.nashorn.internal.objects.annotations package.
  */
 public final class MemberInfo implements Cloneable {
+    // class loader of this class
+    private static ClassLoader myLoader = MemberInfo.class.getClassLoader();
+
     /**
      * The different kinds of available class annotations
      */
     public static enum Kind {
-        /** This is a script class */
+
+        /**
+         * This is a script class
+         */
         SCRIPT_CLASS,
-        /** This is a constructor */
+        /**
+         * This is a constructor
+         */
         CONSTRUCTOR,
-        /** This is a function */
+        /**
+         * This is a function
+         */
         FUNCTION,
-        /** This is a getter */
+        /**
+         * This is a getter
+         */
         GETTER,
-        /** This is a setter */
+        /**
+         * This is a setter
+         */
         SETTER,
-        /** This is a property */
+        /**
+         * This is a property
+         */
         PROPERTY,
-        /** This is a specialized version of a function */
+        /**
+         * This is a specialized version of a function
+         */
         SPECIALIZED_FUNCTION,
-        /** This is a specialized version of a constructor */
+        /**
+         * This is a specialized version of a constructor
+         */
         SPECIALIZED_CONSTRUCTOR
     }
 
@@ -194,6 +216,7 @@
 
     /**
      * Check whether this MemberInfo is a getter that resides in the instance
+     *
      * @return true if instance setter
      */
     boolean isInstanceSetter() {
@@ -245,92 +268,201 @@
     }
 
     void verify() {
-        if (kind == Kind.CONSTRUCTOR) {
-            final Type returnType = Type.getReturnType(javaDesc);
-            if (! returnType.toString().equals(OBJECT_DESC)) {
-                error("return value should be of Object type, found" + returnType);
-            }
-            final Type[] argTypes = Type.getArgumentTypes(javaDesc);
-            if (argTypes.length < 2) {
-                error("constructor methods should have at least 2 args");
-            }
-            if (! argTypes[0].equals(Type.BOOLEAN_TYPE)) {
-                error("first argument should be of boolean type, found" + argTypes[0]);
-            }
-            if (! argTypes[1].toString().equals(OBJECT_DESC)) {
-                error("second argument should be of Object type, found" + argTypes[0]);
-            }
+        switch (kind) {
+            case CONSTRUCTOR: {
+                final Type returnType = Type.getReturnType(javaDesc);
+                if (!isJSObjectType(returnType)) {
+                    error("return value of a @Constructor method should be of Object type, found " + returnType);
+                }
+                final Type[] argTypes = Type.getArgumentTypes(javaDesc);
+                if (argTypes.length < 2) {
+                    error("@Constructor methods should have at least 2 args");
+                }
+                if (!argTypes[0].equals(Type.BOOLEAN_TYPE)) {
+                    error("first argument of a @Constructor method should be of boolean type, found " + argTypes[0]);
+                }
+                if (!isJavaLangObject(argTypes[1])) {
+                    error("second argument of a @Constructor method should be of Object type, found " + argTypes[0]);
+                }
 
-            if (argTypes.length > 2) {
-                for (int i = 2; i < argTypes.length - 1; i++) {
-                    if (! argTypes[i].toString().equals(OBJECT_DESC)) {
-                        error(i + "'th argument should be of Object type, found " + argTypes[i]);
+                if (argTypes.length > 2) {
+                    for (int i = 2; i < argTypes.length - 1; i++) {
+                        if (!isJavaLangObject(argTypes[i])) {
+                            error(i + "'th argument of a @Constructor method should be of Object type, found " + argTypes[i]);
+                        }
+                    }
+
+                    final String lastArgTypeDesc = argTypes[argTypes.length - 1].getDescriptor();
+                    final boolean isVarArg = lastArgTypeDesc.equals(OBJECT_ARRAY_DESC);
+                    if (!lastArgTypeDesc.equals(OBJECT_DESC) && !isVarArg) {
+                        error("last argument of a @Constructor method is neither Object nor Object[] type: " + lastArgTypeDesc);
+                    }
+
+                    if (isVarArg && argTypes.length > 3) {
+                        error("vararg of a @Constructor method has more than 3 arguments");
                     }
                 }
-
-                final String lastArgType = argTypes[argTypes.length - 1].toString();
-                final boolean isVarArg = lastArgType.equals(OBJECT_ARRAY_DESC);
-                if (!lastArgType.equals(OBJECT_DESC) && !isVarArg) {
-                    error("last argument is neither Object nor Object[] type: " + lastArgType);
+            }
+            break;
+            case SPECIALIZED_CONSTRUCTOR: {
+                final Type returnType = Type.getReturnType(javaDesc);
+                if (!isJSObjectType(returnType)) {
+                    error("return value of a @SpecializedConstructor method should be a valid JS type, found " + returnType);
                 }
-
-                if (isVarArg && argTypes.length > 3) {
-                    error("vararg constructor has more than 3 arguments");
+                final Type[] argTypes = Type.getArgumentTypes(javaDesc);
+                for (int i = 0; i < argTypes.length; i++) {
+                    if (!isValidJSType(argTypes[i])) {
+                        error(i + "'th argument of a @SpecializedConstructor method is not valid JS type, found " + argTypes[i]);
+                    }
                 }
             }
-        } else if (kind == Kind.FUNCTION) {
-            final Type[] argTypes = Type.getArgumentTypes(javaDesc);
-            if (argTypes.length < 1) {
-                error("function methods should have at least 1 arg");
-            }
-            if (! argTypes[0].toString().equals(OBJECT_DESC)) {
-                error("first argument should be of Object type, found" + argTypes[0]);
-            }
-
-            if (argTypes.length > 1) {
-                for (int i = 1; i < argTypes.length - 1; i++) {
-                    if (! argTypes[i].toString().equals(OBJECT_DESC)) {
-                        error(i + "'th argument should be of Object type, found " + argTypes[i]);
-                    }
+            break;
+            case FUNCTION: {
+                final Type returnType = Type.getReturnType(javaDesc);
+                if (!isValidJSType(returnType)) {
+                    error("return value of a @Function method should be a valid JS type, found " + returnType);
                 }
-
-                final String lastArgType = argTypes[argTypes.length - 1].toString();
-                final boolean isVarArg = lastArgType.equals(OBJECT_ARRAY_DESC);
-                if (!lastArgType.equals(OBJECT_DESC) && !isVarArg) {
-                    error("last argument is neither Object nor Object[] type: " + lastArgType);
+                final Type[] argTypes = Type.getArgumentTypes(javaDesc);
+                if (argTypes.length < 1) {
+                    error("@Function methods should have at least 1 arg");
+                }
+                if (!isJavaLangObject(argTypes[0])) {
+                    error("first argument of a @Function method should be of Object type, found " + argTypes[0]);
                 }
 
-                if (isVarArg && argTypes.length > 2) {
-                    error("vararg function has more than 2 arguments");
+                if (argTypes.length > 1) {
+                    for (int i = 1; i < argTypes.length - 1; i++) {
+                        if (!isJavaLangObject(argTypes[i])) {
+                            error(i + "'th argument of a @Function method should be of Object type, found " + argTypes[i]);
+                        }
+                    }
+
+                    final String lastArgTypeDesc = argTypes[argTypes.length - 1].getDescriptor();
+                    final boolean isVarArg = lastArgTypeDesc.equals(OBJECT_ARRAY_DESC);
+                    if (!lastArgTypeDesc.equals(OBJECT_DESC) && !isVarArg) {
+                        error("last argument of a @Function method is neither Object nor Object[] type: " + lastArgTypeDesc);
+                    }
+
+                    if (isVarArg && argTypes.length > 2) {
+                        error("vararg @Function method has more than 2 arguments");
+                    }
+                }
+            }
+            break;
+            case SPECIALIZED_FUNCTION: {
+                final Type returnType = Type.getReturnType(javaDesc);
+                if (!isValidJSType(returnType)) {
+                    error("return value of a @SpecializedFunction method should be a valid JS type, found " + returnType);
+                }
+                final Type[] argTypes = Type.getArgumentTypes(javaDesc);
+                for (int i = 0; i < argTypes.length; i++) {
+                    if (!isValidJSType(argTypes[i])) {
+                        error(i + "'th argument of a @SpecializedFunction method is not valid JS type, found " + argTypes[i]);
+                    }
                 }
             }
-        } else if (kind == Kind.GETTER) {
-            final Type[] argTypes = Type.getArgumentTypes(javaDesc);
-            if (argTypes.length != 1) {
-                error("getter methods should have one argument");
-            }
-            if (! argTypes[0].toString().equals(OBJECT_DESC)) {
-                error("first argument of getter should be of Object type, found: " + argTypes[0]);
-            }
-            if (Type.getReturnType(javaDesc).equals(Type.VOID_TYPE)) {
-                error("return type of getter should not be void");
+            break;
+            case GETTER: {
+                final Type[] argTypes = Type.getArgumentTypes(javaDesc);
+                if (argTypes.length != 1) {
+                    error("@Getter methods should have one argument");
+                }
+                if (!isJavaLangObject(argTypes[0])) {
+                    error("first argument of a @Getter method should be of Object type, found: " + argTypes[0]);
+                }
+
+                final Type returnType = Type.getReturnType(javaDesc);
+                if (!isJavaLangObject(returnType)) {
+                    error("return type of a @Getter method should be Object, found: " + javaDesc);
+                }
             }
-        } else if (kind == Kind.SETTER) {
-            final Type[] argTypes = Type.getArgumentTypes(javaDesc);
-            if (argTypes.length != 2) {
-                error("setter methods should have two arguments");
+            break;
+            case SETTER: {
+                final Type[] argTypes = Type.getArgumentTypes(javaDesc);
+                if (argTypes.length != 2) {
+                    error("@Setter methods should have two arguments");
+                }
+                if (!isJavaLangObject(argTypes[0])) {
+                    error("first argument of a @Setter method should be of Object type, found: " + argTypes[0]);
+                }
+                if (!Type.getReturnType(javaDesc).toString().equals("V")) {
+                    error("return type of of a @Setter method should be void, found: " + Type.getReturnType(javaDesc));
+                }
             }
-            if (! argTypes[0].toString().equals(OBJECT_DESC)) {
-                error("first argument of setter should be of Object type, found: " + argTypes[0]);
-            }
-            if (!Type.getReturnType(javaDesc).toString().equals("V")) {
-                error("return type of setter should be void, found: " + Type.getReturnType(javaDesc));
+            break;
+            case PROPERTY: {
+                if (where == Where.CONSTRUCTOR) {
+                    if (isStatic()) {
+                        if (!isFinal()) {
+                            error("static Where.CONSTRUCTOR @Property should be final");
+                        }
+
+                        if (!isJSPrimitiveType(Type.getType(javaDesc))) {
+                            error("static Where.CONSTRUCTOR @Property should be a JS primitive");
+                        }
+                    }
+                } else if (where == Where.PROTOTYPE) {
+                    if (isStatic()) {
+                        if (!isFinal()) {
+                            error("static Where.PROTOTYPE @Property should be final");
+                        }
+
+                        if (!isJSPrimitiveType(Type.getType(javaDesc))) {
+                            error("static Where.PROTOTYPE @Property should be a JS primitive");
+                        }
+                    }
+                }
             }
         }
     }
 
+    private static boolean isValidJSType(final Type type) {
+        return isJSPrimitiveType(type) || isJSObjectType(type);
+    }
+
+    private static boolean isJSPrimitiveType(final Type type) {
+        switch (type.getSort()) {
+            case Type.BOOLEAN:
+            case Type.INT:
+            case Type.LONG:
+            case Type.DOUBLE:
+                return true;
+            default:
+                return false;
+        }
+    }
+
+    private static boolean isJSObjectType(final Type type) {
+        return isJavaLangObject(type) || isJavaLangString(type) || isScriptObject(type);
+    }
+
+    private static boolean isJavaLangObject(final Type type) {
+        return type.getDescriptor().equals(OBJECT_DESC);
+    }
+
+    private static boolean isJavaLangString(final Type type) {
+        return type.getDescriptor().equals(STRING_DESC);
+    }
+
+    private static boolean isScriptObject(final Type type) {
+        if (type.getDescriptor().equals(SCRIPTOBJECT_DESC)) {
+            return true;
+        }
+
+        if (type.getSort() == Type.OBJECT) {
+            try {
+                final Class clazz = Class.forName(type.getClassName(), false, myLoader);
+                return ScriptObject.class.isAssignableFrom(clazz);
+            } catch (final ClassNotFoundException cnfe) {
+                return false;
+            }
+        }
+
+        return false;
+    }
+
     private void error(final String msg) {
-        throw new RuntimeException(javaName + javaDesc + " : " + msg);
+        throw new RuntimeException(javaName + " of type " + javaDesc + " : " + msg);
     }
 
     /**
--- a/nashorn/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/StringConstants.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/StringConstants.java	Tue Apr 01 17:28:17 2014 -0700
@@ -61,6 +61,8 @@
     static final String METHODHANDLE_TYPE = TYPE_METHODHANDLE.getInternalName();
     static final String OBJECT_TYPE = TYPE_OBJECT.getInternalName();
     static final String OBJECT_DESC = TYPE_OBJECT.getDescriptor();
+    static final String STRING_TYPE = TYPE_STRING.getInternalName();
+    static final String STRING_DESC = TYPE_STRING.getDescriptor();
     static final String OBJECT_ARRAY_DESC = Type.getDescriptor(Object[].class);
     static final String ARRAYLIST_TYPE = TYPE_ARRAYLIST.getInternalName();
     static final String COLLECTION_TYPE = TYPE_COLLECTION.getInternalName();
@@ -129,6 +131,7 @@
 
     // ScriptObject
     static final String SCRIPTOBJECT_TYPE = TYPE_SCRIPTOBJECT.getInternalName();
+    static final String SCRIPTOBJECT_DESC = TYPE_SCRIPTOBJECT.getDescriptor();
     static final String SCRIPTOBJECT_INIT_DESC = Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_PROPERTYMAP);
 
     static final String GETTER_PREFIX = "G$";
--- a/nashorn/make/build.xml	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/make/build.xml	Tue Apr 01 17:28:17 2014 -0700
@@ -42,6 +42,9 @@
     <condition property="hg.executable" value="/usr/local/bin/hg" else="hg">
       <available file="/usr/local/bin/hg"/>
     </condition>
+    <condition property="git.executable" value="/usr/local/bin/git" else="git">
+      <available file="/usr/local/bin/git"/>
+    </condition>
     <!-- check if JDK already has ASM classes -->
     <available property="asm.available" classname="jdk.internal.org.objectweb.asm.Type"/>
     <!-- check if testng.jar is avaiable -->
@@ -503,18 +506,17 @@
 
   <!-- test262 test suite -->
   <target name="get-test262" depends="init" unless="${test-sys-prop.external.test262}">
-    <!-- clone test262 mercurial repo -->
-    <exec executable="${hg.executable}">
+    <!-- clone test262 git repo -->
+    <exec executable="${git.executable}">
        <arg value="clone"/>
-       <arg value="http://hg.ecmascript.org/tests/test262"/>
+       <arg value="https://github.com/tc39/test262"/>
        <arg value="${test.external.dir}/test262"/>
     </exec>
   </target>
   <target name="update-test262" depends="init" if="${test-sys-prop.external.test262}">
-    <!-- update test262 mercurial repo -->
-    <exec executable="${hg.executable}" dir="${test.external.dir}/test262">
+    <!-- update test262 git repo -->
+    <exec executable="${git.executable}" dir="${test.external.dir}/test262">
        <arg value="pull"/>
-       <arg value="-u"/>
     </exec>
   </target>
 
--- a/nashorn/src/jdk/nashorn/internal/objects/ArrayBufferView.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/src/jdk/nashorn/internal/objects/ArrayBufferView.java	Tue Apr 01 17:28:17 2014 -0700
@@ -382,7 +382,7 @@
         return (int) (length & Integer.MAX_VALUE);
     }
 
-    protected static Object subarrayImpl(final Object self, final Object begin0, final Object end0) {
+    protected static ScriptObject subarrayImpl(final Object self, final Object begin0, final Object end0) {
         final ArrayBufferView arrayView = ((ArrayBufferView)self);
         final int elementLength = arrayView.elementLength();
         final int begin = NativeArrayBuffer.adjustIndex(JSType.toInt32(begin0), elementLength);
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeArray.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeArray.java	Tue Apr 01 17:28:17 2014 -0700
@@ -31,6 +31,7 @@
 import static jdk.nashorn.internal.runtime.PropertyDescriptor.WRITABLE;
 import static jdk.nashorn.internal.runtime.arrays.ArrayLikeIterator.arrayLikeIterator;
 import static jdk.nashorn.internal.runtime.arrays.ArrayLikeIterator.reverseArrayLikeIterator;
+import static jdk.nashorn.internal.runtime.arrays.ArrayIndex.isValidArrayIndex;
 
 import java.lang.invoke.MethodHandle;
 import java.util.ArrayList;
@@ -350,6 +351,27 @@
     }
 
     /**
+     * Spec. mentions use of [[DefineOwnProperty]] for indexed properties in
+     * certain places (eg. Array.prototype.map, filter). We can not use ScriptObject.set
+     * method in such cases. This is because set method uses inherited setters (if any)
+     * from any object in proto chain such as Array.prototype, Object.prototype.
+     * This method directly sets a particular element value in the current object.
+     *
+     * @param index key for property
+     * @param value value to define
+     */
+    @Override
+    public final void defineOwnProperty(final int index, final Object value) {
+        assert isValidArrayIndex(index) : "invalid array index";
+        final long longIndex = ArrayIndex.toLongIndex(index);
+        if (longIndex >= getArray().length()) {
+            // make array big enough to hold..
+            setArray(getArray().ensure(longIndex));
+        }
+        setArray(getArray().set(index, value, false));
+    }
+
+    /**
      * Return the array contents upcasted as an ObjectArray, regardless of
      * representation
      *
@@ -367,7 +389,7 @@
      * @return true if argument is an array
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object isArray(final Object self, final Object arg) {
+    public static boolean isArray(final Object self, final Object arg) {
         return isArray(arg) || (arg instanceof JSObject && ((JSObject)arg).isArray());
     }
 
@@ -466,7 +488,7 @@
      * @return locale specific string representation for array
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object toLocaleString(final Object self) {
+    public static String toLocaleString(final Object self) {
         final StringBuilder sb = new StringBuilder();
         final Iterator<Object> iter = arrayLikeIterator(self, true);
 
@@ -512,7 +534,7 @@
      * @return the new NativeArray
      */
     @Constructor(arity = 1)
-    public static Object construct(final boolean newObj, final Object self, final Object... args) {
+    public static NativeArray construct(final boolean newObj, final Object self, final Object... args) {
         switch (args.length) {
         case 0:
             return new NativeArray(0);
@@ -565,7 +587,7 @@
      * @return the new NativeArray
      */
     @SpecializedConstructor
-    public static Object construct(final boolean newObj, final Object self) {
+    public static NativeArray construct(final boolean newObj, final Object self) {
         return new NativeArray(0);
     }
 
@@ -580,7 +602,7 @@
      * @return the new NativeArray
      */
     @SpecializedConstructor
-    public static Object construct(final boolean newObj, final Object self, final int length) {
+    public static NativeArray construct(final boolean newObj, final Object self, final int length) {
         if (length >= 0) {
             return new NativeArray(length);
         }
@@ -599,7 +621,7 @@
      * @return the new NativeArray
      */
     @SpecializedConstructor
-    public static Object construct(final boolean newObj, final Object self, final long length) {
+    public static NativeArray construct(final boolean newObj, final Object self, final long length) {
         if (length >= 0L && length <= JSType.MAX_UINT) {
             return new NativeArray(length);
         }
@@ -618,7 +640,7 @@
      * @return the new NativeArray
      */
     @SpecializedConstructor
-    public static Object construct(final boolean newObj, final Object self, final double length) {
+    public static NativeArray construct(final boolean newObj, final Object self, final double length) {
         final long uint32length = JSType.toUint32(length);
 
         if (uint32length == length) {
@@ -636,7 +658,7 @@
      * @return resulting NativeArray
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
-    public static Object concat(final Object self, final Object... args) {
+    public static NativeArray concat(final Object self, final Object... args) {
         final ArrayList<Object> list = new ArrayList<>();
         concatToList(list, Global.toObject(self));
 
@@ -683,7 +705,7 @@
      * @return string representation after join
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object join(final Object self, final Object separator) {
+    public static String join(final Object self, final Object separator) {
         final StringBuilder    sb   = new StringBuilder();
         final Iterator<Object> iter = arrayLikeIterator(self, true);
         final String           sep  = separator == ScriptRuntime.UNDEFINED ? "," : JSType.toString(separator);
@@ -951,7 +973,7 @@
      * @return sorted array
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object sort(final Object self, final Object comparefn) {
+    public static ScriptObject sort(final Object self, final Object comparefn) {
         try {
             final ScriptObject sobj    = (ScriptObject) self;
             final long         len     = JSType.toUint32(sobj.getLength());
@@ -1155,7 +1177,7 @@
      * @return index of element, or -1 if not found
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
-    public static Object indexOf(final Object self, final Object searchElement, final Object fromIndex) {
+    public static long indexOf(final Object self, final Object searchElement, final Object fromIndex) {
         try {
             final ScriptObject sobj = (ScriptObject)Global.toObject(self);
             final long         len  = JSType.toUint32(sobj.getLength());
@@ -1191,7 +1213,7 @@
      * @return index of element, or -1 if not found
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
-    public static Object lastIndexOf(final Object self, final Object... args) {
+    public static long lastIndexOf(final Object self, final Object... args) {
         try {
             final ScriptObject sobj = (ScriptObject)Global.toObject(self);
             final long         len  = JSType.toUint32(sobj.getLength());
@@ -1226,7 +1248,7 @@
      * @return true if callback function return true for every element in the array, false otherwise
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
-    public static Object every(final Object self, final Object callbackfn, final Object thisArg) {
+    public static boolean every(final Object self, final Object callbackfn, final Object thisArg) {
         return applyEvery(Global.toObject(self), callbackfn, thisArg);
     }
 
@@ -1250,7 +1272,7 @@
      * @return true if callback function returned true for any element in the array, false otherwise
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
-    public static Object some(final Object self, final Object callbackfn, final Object thisArg) {
+    public static boolean some(final Object self, final Object callbackfn, final Object thisArg) {
         return new IteratorAction<Boolean>(Global.toObject(self), callbackfn, thisArg, false) {
             private final MethodHandle someInvoker = getSOME_CALLBACK_INVOKER();
 
@@ -1291,7 +1313,7 @@
      * @return array with elements transformed by map function
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
-    public static Object map(final Object self, final Object callbackfn, final Object thisArg) {
+    public static NativeArray map(final Object self, final Object callbackfn, final Object thisArg) {
         return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, null) {
             private final MethodHandle mapInvoker = getMAP_CALLBACK_INVOKER();
 
@@ -1320,7 +1342,7 @@
      * @return filtered array
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
-    public static Object filter(final Object self, final Object callbackfn, final Object thisArg) {
+    public static NativeArray filter(final Object self, final Object callbackfn, final Object thisArg) {
         return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, new NativeArray()) {
             private long to = 0;
             private final MethodHandle filterInvoker = getFILTER_CALLBACK_INVOKER();
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeArrayBuffer.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeArrayBuffer.java	Tue Apr 01 17:28:17 2014 -0700
@@ -45,7 +45,7 @@
     private static PropertyMap $nasgenmap$;
 
     @Constructor(arity = 1)
-    public static Object constructor(final boolean newObj, final Object self, final Object... args) {
+    public static NativeArrayBuffer constructor(final boolean newObj, final Object self, final Object... args) {
         if (args.length == 0) {
             throw new RuntimeException("missing length argument");
         }
@@ -81,7 +81,7 @@
     }
 
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object slice(final Object self, final Object begin0, final Object end0) {
+    public static NativeArrayBuffer slice(final Object self, final Object begin0, final Object end0) {
         final NativeArrayBuffer arrayBuffer = (NativeArrayBuffer)self;
         int begin = JSType.toInt32(begin0);
         int end = end0 != ScriptRuntime.UNDEFINED ? JSType.toInt32(end0) : arrayBuffer.getByteLength();
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeBoolean.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeBoolean.java	Tue Apr 01 17:28:17 2014 -0700
@@ -110,7 +110,7 @@
      * @return string representation of this boolean
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object toString(final Object self) {
+    public static String toString(final Object self) {
         return getBoolean(self).toString();
     }
 
@@ -121,7 +121,7 @@
      * @return value of this boolean
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object valueOf(final Object self) {
+    public static boolean valueOf(final Object self) {
         return getBoolean(self);
     }
 
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeDataView.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeDataView.java	Tue Apr 01 17:28:17 2014 -0700
@@ -131,7 +131,7 @@
      * @return newly constructed DataView object
      */
     @Constructor(arity = 1)
-    public static Object constructor(final boolean newObj, final Object self, final Object... args) {
+    public static NativeDataView constructor(final boolean newObj, final Object self, final Object... args) {
         if (args.length == 0 || !(args[0] instanceof NativeArrayBuffer)) {
             throw typeError("not.an.arraybuffer.in.dataview");
         }
@@ -157,7 +157,7 @@
      * @return newly constructed DataView object
      */
     @SpecializedConstructor
-    public static Object constructor(final boolean newObj, final Object self, final Object arrBuf, final int offset) {
+    public static NativeDataView constructor(final boolean newObj, final Object self, final Object arrBuf, final int offset) {
         if (!(arrBuf instanceof NativeArrayBuffer)) {
             throw typeError("not.an.arraybuffer.in.dataview");
         }
@@ -175,7 +175,7 @@
      * @return newly constructed DataView object
      */
     @SpecializedConstructor
-    public static Object constructor(final boolean newObj, final Object self, final Object arrBuf, final int offset, final int length) {
+    public static NativeDataView constructor(final boolean newObj, final Object self, final Object arrBuf, final int offset, final int length) {
         if (!(arrBuf instanceof NativeArrayBuffer)) {
             throw typeError("not.an.arraybuffer.in.dataview");
         }
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeDate.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeDate.java	Tue Apr 01 17:28:17 2014 -0700
@@ -226,7 +226,7 @@
      * @return Date interpreted from the string, or NaN for illegal values
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object parse(final Object self, final Object string) {
+    public static double parse(final Object self, final Object string) {
         return parseDateString(JSType.toString(string));
     }
 
@@ -238,7 +238,7 @@
      * @return a time clip according to the ECMA specification
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 7, where = Where.CONSTRUCTOR)
-    public static Object UTC(final Object self, final Object... args) {
+    public static double UTC(final Object self, final Object... args) {
         final NativeDate nd = new NativeDate(0);
         final double[] d = convertCtorArgs(args);
         final double time = d == null ? Double.NaN : timeClip(makeDate(d));
@@ -253,8 +253,8 @@
      * @return a Date that points to the current moment in time
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object now(final Object self) {
-        return (double)System.currentTimeMillis();
+    public static long now(final Object self) {
+        return System.currentTimeMillis();
     }
 
     /**
@@ -264,7 +264,7 @@
      * @return string value that represents the Date in the current time zone
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object toString(final Object self) {
+    public static String toString(final Object self) {
         return toStringImpl(self, FORMAT_DATE_TIME);
     }
 
@@ -275,7 +275,7 @@
      * @return string value with the "date" part of the Date in the current time zone
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object toDateString(final Object self) {
+    public static String toDateString(final Object self) {
         return toStringImpl(self, FORMAT_DATE);
     }
 
@@ -286,7 +286,7 @@
      * @return string value with "time" part of Date in the current time zone
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object toTimeString(final Object self) {
+    public static String toTimeString(final Object self) {
         return toStringImpl(self, FORMAT_TIME);
     }
 
@@ -297,7 +297,7 @@
      * @return string value that represents the Data in the current time zone and locale
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object toLocaleString(final Object self) {
+    public static String toLocaleString(final Object self) {
         return toStringImpl(self, FORMAT_LOCAL_DATE_TIME);
     }
 
@@ -308,7 +308,7 @@
      * @return string value with the "date" part of the Date in the current time zone and locale
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object toLocaleDateString(final Object self) {
+    public static String toLocaleDateString(final Object self) {
         return toStringImpl(self, FORMAT_LOCAL_DATE);
     }
 
@@ -319,7 +319,7 @@
      * @return string value with the "time" part of Date in the current time zone and locale
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object toLocaleTimeString(final Object self) {
+    public static String toLocaleTimeString(final Object self) {
         return toStringImpl(self, FORMAT_LOCAL_TIME);
     }
 
@@ -330,7 +330,7 @@
      * @return valueOf - a number which is this time value
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object valueOf(final Object self) {
+    public static double valueOf(final Object self) {
         final NativeDate nd = getNativeDate(self);
         return (nd != null) ? nd.getTime() : Double.NaN;
     }
@@ -342,7 +342,7 @@
      * @return time
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object getTime(final Object self) {
+    public static double getTime(final Object self) {
         final NativeDate nd = getNativeDate(self);
         return (nd != null) ? nd.getTime() : Double.NaN;
     }
@@ -365,7 +365,7 @@
      * @return UTC full year
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object getUTCFullYear(final Object self) {
+    public static double getUTCFullYear(final Object self) {
         return getUTCField(self, YEAR);
     }
 
@@ -376,7 +376,7 @@
      * @return year
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object getYear(final Object self) {
+    public static double getYear(final Object self) {
         final NativeDate nd = getNativeDate(self);
         return (nd != null && nd.isValidDate()) ? (yearFromTime(nd.getLocalTime()) - 1900) : Double.NaN;
     }
@@ -388,7 +388,7 @@
      * @return month
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object getMonth(final Object self) {
+    public static double getMonth(final Object self) {
         return getField(self, MONTH);
     }
 
@@ -399,7 +399,7 @@
      * @return UTC month
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object getUTCMonth(final Object self) {
+    public static double getUTCMonth(final Object self) {
         return getUTCField(self, MONTH);
     }
 
@@ -410,7 +410,7 @@
      * @return date
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object getDate(final Object self) {
+    public static double getDate(final Object self) {
         return getField(self, DAY);
     }
 
@@ -421,7 +421,7 @@
      * @return UTC Date
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object getUTCDate(final Object self) {
+    public static double getUTCDate(final Object self) {
         return getUTCField(self, DAY);
     }
 
@@ -432,7 +432,7 @@
      * @return day
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object getDay(final Object self) {
+    public static double getDay(final Object self) {
         final NativeDate nd = getNativeDate(self);
         return (nd != null && nd.isValidDate()) ? weekDay(nd.getLocalTime()) : Double.NaN;
     }
@@ -444,7 +444,7 @@
      * @return UTC day
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object getUTCDay(final Object self) {
+    public static double getUTCDay(final Object self) {
         final NativeDate nd = getNativeDate(self);
         return (nd != null && nd.isValidDate()) ? weekDay(nd.getTime()) : Double.NaN;
     }
@@ -456,7 +456,7 @@
      * @return hours
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object getHours(final Object self) {
+    public static double getHours(final Object self) {
         return getField(self, HOUR);
     }
 
@@ -467,7 +467,7 @@
      * @return UTC hours
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object getUTCHours(final Object self) {
+    public static double getUTCHours(final Object self) {
         return getUTCField(self, HOUR);
     }
 
@@ -478,7 +478,7 @@
      * @return minutes
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object getMinutes(final Object self) {
+    public static double getMinutes(final Object self) {
         return getField(self, MINUTE);
     }
 
@@ -489,7 +489,7 @@
      * @return UTC minutes
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object getUTCMinutes(final Object self) {
+    public static double getUTCMinutes(final Object self) {
         return getUTCField(self, MINUTE);
     }
 
@@ -500,7 +500,7 @@
      * @return seconds
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object getSeconds(final Object self) {
+    public static double getSeconds(final Object self) {
         return getField(self, SECOND);
     }
 
@@ -511,7 +511,7 @@
      * @return UTC seconds
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object getUTCSeconds(final Object self) {
+    public static double getUTCSeconds(final Object self) {
         return getUTCField(self, SECOND);
     }
 
@@ -522,7 +522,7 @@
      * @return milliseconds
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object getMilliseconds(final Object self) {
+    public static double getMilliseconds(final Object self) {
         return getField(self, MILLISECOND);
     }
 
@@ -533,7 +533,7 @@
      * @return UTC milliseconds
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object getUTCMilliseconds(final Object self) {
+    public static double getUTCMilliseconds(final Object self) {
         return getUTCField(self, MILLISECOND);
     }
 
@@ -544,7 +544,7 @@
      * @return time zone offset or NaN if N/A
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object getTimezoneOffset(final Object self) {
+    public static double getTimezoneOffset(final Object self) {
         final NativeDate nd = getNativeDate(self);
         if (nd != null && nd.isValidDate()) {
             final long msec = (long) nd.getTime();
@@ -561,7 +561,7 @@
      * @return time
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object setTime(final Object self, final Object time) {
+    public static double setTime(final Object self, final Object time) {
         final NativeDate nd  = getNativeDate(self);
         final double     num = timeClip(JSType.toNumber(time));
         nd.setTime(num);
@@ -576,7 +576,7 @@
      * @return time
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
-    public static Object setMilliseconds(final Object self, final Object... args) {
+    public static double setMilliseconds(final Object self, final Object... args) {
         final NativeDate nd = getNativeDate(self);
         setFields(nd, MILLISECOND, args, true);
         return nd.getTime();
@@ -590,7 +590,7 @@
      * @return time
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
-    public static Object setUTCMilliseconds(final Object self, final Object... args) {
+    public static double setUTCMilliseconds(final Object self, final Object... args) {
         final NativeDate nd = getNativeDate(self);
         setFields(nd, MILLISECOND, args, false);
         return nd.getTime();
@@ -604,7 +604,7 @@
      * @return time
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
-    public static Object setSeconds(final Object self, final Object... args) {
+    public static double setSeconds(final Object self, final Object... args) {
         final NativeDate nd = getNativeDate(self);
         setFields(nd, SECOND, args, true);
         return nd.getTime();
@@ -618,7 +618,7 @@
      * @return time
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
-    public static Object setUTCSeconds(final Object self, final Object... args) {
+    public static double setUTCSeconds(final Object self, final Object... args) {
         final NativeDate nd = getNativeDate(self);
         setFields(nd, SECOND, args, false);
         return nd.getTime();
@@ -632,7 +632,7 @@
      * @return time
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 3)
-    public static Object setMinutes(final Object self, final Object... args) {
+    public static double setMinutes(final Object self, final Object... args) {
         final NativeDate nd = getNativeDate(self);
         setFields(nd, MINUTE, args, true);
         return nd.getTime();
@@ -646,7 +646,7 @@
      * @return time
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 3)
-    public static Object setUTCMinutes(final Object self, final Object... args) {
+    public static double setUTCMinutes(final Object self, final Object... args) {
         final NativeDate nd = getNativeDate(self);
         setFields(nd, MINUTE, args, false);
         return nd.getTime();
@@ -660,7 +660,7 @@
      * @return time
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 4)
-    public static Object setHours(final Object self, final Object... args) {
+    public static double setHours(final Object self, final Object... args) {
         final NativeDate nd = getNativeDate(self);
         setFields(nd, HOUR, args, true);
         return nd.getTime();
@@ -674,7 +674,7 @@
      * @return time
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 4)
-    public static Object setUTCHours(final Object self, final Object... args) {
+    public static double setUTCHours(final Object self, final Object... args) {
         final NativeDate nd = getNativeDate(self);
         setFields(nd, HOUR, args, false);
         return nd.getTime();
@@ -688,7 +688,7 @@
      * @return time
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
-    public static Object setDate(final Object self, final Object... args) {
+    public static double setDate(final Object self, final Object... args) {
         final NativeDate nd = getNativeDate(self);
         setFields(nd, DAY, args, true);
         return nd.getTime();
@@ -702,7 +702,7 @@
      * @return time
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
-    public static Object setUTCDate(final Object self, final Object... args) {
+    public static double setUTCDate(final Object self, final Object... args) {
         final NativeDate nd = getNativeDate(self);
         setFields(nd, DAY, args, false);
         return nd.getTime();
@@ -716,7 +716,7 @@
      * @return time
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
-    public static Object setMonth(final Object self, final Object... args) {
+    public static double setMonth(final Object self, final Object... args) {
         final NativeDate nd = getNativeDate(self);
         setFields(nd, MONTH, args, true);
         return nd.getTime();
@@ -730,7 +730,7 @@
      * @return time
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
-    public static Object setUTCMonth(final Object self, final Object... args) {
+    public static double setUTCMonth(final Object self, final Object... args) {
         final NativeDate nd = ensureNativeDate(self);
         setFields(nd, MONTH, args, false);
         return nd.getTime();
@@ -744,7 +744,7 @@
      * @return time
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 3)
-    public static Object setFullYear(final Object self, final Object... args) {
+    public static double setFullYear(final Object self, final Object... args) {
         final NativeDate nd   = ensureNativeDate(self);
         if (nd.isValidDate()) {
             setFields(nd, YEAR, args, true);
@@ -767,7 +767,7 @@
      * @return time
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 3)
-    public static Object setUTCFullYear(final Object self, final Object... args) {
+    public static double setUTCFullYear(final Object self, final Object... args) {
         final NativeDate nd   = ensureNativeDate(self);
         if (nd.isValidDate()) {
             setFields(nd, YEAR, args, false);
@@ -786,7 +786,7 @@
      * @return NativeDate
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object setYear(final Object self, final Object year) {
+    public static double setYear(final Object self, final Object year) {
         final NativeDate nd = getNativeDate(self);
         if (isNaN(nd.getTime())) {
             nd.setTime(utc(0, nd.getTimeZone()));
@@ -813,7 +813,7 @@
      * @return string representation of date
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object toUTCString(final Object self) {
+    public static String toUTCString(final Object self) {
         return toGMTStringImpl(self);
     }
 
@@ -826,7 +826,7 @@
      * @return string representation of date
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object toGMTString(final Object self) {
+    public static String toGMTString(final Object self) {
         return toGMTStringImpl(self);
     }
 
@@ -837,7 +837,7 @@
      * @return string representation of date
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object toISOString(final Object self) {
+    public static String toISOString(final Object self) {
         return toISOStringImpl(self);
     }
 
@@ -1282,14 +1282,14 @@
         }
     }
 
-    private static Object getField(final Object self, final int field) {
+    private static double getField(final Object self, final int field) {
         final NativeDate nd = getNativeDate(self);
-        return (nd != null && nd.isValidDate()) ? valueFromTime(field, nd.getLocalTime()) : Double.NaN;
+        return (nd != null && nd.isValidDate()) ? (double)valueFromTime(field, nd.getLocalTime()) : Double.NaN;
     }
 
-    private static Object getUTCField(final Object self, final int field) {
+    private static double getUTCField(final Object self, final int field) {
         final NativeDate nd = getNativeDate(self);
-        return (nd != null && nd.isValidDate()) ? valueFromTime(field, nd.getTime()) : Double.NaN;
+        return (nd != null && nd.isValidDate()) ? (double)valueFromTime(field, nd.getTime()) : Double.NaN;
     }
 
     private static void setFields(final NativeDate nd, final int fieldId, final Object[] args, final boolean local) {
@@ -1344,5 +1344,4 @@
     private TimeZone getTimeZone() {
         return timezone;
     }
-
 }
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeDebug.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeDebug.java	Tue Apr 01 17:28:17 2014 -0700
@@ -116,7 +116,7 @@
      * @return true if reference identity
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object identical(final Object self, final Object obj1, final Object obj2) {
+    public static boolean identical(final Object self, final Object obj1, final Object obj2) {
         return obj1 == obj2;
     }
 
@@ -144,7 +144,7 @@
      * @return return {@link Object#equals(Object)} for objects.
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object equals(final Object self, final Object obj1, final Object obj2) {
+    public static boolean equals(final Object self, final Object obj1, final Object obj2) {
         return Objects.equals(obj1, obj2);
     }
 
@@ -156,7 +156,7 @@
      * @return Java string representation of {@code obj}
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object toJavaString(final Object self, final Object obj) {
+    public static String toJavaString(final Object self, final Object obj) {
         return Objects.toString(obj);
     }
 
@@ -168,7 +168,7 @@
      * @return string representation
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object toIdentString(final Object self, final Object obj) {
+    public static String toIdentString(final Object self, final Object obj) {
         if (obj == null) {
             return "null";
         }
@@ -185,7 +185,7 @@
      * @return listener count
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object getListenerCount(final Object self, final Object obj) {
+    public static int getListenerCount(final Object self, final Object obj) {
         return (obj instanceof ScriptObject) ? PropertyListeners.getListenerCount((ScriptObject) obj) : 0;
     }
 
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeError.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeError.java	Tue Apr 01 17:28:17 2014 -0700
@@ -126,7 +126,7 @@
      * @return NativeError instance
      */
     @Constructor
-    public static Object constructor(final boolean newObj, final Object self, final Object msg) {
+    public static NativeError constructor(final boolean newObj, final Object self, final Object msg) {
         return new NativeError(msg);
     }
 
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeEvalError.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeEvalError.java	Tue Apr 01 17:28:17 2014 -0700
@@ -98,7 +98,7 @@
      * @return new EvalError
      */
     @Constructor(name = "EvalError")
-    public static Object constructor(final boolean newObj, final Object self, final Object msg) {
+    public static NativeEvalError constructor(final boolean newObj, final Object self, final Object msg) {
         return new NativeEvalError(msg);
     }
 }
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeFloat32Array.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeFloat32Array.java	Tue Apr 01 17:28:17 2014 -0700
@@ -136,8 +136,8 @@
      * @return new typed array
      */
     @Constructor(arity = 1)
-    public static Object constructor(final boolean newObj, final Object self, final Object... args) {
-        return constructorImpl(args, FACTORY);
+    public static NativeFloat32Array constructor(final boolean newObj, final Object self, final Object... args) {
+        return (NativeFloat32Array)constructorImpl(args, FACTORY);
     }
 
     NativeFloat32Array(final NativeArrayBuffer buffer, final int byteOffset, final int length) {
@@ -192,8 +192,8 @@
      * @return sub array
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    protected static Object subarray(final Object self, final Object begin, final Object end) {
-        return ArrayBufferView.subarrayImpl(self, begin, end);
+    protected static NativeFloat32Array subarray(final Object self, final Object begin, final Object end) {
+        return (NativeFloat32Array)ArrayBufferView.subarrayImpl(self, begin, end);
     }
 
     @Override
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeFloat64Array.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeFloat64Array.java	Tue Apr 01 17:28:17 2014 -0700
@@ -146,8 +146,8 @@
      * @return new typed array
      */
     @Constructor(arity = 1)
-    public static Object constructor(final boolean newObj, final Object self, final Object... args) {
-        return constructorImpl(args, FACTORY);
+    public static NativeFloat64Array constructor(final boolean newObj, final Object self, final Object... args) {
+        return (NativeFloat64Array)constructorImpl(args, FACTORY);
     }
 
     NativeFloat64Array(final NativeArrayBuffer buffer, final int byteOffset, final int length) {
@@ -202,8 +202,8 @@
      * @return sub array
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    protected static Object subarray(final Object self, final Object begin, final Object end) {
-        return ArrayBufferView.subarrayImpl(self, begin, end);
+    protected static NativeFloat64Array subarray(final Object self, final Object begin, final Object end) {
+        return (NativeFloat64Array)ArrayBufferView.subarrayImpl(self, begin, end);
     }
 
     @Override
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeFunction.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeFunction.java	Tue Apr 01 17:28:17 2014 -0700
@@ -71,7 +71,7 @@
      * @return string representation of Function
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object toString(final Object self) {
+    public static String toString(final Object self) {
         if (!(self instanceof ScriptFunction)) {
             throw typeError("not.a.function", ScriptRuntime.safeToString(self));
         }
@@ -174,7 +174,7 @@
      * @return function with bound arguments
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
-    public static Object bind(final Object self, final Object... args) {
+    public static ScriptFunction bind(final Object self, final Object... args) {
         if (!(self instanceof ScriptFunction)) {
             throw typeError("not.a.function", ScriptRuntime.safeToString(self));
         }
@@ -199,7 +199,7 @@
      * @return source for function
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object toSource(final Object self) {
+    public static String toSource(final Object self) {
         if (!(self instanceof ScriptFunction)) {
             throw typeError("not.a.function", ScriptRuntime.safeToString(self));
         }
@@ -217,7 +217,7 @@
      * @return new NativeFunction
      */
     @Constructor(arity = 1)
-    public static Object function(final boolean newObj, final Object self, final Object... args) {
+    public static ScriptFunction function(final boolean newObj, final Object self, final Object... args) {
         final StringBuilder sb = new StringBuilder();
 
         sb.append("(function (");
@@ -253,7 +253,7 @@
 
         final Global global = Global.instance();
 
-        return Global.directEval(global, sb.toString(), global, "<function>", global.isStrictContext());
+        return (ScriptFunction)Global.directEval(global, sb.toString(), global, "<function>", global.isStrictContext());
     }
 
     private static void checkFunctionParameters(final String params) {
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeInt16Array.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeInt16Array.java	Tue Apr 01 17:28:17 2014 -0700
@@ -100,8 +100,8 @@
      * @return new typed array
      */
     @Constructor(arity = 1)
-    public static Object constructor(final boolean newObj, final Object self, final Object... args) {
-        return constructorImpl(args, FACTORY);
+    public static NativeInt16Array constructor(final boolean newObj, final Object self, final Object... args) {
+        return (NativeInt16Array)constructorImpl(args, FACTORY);
     }
 
     NativeInt16Array(final NativeArrayBuffer buffer, final int byteOffset, final int byteLength) {
@@ -151,8 +151,8 @@
      * @return sub array
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    protected static Object subarray(final Object self, final Object begin, final Object end) {
-        return ArrayBufferView.subarrayImpl(self, begin, end);
+    protected static NativeInt16Array subarray(final Object self, final Object begin, final Object end) {
+        return (NativeInt16Array)ArrayBufferView.subarrayImpl(self, begin, end);
     }
 
     @Override
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeInt32Array.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeInt32Array.java	Tue Apr 01 17:28:17 2014 -0700
@@ -103,8 +103,8 @@
      * @return new typed array
      */
     @Constructor(arity = 1)
-    public static Object constructor(final boolean newObj, final Object self, final Object... args) {
-        return constructorImpl(args, FACTORY);
+    public static NativeInt32Array constructor(final boolean newObj, final Object self, final Object... args) {
+        return (NativeInt32Array)constructorImpl(args, FACTORY);
     }
 
     NativeInt32Array(final NativeArrayBuffer buffer, final int byteOffset, final int length) {
@@ -154,8 +154,8 @@
      * @return sub array
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    protected static Object subarray(final Object self, final Object begin, final Object end) {
-        return ArrayBufferView.subarrayImpl(self, begin, end);
+    protected static NativeInt32Array subarray(final Object self, final Object begin, final Object end) {
+        return (NativeInt32Array)ArrayBufferView.subarrayImpl(self, begin, end);
     }
 
     @Override
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeInt8Array.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeInt8Array.java	Tue Apr 01 17:28:17 2014 -0700
@@ -93,8 +93,8 @@
      * @return new typed array
      */
     @Constructor(arity = 1)
-    public static Object constructor(final boolean newObj, final Object self, final Object... args) {
-        return constructorImpl(args, FACTORY);
+    public static NativeInt8Array constructor(final boolean newObj, final Object self, final Object... args) {
+        return (NativeInt8Array)constructorImpl(args, FACTORY);
     }
 
     NativeInt8Array(final NativeArrayBuffer buffer, final int byteOffset, final int length) {
@@ -144,8 +144,8 @@
      * @return sub array
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    protected static Object subarray(final Object self, final Object begin, final Object end) {
-        return ArrayBufferView.subarrayImpl(self, begin, end);
+    protected static NativeInt8Array subarray(final Object self, final Object begin, final Object end) {
+        return (NativeInt8Array)ArrayBufferView.subarrayImpl(self, begin, end);
     }
 
     @Override
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeJSAdapter.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeJSAdapter.java	Tue Apr 01 17:28:17 2014 -0700
@@ -536,7 +536,7 @@
      * @return new NativeJSAdapter
      */
     @Constructor
-    public static Object construct(final boolean isNew, final Object self, final Object... args) {
+    public static NativeJSAdapter construct(final boolean isNew, final Object self, final Object... args) {
         Object proto     = UNDEFINED;
         Object overrides = UNDEFINED;
         Object adaptee;
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeJava.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeJava.java	Tue Apr 01 17:28:17 2014 -0700
@@ -75,7 +75,7 @@
      * @see #type(Object, Object)
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object isType(final Object self, final Object type) {
+    public static boolean isType(final Object self, final Object type) {
         return type instanceof StaticClass;
     }
 
@@ -338,7 +338,7 @@
      * null.
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object from(final Object self, final Object objArray) {
+    public static NativeArray from(final Object self, final Object objArray) {
         if (objArray == null) {
             return null;
         } else if (objArray instanceof Collection) {
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeJavaImporter.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeJavaImporter.java	Tue Apr 01 17:28:17 2014 -0700
@@ -86,7 +86,7 @@
      * @return NativeJavaImporter instance
      */
     @Constructor(arity = 1)
-    public static Object constructor(final boolean isNew, final Object self, final Object... args) {
+    public static NativeJavaImporter constructor(final boolean isNew, final Object self, final Object... args) {
         return new NativeJavaImporter(args);
     }
 
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeNumber.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeNumber.java	Tue Apr 01 17:28:17 2014 -0700
@@ -185,7 +185,7 @@
      * @return number in decimal fixed point notation
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object toFixed(final Object self, final Object fractionDigits) {
+    public static String toFixed(final Object self, final Object fractionDigits) {
         final int f = JSType.toInteger(fractionDigits);
         if (f < 0 || f > 20) {
             throw rangeError("invalid.fraction.digits", "toFixed");
@@ -217,7 +217,7 @@
      * @return number in decimal exponential notation
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object toExponential(final Object self, final Object fractionDigits) {
+    public static String toExponential(final Object self, final Object fractionDigits) {
         final double  x         = getNumberValue(self);
         final boolean trimZeros = fractionDigits == UNDEFINED;
         final int     f         = trimZeros ? 16 : JSType.toInteger(fractionDigits);
@@ -245,7 +245,7 @@
      * @return number in decimal exponentiation notation or decimal fixed notation depending on {@code precision}
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object toPrecision(final Object self, final Object precision) {
+    public static String toPrecision(final Object self, final Object precision) {
         final double x = getNumberValue(self);
         if (precision == UNDEFINED) {
             return JSType.toString(x);
@@ -278,7 +278,7 @@
      * @return string representation of this Number in the given radix
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object toString(final Object self, final Object radix) {
+    public static String toString(final Object self, final Object radix) {
         if (radix != UNDEFINED) {
             final int intRadix = JSType.toInteger(radix);
             if (intRadix != 10) {
@@ -299,7 +299,7 @@
      * @return localized string for this Number
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object toLocaleString(final Object self) {
+    public static String toLocaleString(final Object self) {
         return JSType.toString(getNumberValue(self));
     }
 
@@ -308,10 +308,10 @@
      * ECMA 15.7.4.4 Number.prototype.valueOf ( )
      *
      * @param self self reference
-     * @return boxed number value for this Number
+     * @return number value for this Number
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object valueOf(final Object self) {
+    public static double valueOf(final Object self) {
         return getNumberValue(self);
     }
 
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeObject.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeObject.java	Tue Apr 01 17:28:17 2014 -0700
@@ -111,7 +111,7 @@
      * @return the 'obj' object
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object setIndexedPropertiesToExternalArrayData(final Object self, final Object obj, final Object buf) {
+    public static ScriptObject setIndexedPropertiesToExternalArrayData(final Object self, final Object obj, final Object buf) {
         Global.checkObject(obj);
         final ScriptObject sobj = (ScriptObject)obj;
         if (buf instanceof ByteBuffer) {
@@ -203,7 +203,7 @@
      * @return array of property names
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object getOwnPropertyNames(final Object self, final Object obj) {
+    public static ScriptObject getOwnPropertyNames(final Object self, final Object obj) {
         if (obj instanceof ScriptObject) {
             return new NativeArray(((ScriptObject)obj).getOwnKeys(true));
         } else if (obj instanceof ScriptObjectMirror) {
@@ -222,7 +222,7 @@
      * @return object created
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object create(final Object self, final Object proto, final Object props) {
+    public static ScriptObject create(final Object self, final Object proto, final Object props) {
         if (proto != null) {
             Global.checkObject(proto);
         }
@@ -248,10 +248,11 @@
      * @return object
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object defineProperty(final Object self, final Object obj, final Object prop, final Object attr) {
+    public static ScriptObject defineProperty(final Object self, final Object obj, final Object prop, final Object attr) {
         Global.checkObject(obj);
-        ((ScriptObject)obj).defineOwnProperty(JSType.toString(prop), attr, true);
-        return obj;
+        final ScriptObject sobj = (ScriptObject)obj;
+        sobj.defineOwnProperty(JSType.toString(prop), attr, true);
+        return sobj;
     }
 
     /**
@@ -263,7 +264,7 @@
      * @return object
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object defineProperties(final Object self, final Object obj, final Object props) {
+    public static ScriptObject defineProperties(final Object self, final Object obj, final Object props) {
         Global.checkObject(obj);
 
         final ScriptObject sobj     = (ScriptObject)obj;
@@ -342,7 +343,7 @@
      * @return true if sealed, false otherwise
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object isSealed(final Object self, final Object obj) {
+    public static boolean isSealed(final Object self, final Object obj) {
         if (obj instanceof ScriptObject) {
             return ((ScriptObject)obj).isSealed();
         } else if (obj instanceof ScriptObjectMirror) {
@@ -360,7 +361,7 @@
      * @return true if object is frozen, false otherwise
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object isFrozen(final Object self, final Object obj) {
+    public static boolean isFrozen(final Object self, final Object obj) {
         if (obj instanceof ScriptObject) {
             return ((ScriptObject)obj).isFrozen();
         } else if (obj instanceof ScriptObjectMirror) {
@@ -378,7 +379,7 @@
      * @return true if object is extensible, false otherwise
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object isExtensible(final Object self, final Object obj) {
+    public static boolean isExtensible(final Object self, final Object obj) {
         if (obj instanceof ScriptObject) {
             return ((ScriptObject)obj).isExtensible();
         } else if (obj instanceof ScriptObjectMirror) {
@@ -396,7 +397,7 @@
      * @return array of keys in object
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object keys(final Object self, final Object obj) {
+    public static ScriptObject keys(final Object self, final Object obj) {
         if (obj instanceof ScriptObject) {
             final ScriptObject sobj = (ScriptObject)obj;
             return new NativeArray(sobj.getOwnKeys(false));
@@ -453,7 +454,7 @@
      * @return ToString of object
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object toString(final Object self) {
+    public static String toString(final Object self) {
         return ScriptRuntime.builtinObjectToString(self);
     }
 
@@ -506,7 +507,7 @@
      * @return true if property exists in object
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object hasOwnProperty(final Object self, final Object v) {
+    public static boolean hasOwnProperty(final Object self, final Object v) {
         // Convert ScriptObjects to primitive with String.class hint
         // but no need to convert other primitives to string.
         final Object key = JSType.toPrimitive(v, String.class);
@@ -523,7 +524,7 @@
      * @return true if object is prototype of v
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object isPrototypeOf(final Object self, final Object v) {
+    public static boolean isPrototypeOf(final Object self, final Object v) {
         if (!(v instanceof ScriptObject)) {
             return false;
         }
@@ -549,7 +550,7 @@
      * @return true if property is enumerable
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object propertyIsEnumerable(final Object self, final Object v) {
+    public static boolean propertyIsEnumerable(final Object self, final Object v) {
         final String str = JSType.toString(v);
         final Object obj = Global.toObject(self);
 
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeRangeError.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeRangeError.java	Tue Apr 01 17:28:17 2014 -0700
@@ -98,7 +98,7 @@
      * @return new RangeError
      */
     @Constructor(name = "RangeError")
-    public static Object constructor(final boolean newObj, final Object self, final Object msg) {
+    public static NativeRangeError constructor(final boolean newObj, final Object self, final Object msg) {
         return new NativeRangeError(msg);
     }
 }
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeReferenceError.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeReferenceError.java	Tue Apr 01 17:28:17 2014 -0700
@@ -98,7 +98,7 @@
      * @return new ReferenceError
      */
     @Constructor(name = "ReferenceError")
-    public static Object constructor(final boolean newObj, final Object self, final Object msg) {
+    public static NativeReferenceError constructor(final boolean newObj, final Object self, final Object msg) {
         return new NativeReferenceError(msg);
     }
 }
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeRegExp.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeRegExp.java	Tue Apr 01 17:28:17 2014 -0700
@@ -122,7 +122,7 @@
      * @return new NativeRegExp
      */
     @Constructor(arity = 2)
-    public static Object constructor(final boolean isNew, final Object self, final Object... args) {
+    public static NativeRegExp constructor(final boolean isNew, final Object self, final Object... args) {
         if (args.length > 1) {
             return newRegExp(args[0], args[1]);
         } else if (args.length > 0) {
@@ -142,7 +142,7 @@
      * @return new NativeRegExp
      */
     @SpecializedConstructor
-    public static Object constructor(final boolean isNew, final Object self) {
+    public static NativeRegExp constructor(final boolean isNew, final Object self) {
         return new NativeRegExp("", "");
     }
 
@@ -157,7 +157,7 @@
      * @return new NativeRegExp
      */
     @SpecializedConstructor
-    public static Object constructor(final boolean isNew, final Object self, final Object pattern) {
+    public static NativeRegExp constructor(final boolean isNew, final Object self, final Object pattern) {
         return newRegExp(pattern, UNDEFINED);
     }
 
@@ -173,7 +173,7 @@
      * @return new NativeRegExp
      */
     @SpecializedConstructor
-    public static Object constructor(final boolean isNew, final Object self, final Object pattern, final Object flags) {
+    public static NativeRegExp constructor(final boolean isNew, final Object self, final Object pattern, final Object flags) {
         return newRegExp(pattern, flags);
     }
 
@@ -283,7 +283,7 @@
      * @return new NativeRegExp
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object compile(final Object self, final Object pattern, final Object flags) {
+    public static ScriptObject compile(final Object self, final Object pattern, final Object flags) {
         final NativeRegExp regExp   = checkRegExp(self);
         final NativeRegExp compiled = newRegExp(pattern, flags);
         // copy over regexp to 'self'
@@ -302,7 +302,7 @@
      * @return array containing the matches or {@code null} if no match
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object exec(final Object self, final Object string) {
+    public static ScriptObject exec(final Object self, final Object string) {
         return checkRegExp(self).exec(JSType.toString(string));
     }
 
@@ -314,7 +314,7 @@
      * @return true if matches found, false otherwise
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object test(final Object self, final Object string) {
+    public static boolean test(final Object self, final Object string) {
         return checkRegExp(self).test(JSType.toString(string));
     }
 
@@ -325,7 +325,7 @@
      * @return string version of regexp
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object toString(final Object self) {
+    public static String toString(final Object self) {
         return checkRegExp(self).toString();
     }
 
@@ -618,7 +618,7 @@
      * @param string String to match.
      * @return NativeArray of matches, string or null.
      */
-    public Object exec(final String string) {
+    public NativeRegExpExecResult exec(final String string) {
         final RegExpResult match = execInner(string);
 
         if (match == null) {
@@ -635,7 +635,7 @@
      * @param string String to match.
      * @return True if a match is found.
      */
-    public Object test(final String string) {
+    public boolean test(final String string) {
         return execInner(string) != null;
     }
 
@@ -649,7 +649,7 @@
      * @param replacement Replacement string.
      * @return String with substitutions.
      */
-    Object replace(final String string, final String replacement, final ScriptFunction function) {
+    String replace(final String string, final String replacement, final ScriptFunction function) {
         final RegExpMatcher matcher = regexp.match(string);
 
         if (matcher == null) {
@@ -804,7 +804,7 @@
      * @param limit  Split limit.
      * @return Array of substrings.
      */
-    Object split(final String string, final long limit) {
+    NativeArray split(final String string, final long limit) {
         if (limit == 0L) {
             return new NativeArray();
         }
@@ -867,7 +867,7 @@
      * @param string String to match.
      * @return Index of match.
      */
-    Object search(final String string) {
+    int search(final String string) {
         final RegExpResult match = execInner(string);
 
         if (match == null) {
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeString.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeString.java	Tue Apr 01 17:28:17 2014 -0700
@@ -425,7 +425,7 @@
      * @return string with arguments translated to charcodes
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1, where = Where.CONSTRUCTOR)
-    public static Object fromCharCode(final Object self, final Object... args) {
+    public static String fromCharCode(final Object self, final Object... args) {
         final char[] buf = new char[args.length];
         int index = 0;
         for (final Object arg : args) {
@@ -441,7 +441,7 @@
      * @return string with one charcode
      */
     @SpecializedFunction
-    public static Object fromCharCode(final Object self, final Object value) {
+    public static String fromCharCode(final Object self, final Object value) {
         try {
             return "" + (char)JSType.toUint16(((Number)value).doubleValue());
         } catch (final ClassCastException e) {
@@ -456,7 +456,7 @@
      * @return string with one charcode
      */
     @SpecializedFunction
-    public static Object fromCharCode(final Object self, final int value) {
+    public static String fromCharCode(final Object self, final int value) {
         return "" + (char)(value & 0xffff);
     }
 
@@ -467,7 +467,7 @@
      * @return string with one charcode
      */
     @SpecializedFunction
-    public static Object fromCharCode(final Object self, final long value) {
+    public static String fromCharCode(final Object self, final long value) {
         return "" + (char)((int)value & 0xffff);
     }
 
@@ -478,7 +478,7 @@
      * @return string with one charcode
      */
     @SpecializedFunction
-    public static Object fromCharCode(final Object self, final double value) {
+    public static String fromCharCode(final Object self, final double value) {
         return "" + (char)JSType.toUint16(value);
     }
 
@@ -488,7 +488,7 @@
      * @return self as string
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object toString(final Object self) {
+    public static String toString(final Object self) {
         return getString(self);
     }
 
@@ -498,7 +498,7 @@
      * @return self as string
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object valueOf(final Object self) {
+    public static String valueOf(final Object self) {
         return getString(self);
     }
 
@@ -509,7 +509,7 @@
      * @return string representing the char at the given position
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object charAt(final Object self, final Object pos) {
+    public static String charAt(final Object self, final Object pos) {
         return charAtImpl(checkObjectToString(self), JSType.toInteger(pos));
     }
 
@@ -546,7 +546,7 @@
      * @return number representing charcode at position
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object charCodeAt(final Object self, final Object pos) {
+    public static double charCodeAt(final Object self, final Object pos) {
         return charCodeAtImpl(checkObjectToString(self), JSType.toInteger(pos));
     }
 
@@ -601,7 +601,7 @@
      * @return position of first match or -1
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
-    public static Object indexOf(final Object self, final Object search, final Object pos) {
+    public static int indexOf(final Object self, final Object search, final Object pos) {
         final String str = checkObjectToString(self);
         return str.indexOf(JSType.toString(search), JSType.toInteger(pos));
     }
@@ -649,7 +649,7 @@
      * @return last position of match or -1
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
-    public static Object lastIndexOf(final Object self, final Object search, final Object pos) {
+    public static int lastIndexOf(final Object self, final Object search, final Object pos) {
 
         final String str       = checkObjectToString(self);
         final String searchStr = JSType.toString(search);
@@ -680,7 +680,7 @@
      * @return result of locale sensitive comparison operation between {@code self} and {@code that}
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object localeCompare(final Object self, final Object that) {
+    public static double localeCompare(final Object self, final Object that) {
 
         final String   str      = checkObjectToString(self);
         final Collator collator = Collator.getInstance(Global.getEnv()._locale);
@@ -698,7 +698,7 @@
      * @return array of regexp matches
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object match(final Object self, final Object regexp) {
+    public static ScriptObject match(final Object self, final Object regexp) {
 
         final String str = checkObjectToString(self);
 
@@ -745,7 +745,7 @@
      * @return string after replacement
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object replace(final Object self, final Object string, final Object replacement) {
+    public static String replace(final Object self, final Object string, final Object replacement) {
 
         final String str = checkObjectToString(self);
 
@@ -771,7 +771,7 @@
      * @return offset where match occurred
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object search(final Object self, final Object string) {
+    public static int search(final Object self, final Object string) {
 
         final String       str          = checkObjectToString(self);
         final NativeRegExp nativeRegExp = Global.toRegExp(string == UNDEFINED ? "" : string);
@@ -788,7 +788,7 @@
      * @return sliced out substring
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object slice(final Object self, final Object start, final Object end) {
+    public static String slice(final Object self, final Object start, final Object end) {
 
         final String str      = checkObjectToString(self);
         if (end == UNDEFINED) {
@@ -805,7 +805,7 @@
      * @return sliced out substring
      */
     @SpecializedFunction
-    public static Object slice(final Object self, final int start) {
+    public static String slice(final Object self, final int start) {
         final String str = checkObjectToString(self);
         final int from = (start < 0) ? Math.max(str.length() + start, 0) : Math.min(start, str.length());
 
@@ -820,7 +820,7 @@
      * @return sliced out substring
      */
     @SpecializedFunction
-    public static Object slice(final Object self, final double start) {
+    public static String slice(final Object self, final double start) {
         return slice(self, (int)start);
     }
 
@@ -833,7 +833,7 @@
      * @return sliced out substring
      */
     @SpecializedFunction
-    public static Object slice(final Object self, final int start, final int end) {
+    public static String slice(final Object self, final int start, final int end) {
 
         final String str = checkObjectToString(self);
         final int len    = str.length();
@@ -853,7 +853,7 @@
      * @return sliced out substring
      */
     @SpecializedFunction
-    public static Object slice(final Object self, final double start, final double end) {
+    public static String slice(final Object self, final double start, final double end) {
         return slice(self, (int)start, (int)end);
     }
 
@@ -866,7 +866,7 @@
      * @return array object in which splits have been placed
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object split(final Object self, final Object separator, final Object limit) {
+    public static ScriptObject split(final Object self, final Object separator, final Object limit) {
         final String str = checkObjectToString(self);
         final long lim = (limit == UNDEFINED) ? JSType.MAX_UINT : JSType.toUint32(limit);
 
@@ -882,7 +882,7 @@
         return splitString(str, JSType.toString(separator), lim);
     }
 
-    private static Object splitString(String str, String separator, long limit) {
+    private static ScriptObject splitString(String str, String separator, long limit) {
         if (separator.isEmpty()) {
             final int length = (int) Math.min(str.length(), limit);
             final Object[] array = new Object[length];
@@ -923,7 +923,7 @@
      * @return substring given start and length of section
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object substr(final Object self, final Object start, final Object length) {
+    public static String substr(final Object self, final Object start, final Object length) {
         final String str       = JSType.toString(self);
         final int    strLength = str.length();
 
@@ -946,7 +946,7 @@
      * @return substring given start and end indexes
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object substring(final Object self, final Object start, final Object end) {
+    public static String substring(final Object self, final Object start, final Object end) {
 
         final String str = checkObjectToString(self);
         if (end == UNDEFINED) {
@@ -1026,7 +1026,7 @@
      * @return string to lower case
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object toLowerCase(final Object self) {
+    public static String toLowerCase(final Object self) {
         return checkObjectToString(self).toLowerCase(Locale.ROOT);
     }
 
@@ -1036,7 +1036,7 @@
      * @return string to locale sensitive lower case
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object toLocaleLowerCase(final Object self) {
+    public static String toLocaleLowerCase(final Object self) {
         return checkObjectToString(self).toLowerCase(Global.getEnv()._locale);
     }
 
@@ -1046,7 +1046,7 @@
      * @return string to upper case
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object toUpperCase(final Object self) {
+    public static String toUpperCase(final Object self) {
         return checkObjectToString(self).toUpperCase(Locale.ROOT);
     }
 
@@ -1056,7 +1056,7 @@
      * @return string to locale sensitive upper case
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object toLocaleUpperCase(final Object self) {
+    public static String toLocaleUpperCase(final Object self) {
         return checkObjectToString(self).toUpperCase(Global.getEnv()._locale);
     }
 
@@ -1066,7 +1066,7 @@
      * @return string trimmed from whitespace
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object trim(final Object self) {
+    public static String trim(final Object self) {
 
         final String str = checkObjectToString(self);
         int start = 0;
@@ -1088,7 +1088,7 @@
      * @return string trimmed left from whitespace
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object trimLeft(final Object self) {
+    public static String trimLeft(final Object self) {
 
         final String str = checkObjectToString(self);
         int start = 0;
@@ -1107,7 +1107,7 @@
      * @return string trimmed right from whitespace
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    public static Object trimRight(final Object self) {
+    public static String trimRight(final Object self) {
 
         final String str = checkObjectToString(self);
         int start = 0;
@@ -1120,7 +1120,7 @@
         return str.substring(start, end + 1);
     }
 
-    private static Object newObj(final Object self, final CharSequence str) {
+    private static ScriptObject newObj(final Object self, final CharSequence str) {
         return new NativeString(str);
     }
 
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeSyntaxError.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeSyntaxError.java	Tue Apr 01 17:28:17 2014 -0700
@@ -94,7 +94,7 @@
      * @return new SyntaxError
      */
     @Constructor(name = "SyntaxError")
-    public static Object constructor(final boolean newObj, final Object self, final Object msg) {
+    public static NativeSyntaxError constructor(final boolean newObj, final Object self, final Object msg) {
         return new NativeSyntaxError(msg);
     }
 }
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeTypeError.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeTypeError.java	Tue Apr 01 17:28:17 2014 -0700
@@ -94,7 +94,7 @@
      * @return new TypeError
      */
     @Constructor(name = "TypeError")
-    public static Object constructor(final boolean newObj, final Object self, final Object msg) {
+    public static NativeTypeError constructor(final boolean newObj, final Object self, final Object msg) {
         return new NativeTypeError(msg);
     }
 }
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeURIError.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeURIError.java	Tue Apr 01 17:28:17 2014 -0700
@@ -93,7 +93,7 @@
      * @return new URIError
      */
     @Constructor(name = "URIError")
-    public static Object constructor(final boolean newObj, final Object self, final Object msg) {
+    public static NativeURIError constructor(final boolean newObj, final Object self, final Object msg) {
         return new NativeURIError(msg);
     }
 }
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeUint16Array.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeUint16Array.java	Tue Apr 01 17:28:17 2014 -0700
@@ -99,8 +99,8 @@
      * @return new typed array
      */
     @Constructor(arity = 1)
-    public static Object constructor(final boolean newObj, final Object self, final Object... args) {
-        return constructorImpl(args, FACTORY);
+    public static NativeUint16Array constructor(final boolean newObj, final Object self, final Object... args) {
+        return (NativeUint16Array)constructorImpl(args, FACTORY);
     }
 
     NativeUint16Array(final NativeArrayBuffer buffer, final int byteOffset, final int length) {
@@ -150,8 +150,8 @@
      * @return sub array
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    protected static Object subarray(final Object self, final Object begin, final Object end) {
-        return ArrayBufferView.subarrayImpl(self, begin, end);
+    protected static NativeUint16Array subarray(final Object self, final Object begin, final Object end) {
+        return (NativeUint16Array)ArrayBufferView.subarrayImpl(self, begin, end);
     }
 
     @Override
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeUint32Array.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeUint32Array.java	Tue Apr 01 17:28:17 2014 -0700
@@ -118,8 +118,8 @@
      * @return new typed array
      */
     @Constructor(arity = 1)
-    public static Object constructor(final boolean newObj, final Object self, final Object... args) {
-        return constructorImpl(args, FACTORY);
+    public static NativeUint32Array constructor(final boolean newObj, final Object self, final Object... args) {
+        return (NativeUint32Array)constructorImpl(args, FACTORY);
     }
 
     NativeUint32Array(final NativeArrayBuffer buffer, final int byteOffset, final int length) {
@@ -169,8 +169,8 @@
      * @return sub array
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    protected static Object subarray(final Object self, final Object begin, final Object end) {
-        return ArrayBufferView.subarrayImpl(self, begin, end);
+    protected static NativeUint32Array subarray(final Object self, final Object begin, final Object end) {
+        return (NativeUint32Array)ArrayBufferView.subarrayImpl(self, begin, end);
     }
 
     @Override
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeUint8Array.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeUint8Array.java	Tue Apr 01 17:28:17 2014 -0700
@@ -92,8 +92,8 @@
      * @return new typed array
      */
     @Constructor(arity = 1)
-    public static Object constructor(final boolean newObj, final Object self, final Object... args) {
-        return constructorImpl(args, FACTORY);
+    public static NativeUint8Array constructor(final boolean newObj, final Object self, final Object... args) {
+        return (NativeUint8Array)constructorImpl(args, FACTORY);
     }
 
     NativeUint8Array(final NativeArrayBuffer buffer, final int byteOffset, final int length) {
@@ -143,8 +143,8 @@
      * @return sub array
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    protected static Object subarray(final Object self, final Object begin, final Object end) {
-        return ArrayBufferView.subarrayImpl(self, begin, end);
+    protected static NativeUint8Array subarray(final Object self, final Object begin, final Object end) {
+        return (NativeUint8Array)ArrayBufferView.subarrayImpl(self, begin, end);
     }
 
     @Override
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeUint8ClampedArray.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeUint8ClampedArray.java	Tue Apr 01 17:28:17 2014 -0700
@@ -109,8 +109,8 @@
      * @return new typed array
      */
     @Constructor(arity = 1)
-    public static Object constructor(final boolean newObj, final Object self, final Object... args) {
-        return constructorImpl(args, FACTORY);
+    public static NativeUint8ClampedArray constructor(final boolean newObj, final Object self, final Object... args) {
+        return (NativeUint8ClampedArray)constructorImpl(args, FACTORY);
     }
 
     NativeUint8ClampedArray(final NativeArrayBuffer buffer, final int byteOffset, final int length) {
@@ -160,8 +160,8 @@
      * @return sub array
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
-    protected static Object subarray(final Object self, final Object begin, final Object end) {
-        return ArrayBufferView.subarrayImpl(self, begin, end);
+    protected static NativeUint8ClampedArray subarray(final Object self, final Object begin, final Object end) {
+        return (NativeUint8ClampedArray)ArrayBufferView.subarrayImpl(self, begin, end);
     }
 
     @Override
--- a/nashorn/src/jdk/nashorn/internal/runtime/JSONFunctions.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/src/jdk/nashorn/internal/runtime/JSONFunctions.java	Tue Apr 01 17:28:17 2014 -0700
@@ -101,7 +101,6 @@
     // apply 'reviver' function if available
     private static Object applyReviver(final Global global, final Object unfiltered, final Object reviver) {
         if (reviver instanceof ScriptFunction) {
-            assert global instanceof Global;
             final ScriptObject root = global.newObject();
             root.addOwnProperty("", Property.WRITABLE_ENUMERABLE_CONFIGURABLE, unfiltered);
             return walk(root, "", (ScriptFunction)reviver);
--- a/nashorn/src/jdk/nashorn/internal/runtime/ScriptObject.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/src/jdk/nashorn/internal/runtime/ScriptObject.java	Tue Apr 01 17:28:17 2014 -0700
@@ -593,23 +593,16 @@
     }
 
     /**
-     * Spec. mentions use of [[DefineOwnProperty]] for indexed properties in
-     * certain places (eg. Array.prototype.map, filter). We can not use ScriptObject.set
-     * method in such cases. This is because set method uses inherited setters (if any)
-     * from any object in proto chain such as Array.prototype, Object.prototype.
-     * This method directly sets a particular element value in the current object.
+     * Almost like defineOwnProperty(int,Object) for arrays this one does
+     * not add 'gap' elements (like the array one does).
      *
      * @param index key for property
      * @param value value to define
      */
-    public final void defineOwnProperty(final int index, final Object value) {
+    public void defineOwnProperty(final int index, final Object value) {
         assert isValidArrayIndex(index) : "invalid array index";
         final long longIndex = ArrayIndex.toLongIndex(index);
-        if (longIndex >= getArray().length()) {
-            // make array big enough to hold..
-            setArray(getArray().ensure(longIndex));
-        }
-        setArray(getArray().set(index, value, false));
+        setValueAtArrayIndex(longIndex, index, value, false);
     }
 
     private void checkIntegerKey(final String key) {
@@ -2747,9 +2740,7 @@
      * @param strict are we in strict mode
      */
     private void doesNotHave(final int index, final Object value, final boolean strict) {
-        final long oldLength = getArray().length();
         final long longIndex = ArrayIndex.toLongIndex(index);
-
         if (getMap().containsArrayKeys()) {
             final String key = JSType.toString(longIndex);
             final FindProperty find = findProperty(key, true);
@@ -2760,6 +2751,18 @@
             }
         }
 
+        setValueAtArrayIndex(longIndex, index, value, strict);
+    }
+
+    /**
+     * Handle when an array doesn't have a slot - possibly grow and/or convert array.
+     *
+     * @param index  key as index
+     * @param value  element value
+     * @param strict are we in strict mode
+     */
+    private void setValueAtArrayIndex(final long longIndex, final int index, final Object value, final boolean strict) {
+        final long oldLength = getArray().length();
         if (longIndex >= oldLength) {
             if (!isExtensible()) {
                 if (strict) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8037562.js	Tue Apr 01 17:28:17 2014 -0700
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ */
+
+
+/**
+ * JDK-8037562: Nashorn: JSON.parse comes up with nonexistent entries if there are gaps between the keys
+ *
+ * @test
+ * @run
+ */
+
+var strs = [
+    '{ "0":0, "2":2       }',
+    '{ "0":"", "2":""     }',
+    '{ "0":0,  "5":"hello" }',
+    '{ "0":"", "15":3234   }',
+]
+
+for (var i in strs) {
+    print(JSON.stringify(JSON.parse(strs[i])));
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8037562.js.EXPECTED	Tue Apr 01 17:28:17 2014 -0700
@@ -0,0 +1,4 @@
+{"0":0,"2":2}
+{"0":"","2":""}
+{"0":0,"5":"hello"}
+{"0":"","15":3234}
--- a/nashorn/test/src/jdk/nashorn/internal/runtime/NoPersistenceCachingTest.java	Wed Jul 05 19:34:36 2017 +0200
+++ b/nashorn/test/src/jdk/nashorn/internal/runtime/NoPersistenceCachingTest.java	Tue Apr 01 17:28:17 2014 -0700
@@ -37,6 +37,8 @@
 import javax.script.ScriptEngineManager;
 import javax.script.SimpleScriptContext;
 import jdk.nashorn.api.scripting.NashornScriptEngineFactory;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
 
 /**
  * @test
@@ -50,8 +52,8 @@
    private ScriptContext context1, context2, context3;
    private ByteArrayOutputStream stderr;
    private PrintStream prevStderr;
-   private final String script = "print('Hello')";
 
+   @BeforeTest
    public void setupTest() {
       stderr = new ByteArrayOutputStream();
       prevStderr = System.err;
@@ -69,33 +71,33 @@
       }
       String[] options = new String[]{"--log=compiler:finest"};
       engine = nashornFactory.getScriptEngine(options);
+      context1 = engine.getContext();
+      context2 = new SimpleScriptContext();
+      context2.setBindings(engine.createBindings(), ScriptContext.ENGINE_SCOPE);
+      context3 = new SimpleScriptContext();
+      context3.setBindings(engine.createBindings(), ScriptContext.ENGINE_SCOPE);
    }
 
+   @AfterTest
    public void setErrTest() {
       System.setErr(prevStderr);
    }
 
    public void runTest(int numberOfContext, String expectedOutputPattern,
                        int expectedPatternOccurrence) {
-      setupTest();
+
       try {
          switch (numberOfContext) {
          case 2:
-            context1 = engine.getContext();
-            context2 = new SimpleScriptContext();
-            context2.setBindings(engine.createBindings(), ScriptContext.ENGINE_SCOPE);
-            engine.eval(script, context1);
-            engine.eval(script, context2);
+            String scriptTwoContexts = "print('HelloTwoContexts')";
+            engine.eval(scriptTwoContexts, context1);
+            engine.eval(scriptTwoContexts, context2);
             break;
          case 3:
-            context1 = engine.getContext();
-            context2 = new SimpleScriptContext();
-            context2.setBindings(engine.createBindings(), ScriptContext.ENGINE_SCOPE);
-            context3 = new SimpleScriptContext();
-            context3.setBindings(engine.createBindings(), ScriptContext.ENGINE_SCOPE);
-            engine.eval(script, context1);
-            engine.eval(script, context2);
-            engine.eval(script, context3);
+            String scriptThreeContexts = "print('HelloThreeContexts')";
+            engine.eval(scriptThreeContexts, context1);
+            engine.eval(scriptThreeContexts, context2);
+            engine.eval(scriptThreeContexts, context3);
             break;
          }
       } catch (final Exception se) {
@@ -113,7 +115,7 @@
                     + expectedPatternOccurrence + " and found: " + matches + "\n"
               + stderr);
       }
-      setErrTest();
+      stderr.reset();
    }
 
    private static String getCodeCachePattern() {