Merging critical fixes (@ExtraJavaScript and String.equals) from default branch
1.1 --- a/emul/src/main/java/java/lang/Double.java Mon Jan 21 13:43:40 2013 +0100
1.2 +++ b/emul/src/main/java/java/lang/Double.java Mon Jan 21 13:46:44 2013 +0100
1.3 @@ -774,8 +774,7 @@
1.4 */
1.5 public boolean equals(Object obj) {
1.6 return (obj instanceof Double)
1.7 - && (doubleToLongBits(((Double)obj).value) ==
1.8 - doubleToLongBits(value));
1.9 + && (((Double)obj).value) == value;
1.10 }
1.11
1.12 /**
2.1 --- a/emul/src/main/java/java/lang/String.java Mon Jan 21 13:43:40 2013 +0100
2.2 +++ b/emul/src/main/java/java/lang/String.java Mon Jan 21 13:46:44 2013 +0100
2.3 @@ -994,7 +994,7 @@
2.4 * @see #equalsIgnoreCase(String)
2.5 */
2.6 @JavaScriptBody(args = { "obj" }, body =
2.7 - "return obj.$instOf_java_lang_String && "
2.8 + "return obj != null && obj.$instOf_java_lang_String && "
2.9 + "this.toString() === obj.toString();"
2.10 )
2.11 public boolean equals(Object anObject) {
3.1 --- a/emul/src/main/java/java/lang/Throwable.java Mon Jan 21 13:43:40 2013 +0100
3.2 +++ b/emul/src/main/java/java/lang/Throwable.java Mon Jan 21 13:46:44 2013 +0100
3.3 @@ -26,6 +26,7 @@
3.4 package java.lang;
3.5 import java.io.*;
3.6 import org.apidesign.bck2brwsr.core.JavaScriptBody;
3.7 +import org.apidesign.bck2brwsr.core.JavaScriptOnly;
3.8
3.9 /**
3.10 * The {@code Throwable} class is the superclass of all errors and
3.11 @@ -234,6 +235,13 @@
3.12 private static final String SELF_SUPPRESSION_MESSAGE = "Self-suppression not permitted";
3.13
3.14 /** Caption for labeling causative exception stack traces */
3.15 + @JavaScriptOnly(name="toString", value="function() { return this.toString__Ljava_lang_String_2().toString(); }")
3.16 + private static void jsToString() {
3.17 + }
3.18 +
3.19 + @JavaScriptOnly(name="valueOf", value="function() { return this.toString().valueOf(); }")
3.20 + private static void jsValudOf() {
3.21 + }
3.22 private static final String CAUSE_CAPTION = "Caused by: ";
3.23
3.24 /** Caption for labeling suppressed exception stack traces */
4.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Mon Jan 21 13:43:40 2013 +0100
4.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Mon Jan 21 13:46:44 2013 +0100
4.3 @@ -52,7 +52,7 @@
4.4 /*
4.5 * @param resourcePath name of resources to read
4.6 */
4.7 - protected abstract void requireScript(String resourcePath);
4.8 + protected abstract void requireScript(String resourcePath) throws IOException;
4.9
4.10 /** Allows subclasses to redefine what field a function representing a
4.11 * class gets assigned. By default it returns the suggested name followed
5.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/VMLazy.java Mon Jan 21 13:43:40 2013 +0100
5.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/VMLazy.java Mon Jan 21 13:46:44 2013 +0100
5.3 @@ -19,6 +19,7 @@
5.4
5.5 import java.io.ByteArrayInputStream;
5.6 import java.io.IOException;
5.7 +import java.io.InputStream;
5.8 import org.apidesign.bck2brwsr.core.JavaScriptBody;
5.9
5.10 /**
5.11 @@ -131,7 +132,17 @@
5.12 }
5.13
5.14 @Override
5.15 - protected void requireScript(String resourcePath) {
5.16 + protected void requireScript(String resourcePath) throws IOException {
5.17 + InputStream is = getClass().getResourceAsStream(resourcePath);
5.18 + StringBuilder sb = new StringBuilder();
5.19 + for (;;) {
5.20 + int ch = is.read();
5.21 + if (ch == -1) {
5.22 + break;
5.23 + }
5.24 + sb.append((char)ch);
5.25 + }
5.26 + applyCode(lazy.loader, null, sb.toString(), false);
5.27 }
5.28
5.29 @Override
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/Script.java Mon Jan 21 13:46:44 2013 +0100
6.3 @@ -0,0 +1,31 @@
6.4 +/**
6.5 + * Back 2 Browser Bytecode Translator
6.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
6.7 + *
6.8 + * This program is free software: you can redistribute it and/or modify
6.9 + * it under the terms of the GNU General Public License as published by
6.10 + * the Free Software Foundation, version 2 of the License.
6.11 + *
6.12 + * This program is distributed in the hope that it will be useful,
6.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6.15 + * GNU General Public License for more details.
6.16 + *
6.17 + * You should have received a copy of the GNU General Public License
6.18 + * along with this program. Look for COPYING file in the top folder.
6.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
6.20 + */
6.21 +package org.apidesign.vm4brwsr;
6.22 +
6.23 +import org.apidesign.bck2brwsr.core.ExtraJavaScript;
6.24 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
6.25 +
6.26 +/** Test to verify external scripts are processed in lazy mode.
6.27 + *
6.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
6.29 + */
6.30 +@ExtraJavaScript(resource = "/org/apidesign/vm4brwsr/ko.js")
6.31 +public class Script {
6.32 + @JavaScriptBody(args = { }, body = "return ko !== null;")
6.33 + public static native boolean checkNotNull();
6.34 +}
7.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/VMLazyTest.java Mon Jan 21 13:43:40 2013 +0100
7.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/VMLazyTest.java Mon Jan 21 13:46:44 2013 +0100
7.3 @@ -67,6 +67,12 @@
7.4 );
7.5 }
7.6
7.7 + @Test public void loadClassWithAssociatedScript() throws Exception {
7.8 + assertExec("ko is defined", "test", true,
7.9 + Script.class.getName(), "checkNotNull__Z"
7.10 + );
7.11 + }
7.12 +
7.13 private static void assertExec(String msg, String methodName, Object expRes, Object... args) throws Exception {
7.14 Object ret = null;
7.15 try {
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/vm/src/test/resources/org/apidesign/vm4brwsr/ko.js Mon Jan 21 13:46:44 2013 +0100
8.3 @@ -0,0 +1,20 @@
8.4 +/*
8.5 + * Back 2 Browser Bytecode Translator
8.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
8.7 + *
8.8 + * This program is free software: you can redistribute it and/or modify
8.9 + * it under the terms of the GNU General Public License as published by
8.10 + * the Free Software Foundation, version 2 of the License.
8.11 + *
8.12 + * This program is distributed in the hope that it will be useful,
8.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8.15 + * GNU General Public License for more details.
8.16 + *
8.17 + * You should have received a copy of the GNU General Public License
8.18 + * along with this program. Look for COPYING file in the top folder.
8.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
8.20 + */
8.21 +this.ko = {};
8.22 +
8.23 +
9.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CompareStringsTest.java Mon Jan 21 13:43:40 2013 +0100
9.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CompareStringsTest.java Mon Jan 21 13:46:44 2013 +0100
9.3 @@ -42,6 +42,10 @@
9.4 return String.class.cast(o);
9.5 }
9.6
9.7 + @Compare public boolean equalToNull() {
9.8 + return "Ahoj".equals(null);
9.9 + }
9.10 +
9.11 @Compare public static Object compareURLs() throws MalformedURLException {
9.12 return new URL("http://apidesign.org:8080/wiki/").toExternalForm().toString();
9.13 }