# HG changeset patch # User Jaroslav Tulach # Date 1358772404 -3600 # Node ID 305a67fe4ed20fddb973ffb063a1d37c919edf39 # Parent 4198be34b51688855ef79e53c5fedef1d186374f# Parent 974bc55865c78756cc2bb57717074d14449bb349 Merging critical fixes (@ExtraJavaScript and String.equals) from default branch diff -r 4198be34b516 -r 305a67fe4ed2 emul/src/main/java/java/lang/Double.java --- a/emul/src/main/java/java/lang/Double.java Mon Jan 21 13:43:40 2013 +0100 +++ b/emul/src/main/java/java/lang/Double.java Mon Jan 21 13:46:44 2013 +0100 @@ -774,8 +774,7 @@ */ public boolean equals(Object obj) { return (obj instanceof Double) - && (doubleToLongBits(((Double)obj).value) == - doubleToLongBits(value)); + && (((Double)obj).value) == value; } /** diff -r 4198be34b516 -r 305a67fe4ed2 emul/src/main/java/java/lang/String.java --- a/emul/src/main/java/java/lang/String.java Mon Jan 21 13:43:40 2013 +0100 +++ b/emul/src/main/java/java/lang/String.java Mon Jan 21 13:46:44 2013 +0100 @@ -994,7 +994,7 @@ * @see #equalsIgnoreCase(String) */ @JavaScriptBody(args = { "obj" }, body = - "return obj.$instOf_java_lang_String && " + "return obj != null && obj.$instOf_java_lang_String && " + "this.toString() === obj.toString();" ) public boolean equals(Object anObject) { diff -r 4198be34b516 -r 305a67fe4ed2 emul/src/main/java/java/lang/Throwable.java --- a/emul/src/main/java/java/lang/Throwable.java Mon Jan 21 13:43:40 2013 +0100 +++ b/emul/src/main/java/java/lang/Throwable.java Mon Jan 21 13:46:44 2013 +0100 @@ -26,6 +26,7 @@ package java.lang; import java.io.*; import org.apidesign.bck2brwsr.core.JavaScriptBody; +import org.apidesign.bck2brwsr.core.JavaScriptOnly; /** * The {@code Throwable} class is the superclass of all errors and @@ -234,6 +235,13 @@ private static final String SELF_SUPPRESSION_MESSAGE = "Self-suppression not permitted"; /** Caption for labeling causative exception stack traces */ + @JavaScriptOnly(name="toString", value="function() { return this.toString__Ljava_lang_String_2().toString(); }") + private static void jsToString() { + } + + @JavaScriptOnly(name="valueOf", value="function() { return this.toString().valueOf(); }") + private static void jsValudOf() { + } private static final String CAUSE_CAPTION = "Caused by: "; /** Caption for labeling suppressed exception stack traces */ diff -r 4198be34b516 -r 305a67fe4ed2 vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java --- a/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Mon Jan 21 13:43:40 2013 +0100 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Mon Jan 21 13:46:44 2013 +0100 @@ -52,7 +52,7 @@ /* * @param resourcePath name of resources to read */ - protected abstract void requireScript(String resourcePath); + protected abstract void requireScript(String resourcePath) throws IOException; /** Allows subclasses to redefine what field a function representing a * class gets assigned. By default it returns the suggested name followed diff -r 4198be34b516 -r 305a67fe4ed2 vm/src/main/java/org/apidesign/vm4brwsr/VMLazy.java --- a/vm/src/main/java/org/apidesign/vm4brwsr/VMLazy.java Mon Jan 21 13:43:40 2013 +0100 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/VMLazy.java Mon Jan 21 13:46:44 2013 +0100 @@ -19,6 +19,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; +import java.io.InputStream; import org.apidesign.bck2brwsr.core.JavaScriptBody; /** @@ -131,7 +132,17 @@ } @Override - protected void requireScript(String resourcePath) { + protected void requireScript(String resourcePath) throws IOException { + InputStream is = getClass().getResourceAsStream(resourcePath); + StringBuilder sb = new StringBuilder(); + for (;;) { + int ch = is.read(); + if (ch == -1) { + break; + } + sb.append((char)ch); + } + applyCode(lazy.loader, null, sb.toString(), false); } @Override diff -r 4198be34b516 -r 305a67fe4ed2 vm/src/test/java/org/apidesign/vm4brwsr/Script.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/Script.java Mon Jan 21 13:46:44 2013 +0100 @@ -0,0 +1,31 @@ +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012 Jaroslav Tulach + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +package org.apidesign.vm4brwsr; + +import org.apidesign.bck2brwsr.core.ExtraJavaScript; +import org.apidesign.bck2brwsr.core.JavaScriptBody; + +/** Test to verify external scripts are processed in lazy mode. + * + * @author Jaroslav Tulach + */ +@ExtraJavaScript(resource = "/org/apidesign/vm4brwsr/ko.js") +public class Script { + @JavaScriptBody(args = { }, body = "return ko !== null;") + public static native boolean checkNotNull(); +} diff -r 4198be34b516 -r 305a67fe4ed2 vm/src/test/java/org/apidesign/vm4brwsr/VMLazyTest.java --- a/vm/src/test/java/org/apidesign/vm4brwsr/VMLazyTest.java Mon Jan 21 13:43:40 2013 +0100 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/VMLazyTest.java Mon Jan 21 13:46:44 2013 +0100 @@ -67,6 +67,12 @@ ); } + @Test public void loadClassWithAssociatedScript() throws Exception { + assertExec("ko is defined", "test", true, + Script.class.getName(), "checkNotNull__Z" + ); + } + private static void assertExec(String msg, String methodName, Object expRes, Object... args) throws Exception { Object ret = null; try { diff -r 4198be34b516 -r 305a67fe4ed2 vm/src/test/resources/org/apidesign/vm4brwsr/ko.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm/src/test/resources/org/apidesign/vm4brwsr/ko.js Mon Jan 21 13:46:44 2013 +0100 @@ -0,0 +1,20 @@ +/* + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012 Jaroslav Tulach + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +this.ko = {}; + + diff -r 4198be34b516 -r 305a67fe4ed2 vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CompareStringsTest.java --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CompareStringsTest.java Mon Jan 21 13:43:40 2013 +0100 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CompareStringsTest.java Mon Jan 21 13:46:44 2013 +0100 @@ -42,6 +42,10 @@ return String.class.cast(o); } + @Compare public boolean equalToNull() { + return "Ahoj".equals(null); + } + @Compare public static Object compareURLs() throws MalformedURLException { return new URL("http://apidesign.org:8080/wiki/").toExternalForm().toString(); }