emul/src/main/java/java/lang/Object.java
changeset 411 6506d5132e03
parent 335 b8fd5ab83a20
child 429 7c4442271367
     1.1 --- a/emul/src/main/java/java/lang/Object.java	Sun Dec 16 21:19:26 2012 +0100
     1.2 +++ b/emul/src/main/java/java/lang/Object.java	Mon Jan 07 16:46:09 2013 +0100
     1.3 @@ -221,7 +221,28 @@
     1.4       *               be cloned.
     1.5       * @see java.lang.Cloneable
     1.6       */
     1.7 -    protected native Object clone() throws CloneNotSupportedException;
     1.8 +    protected Object clone() throws CloneNotSupportedException {
     1.9 +        Object ret = clone(this);
    1.10 +        if (ret == null) {
    1.11 +            throw new CloneNotSupportedException(getClass().getName());
    1.12 +        }
    1.13 +        return ret;
    1.14 +    }
    1.15 +
    1.16 +    @JavaScriptBody(args = "self", body = 
    1.17 +          "\nif (!self.$instOf_java_lang_Cloneable) {"
    1.18 +        + "\n  return null;"
    1.19 +        + "\n} else {"
    1.20 +        + "\n  var clone = self.constructor(true);"
    1.21 +        + "\n  var props = Object.getOwnPropertyNames(self);"
    1.22 +        + "\n  for (var i = 0; i < props.length; i++) {"
    1.23 +        + "\n    var p = props[i];"
    1.24 +        + "\n    clone[p] = self[p];"
    1.25 +        + "\n  };"
    1.26 +        + "\n  return clone;"
    1.27 +        + "\n}"
    1.28 +    )
    1.29 +    private static native Object clone(Object self) throws CloneNotSupportedException;
    1.30  
    1.31      /**
    1.32       * Returns a string representation of the object. In general, the