# HG changeset patch # User Jaroslav Tulach # Date 1398268123 -7200 # Node ID 76cdd49e774bb9d08e48ec56a004dd0bb13c711e # Parent 2e3e00009c6ec025a0a70522f7e98760b75a77f1# Parent cecf27be38025e614faaa3698da46ecede0c8fda Merge in less methods in Object diff -r 2e3e00009c6e -r 76cdd49e774b rt/emul/compact/src/main/java/java/lang/System.java --- a/rt/emul/compact/src/main/java/java/lang/System.java Sat Mar 15 20:09:06 2014 +0100 +++ b/rt/emul/compact/src/main/java/java/lang/System.java Wed Apr 23 17:48:43 2014 +0200 @@ -43,7 +43,7 @@ } public static int identityHashCode(Object obj) { - return obj.defaultHashCode(); + return Class.defaultHashCode(obj); } public static String getProperty(String name) { diff -r 2e3e00009c6e -r 76cdd49e774b rt/emul/mini/src/main/java/java/lang/Class.java --- a/rt/emul/mini/src/main/java/java/lang/Class.java Sat Mar 15 20:09:06 2014 +0100 +++ b/rt/emul/mini/src/main/java/java/lang/Class.java Wed Apr 23 17:48:43 2014 +0200 @@ -26,15 +26,16 @@ package java.lang; import java.io.ByteArrayInputStream; -import org.apidesign.bck2brwsr.emul.reflect.AnnotationImpl; import java.io.InputStream; import java.lang.annotation.Annotation; +import java.lang.reflect.Array; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.TypeVariable; import java.net.URL; import org.apidesign.bck2brwsr.core.JavaScriptBody; +import org.apidesign.bck2brwsr.emul.reflect.AnnotationImpl; import org.apidesign.bck2brwsr.emul.reflect.MethodImpl; /** @@ -1727,4 +1728,50 @@ "return vm.desiredAssertionStatus ? vm.desiredAssertionStatus : false;" ) public native boolean desiredAssertionStatus(); + + static void registerNatives() { + boolean assertsOn = false; + // assert assertsOn = true; + if (assertsOn) { + try { + Array.get(null, 0); + } catch (Throwable ex) { + // ignore + } + } + } + + @JavaScriptBody(args = {}, body = "var p = vm.java_lang_Object(false);" + + "p.toString = function() { return this.toString__Ljava_lang_String_2(); };" + ) + static native void registerToString(); + + @JavaScriptBody(args = {"self"}, body + = "var c = self.constructor.$class;\n" + + "return c ? c : null;\n" + ) + static native Class classFor(Object self); + + @JavaScriptBody(args = { "self" }, body + = "if (self.$hashCode) return self.$hashCode;\n" + + "var h = self.computeHashCode__I ? self.computeHashCode__I() : Math.random() * Math.pow(2, 31);\n" + + "return self.$hashCode = h & h;" + ) + static native int defaultHashCode(Object self); + + @JavaScriptBody(args = "self", body + = "\nif (!self.$instOf_java_lang_Cloneable) {" + + "\n return null;" + + "\n} else {" + + "\n var clone = self.constructor(true);" + + "\n var props = Object.getOwnPropertyNames(self);" + + "\n for (var i = 0; i < props.length; i++) {" + + "\n var p = props[i];" + + "\n clone[p] = self[p];" + + "\n };" + + "\n return clone;" + + "\n}" + ) + static native Object clone(Object self) throws CloneNotSupportedException; + } diff -r 2e3e00009c6e -r 76cdd49e774b rt/emul/mini/src/main/java/java/lang/Object.java --- a/rt/emul/mini/src/main/java/java/lang/Object.java Sat Mar 15 20:09:06 2014 +0100 +++ b/rt/emul/mini/src/main/java/java/lang/Object.java Wed Apr 23 17:48:43 2014 +0200 @@ -25,7 +25,6 @@ package java.lang; -import java.lang.reflect.Array; import org.apidesign.bck2brwsr.core.JavaScriptBody; import org.apidesign.bck2brwsr.core.JavaScriptPrototype; @@ -40,23 +39,9 @@ */ @JavaScriptPrototype(container = "Object.prototype", prototype = "new Object") public class Object { - - private static void registerNatives() { - boolean assertsOn = false; - // assert assertsOn = true; - if (assertsOn) try { - Array.get(null, 0); - } catch (Throwable ex) { - // ignore - } - } - @JavaScriptBody(args = {}, body = "var p = vm.java_lang_Object(false);" + - "p.toString = function() { return this.toString__Ljava_lang_String_2(); };" - ) - private static native void registerToString(); static { - registerNatives(); - registerToString(); + Class.registerNatives(); + Class.registerToString(); } /** @@ -80,16 +65,10 @@ * The Java™ Language Specification. */ public final Class getClass() { - Class c = getClassImpl(); + Class c = Class.classFor(this); return c == null ? Object.class : c; } - @JavaScriptBody(args={}, body= - "var c = this.constructor.$class;\n" - + "return c ? c : null;\n" - ) - private final native Class getClassImpl(); - /** * Returns a hash code value for the object. This method is * supported for the benefit of hash tables such as those provided by @@ -126,18 +105,9 @@ * @see java.lang.System#identityHashCode */ public int hashCode() { - return defaultHashCode(); + return Class.defaultHashCode(this); } - @JavaScriptBody(args = {}, body = - "if (this.$hashCode) return this.$hashCode;\n" - + "var h = this.computeHashCode__I();\n" - + "return this.$hashCode = h & h;" - ) - final native int defaultHashCode(); - @JavaScriptBody(args = {}, body = "return Math.random() * Math.pow(2, 32);") - native int computeHashCode(); - /** * Indicates whether some other object is "equal to" this one. *

@@ -249,28 +219,13 @@ * @see java.lang.Cloneable */ protected Object clone() throws CloneNotSupportedException { - Object ret = clone(this); + Object ret = Class.clone(this); if (ret == null) { throw new CloneNotSupportedException(getClass().getName()); } return ret; } - @JavaScriptBody(args = "self", body = - "\nif (!self.$instOf_java_lang_Cloneable) {" - + "\n return null;" - + "\n} else {" - + "\n var clone = self.constructor(true);" - + "\n var props = Object.getOwnPropertyNames(self);" - + "\n for (var i = 0; i < props.length; i++) {" - + "\n var p = props[i];" - + "\n clone[p] = self[p];" - + "\n };" - + "\n return clone;" - + "\n}" - ) - private static native Object clone(Object self) throws CloneNotSupportedException; - /** * Returns a string representation of the object. In general, the * {@code toString} method returns a string that