1.1 --- a/rt/emul/mini/src/main/java/java/lang/Number.java Tue Feb 26 16:54:16 2013 +0100
1.2 +++ b/rt/emul/mini/src/main/java/java/lang/Number.java Wed Feb 27 17:50:47 2013 +0100
1.3 @@ -26,6 +26,9 @@
1.4 package java.lang;
1.5
1.6 import org.apidesign.bck2brwsr.core.ExtraJavaScript;
1.7 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
1.8 +import org.apidesign.bck2brwsr.core.JavaScriptOnly;
1.9 +import org.apidesign.bck2brwsr.core.JavaScriptPrototype;
1.10
1.11 /**
1.12 * The abstract class <code>Number</code> is the superclass of classes
1.13 @@ -52,6 +55,7 @@
1.14 resource="/org/apidesign/vm4brwsr/emul/lang/java_lang_Number.js",
1.15 processByteCode=true
1.16 )
1.17 +@JavaScriptPrototype(container = "Number.prototype", prototype = "new Number")
1.18 public abstract class Number implements java.io.Serializable {
1.19 /**
1.20 * Returns the value of the specified number as an <code>int</code>.
1.21 @@ -60,6 +64,7 @@
1.22 * @return the numeric value represented by this object after conversion
1.23 * to type <code>int</code>.
1.24 */
1.25 + @JavaScriptBody(args = {}, body = "return this | 0;")
1.26 public abstract int intValue();
1.27
1.28 /**
1.29 @@ -69,6 +74,7 @@
1.30 * @return the numeric value represented by this object after conversion
1.31 * to type <code>long</code>.
1.32 */
1.33 + @JavaScriptBody(args = {}, body = "return this.toLong();")
1.34 public abstract long longValue();
1.35
1.36 /**
1.37 @@ -78,6 +84,7 @@
1.38 * @return the numeric value represented by this object after conversion
1.39 * to type <code>float</code>.
1.40 */
1.41 + @JavaScriptBody(args = {}, body = "return this;")
1.42 public abstract float floatValue();
1.43
1.44 /**
1.45 @@ -87,6 +94,7 @@
1.46 * @return the numeric value represented by this object after conversion
1.47 * to type <code>double</code>.
1.48 */
1.49 + @JavaScriptBody(args = {}, body = "return this;")
1.50 public abstract double doubleValue();
1.51
1.52 /**
1.53 @@ -115,4 +123,15 @@
1.54
1.55 /** use serialVersionUID from JDK 1.0.2 for interoperability */
1.56 private static final long serialVersionUID = -8742448824652078965L;
1.57 +
1.58 + static {
1.59 + // as last step of initialization, initialize valueOf method
1.60 + initValueOf();
1.61 + }
1.62 + @JavaScriptBody(args = { }, body =
1.63 + "var p = vm.java_lang_Number(false);\n" +
1.64 + "p.valueOf = function() { return this.doubleValue__D(); };\n" +
1.65 + "p.toString = function() { return this.toString__Ljava_lang_String_2(); };"
1.66 + )
1.67 + private native static void initValueOf();
1.68 }