1.1 --- a/rt/emul/mini/src/main/java/java/lang/Object.java Sat Feb 15 23:13:53 2014 +0100
1.2 +++ b/rt/emul/mini/src/main/java/java/lang/Object.java Wed Apr 23 17:48:43 2014 +0200
1.3 @@ -25,7 +25,6 @@
1.4
1.5 package java.lang;
1.6
1.7 -import java.lang.reflect.Array;
1.8 import org.apidesign.bck2brwsr.core.JavaScriptBody;
1.9 import org.apidesign.bck2brwsr.core.JavaScriptPrototype;
1.10
1.11 @@ -40,23 +39,9 @@
1.12 */
1.13 @JavaScriptPrototype(container = "Object.prototype", prototype = "new Object")
1.14 public class Object {
1.15 -
1.16 - private static void registerNatives() {
1.17 - boolean assertsOn = false;
1.18 - // assert assertsOn = true;
1.19 - if (assertsOn) try {
1.20 - Array.get(null, 0);
1.21 - } catch (Throwable ex) {
1.22 - // ignore
1.23 - }
1.24 - }
1.25 - @JavaScriptBody(args = {}, body = "var p = vm.java_lang_Object(false);" +
1.26 - "p.toString = function() { return this.toString__Ljava_lang_String_2(); };"
1.27 - )
1.28 - private static native void registerToString();
1.29 static {
1.30 - registerNatives();
1.31 - registerToString();
1.32 + Class.registerNatives();
1.33 + Class.registerToString();
1.34 }
1.35
1.36 /**
1.37 @@ -80,16 +65,10 @@
1.38 * <cite>The Java™ Language Specification</cite>.
1.39 */
1.40 public final Class<?> getClass() {
1.41 - Class<?> c = getClassImpl();
1.42 + Class<?> c = Class.classFor(this);
1.43 return c == null ? Object.class : c;
1.44 }
1.45
1.46 - @JavaScriptBody(args={}, body=
1.47 - "var c = this.constructor.$class;\n"
1.48 - + "return c ? c : null;\n"
1.49 - )
1.50 - private final native Class<?> getClassImpl();
1.51 -
1.52 /**
1.53 * Returns a hash code value for the object. This method is
1.54 * supported for the benefit of hash tables such as those provided by
1.55 @@ -126,18 +105,9 @@
1.56 * @see java.lang.System#identityHashCode
1.57 */
1.58 public int hashCode() {
1.59 - return defaultHashCode();
1.60 + return Class.defaultHashCode(this);
1.61 }
1.62 - @JavaScriptBody(args = {}, body =
1.63 - "if (this.$hashCode) return this.$hashCode;\n"
1.64 - + "var h = this.computeHashCode__I();\n"
1.65 - + "return this.$hashCode = h & h;"
1.66 - )
1.67 - final native int defaultHashCode();
1.68
1.69 - @JavaScriptBody(args = {}, body = "return Math.random() * Math.pow(2, 32);")
1.70 - native int computeHashCode();
1.71 -
1.72 /**
1.73 * Indicates whether some other object is "equal to" this one.
1.74 * <p>
1.75 @@ -249,28 +219,13 @@
1.76 * @see java.lang.Cloneable
1.77 */
1.78 protected Object clone() throws CloneNotSupportedException {
1.79 - Object ret = clone(this);
1.80 + Object ret = Class.clone(this);
1.81 if (ret == null) {
1.82 throw new CloneNotSupportedException(getClass().getName());
1.83 }
1.84 return ret;
1.85 }
1.86
1.87 - @JavaScriptBody(args = "self", body =
1.88 - "\nif (!self.$instOf_java_lang_Cloneable) {"
1.89 - + "\n return null;"
1.90 - + "\n} else {"
1.91 - + "\n var clone = self.constructor(true);"
1.92 - + "\n var props = Object.getOwnPropertyNames(self);"
1.93 - + "\n for (var i = 0; i < props.length; i++) {"
1.94 - + "\n var p = props[i];"
1.95 - + "\n clone[p] = self[p];"
1.96 - + "\n };"
1.97 - + "\n return clone;"
1.98 - + "\n}"
1.99 - )
1.100 - private static native Object clone(Object self) throws CloneNotSupportedException;
1.101 -
1.102 /**
1.103 * Returns a string representation of the object. In general, the
1.104 * {@code toString} method returns a string that