rt/emul/mini/src/main/java/java/lang/Object.java
branchclosure
changeset 1513 ba912ef24b27
parent 1082 977cc6141083
parent 1484 76cdd49e774b
     1.1 --- a/rt/emul/mini/src/main/java/java/lang/Object.java	Fri May 03 18:15:47 2013 +0200
     1.2 +++ b/rt/emul/mini/src/main/java/java/lang/Object.java	Wed Apr 30 15:04:10 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 = false;
    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 @@ -79,8 +64,10 @@
    1.38       * @see    Class Literals, section 15.8.2 of
    1.39       *         <cite>The Java&trade; Language Specification</cite>.
    1.40       */
    1.41 -    @JavaScriptBody(args={}, body="return this.constructor.$class;")
    1.42 -    public final native Class<?> getClass();
    1.43 +    public final Class<?> getClass() {
    1.44 +        Class<?> c = Class.classFor(this);
    1.45 +        return c == null ? Object.class : c;
    1.46 +    }
    1.47  
    1.48      /**
    1.49       * Returns a hash code value for the object. This method is
    1.50 @@ -117,16 +104,10 @@
    1.51       * @see     java.lang.Object#equals(java.lang.Object)
    1.52       * @see     java.lang.System#identityHashCode
    1.53       */
    1.54 -    @JavaScriptBody(args = {}, body = 
    1.55 -        "if (this.$hashCode) return this.$hashCode;\n"
    1.56 -        + "var h = this.computeHashCode__I();\n"
    1.57 -        + "return this.$hashCode = h & h;"
    1.58 -    )
    1.59 -    public native int hashCode();
    1.60 +    public int hashCode() {
    1.61 +        return Class.defaultHashCode(this);
    1.62 +    }
    1.63  
    1.64 -    @JavaScriptBody(args = {}, body = "return Math.random() * Math.pow(2, 32);")
    1.65 -    native int computeHashCode();
    1.66 -    
    1.67      /**
    1.68       * Indicates whether some other object is "equal to" this one.
    1.69       * <p>
    1.70 @@ -238,28 +219,13 @@
    1.71       * @see java.lang.Cloneable
    1.72       */
    1.73      protected Object clone() throws CloneNotSupportedException {
    1.74 -        Object ret = clone(this);
    1.75 +        Object ret = Class.clone(this);
    1.76          if (ret == null) {
    1.77              throw new CloneNotSupportedException(getClass().getName());
    1.78          }
    1.79          return ret;
    1.80      }
    1.81  
    1.82 -    @JavaScriptBody(args = "self", body = 
    1.83 -          "\nif (!self['$instOf_java_lang_Cloneable']) {"
    1.84 -        + "\n  return null;"
    1.85 -        + "\n} else {"
    1.86 -        + "\n  var clone = self.constructor(true);"
    1.87 -        + "\n  var props = Object.getOwnPropertyNames(self);"
    1.88 -        + "\n  for (var i = 0; i < props.length; i++) {"
    1.89 -        + "\n    var p = props[i];"
    1.90 -        + "\n    clone[p] = self[p];"
    1.91 -        + "\n  };"
    1.92 -        + "\n  return clone;"
    1.93 -        + "\n}"
    1.94 -    )
    1.95 -    private static native Object clone(Object self) throws CloneNotSupportedException;
    1.96 -
    1.97      /**
    1.98       * Returns a string representation of the object. In general, the
    1.99       * {@code toString} method returns a string that
   1.100 @@ -317,7 +283,8 @@
   1.101       * @see        java.lang.Object#notifyAll()
   1.102       * @see        java.lang.Object#wait()
   1.103       */
   1.104 -    public final native void notify();
   1.105 +    public final void notify() {
   1.106 +    }
   1.107  
   1.108      /**
   1.109       * Wakes up all threads that are waiting on this object's monitor. A
   1.110 @@ -341,7 +308,8 @@
   1.111       * @see        java.lang.Object#notify()
   1.112       * @see        java.lang.Object#wait()
   1.113       */
   1.114 -    public final native void notifyAll();
   1.115 +    public final void notifyAll() {
   1.116 +    }
   1.117  
   1.118      /**
   1.119       * Causes the current thread to wait until either another thread invokes the
   1.120 @@ -428,7 +396,9 @@
   1.121       * @see        java.lang.Object#notify()
   1.122       * @see        java.lang.Object#notifyAll()
   1.123       */
   1.124 -    public final native void wait(long timeout) throws InterruptedException;
   1.125 +    public final void wait(long timeout) throws InterruptedException {
   1.126 +        throw new InterruptedException();
   1.127 +    }
   1.128  
   1.129      /**
   1.130       * Causes the current thread to wait until another thread invokes the
   1.131 @@ -493,20 +463,7 @@
   1.132       *             this exception is thrown.
   1.133       */
   1.134      public final void wait(long timeout, int nanos) throws InterruptedException {
   1.135 -        if (timeout < 0) {
   1.136 -            throw new IllegalArgumentException("timeout value is negative");
   1.137 -        }
   1.138 -
   1.139 -        if (nanos < 0 || nanos > 999999) {
   1.140 -            throw new IllegalArgumentException(
   1.141 -                                "nanosecond timeout value out of range");
   1.142 -        }
   1.143 -
   1.144 -        if (nanos >= 500000 || (nanos != 0 && timeout == 0)) {
   1.145 -            timeout++;
   1.146 -        }
   1.147 -
   1.148 -        wait(timeout);
   1.149 +        throw new InterruptedException();
   1.150      }
   1.151  
   1.152      /**
   1.153 @@ -548,7 +505,7 @@
   1.154       * @see        java.lang.Object#notifyAll()
   1.155       */
   1.156      public final void wait() throws InterruptedException {
   1.157 -        wait(0);
   1.158 +        throw new InterruptedException();
   1.159      }
   1.160  
   1.161      /**