@@ -4,11 +4,11 @@
<parent>
<groupId>org.apidesign.bck2brwsr</groupId>
<artifactId>emul.pom</artifactId>
<version>0.20</version>
<version>0.21</version>
</parent>
<groupId>org.apidesign.bck2brwsr</groupId>
<artifactId>emul</artifactId>
<version>0.20</version>
<version>0.21</version>
<name>Bck2Brwsr API Profile</name>
<url>http://maven.apache.org</url>
<properties>
@@ -4,11 +4,11 @@
<parent>
<groupId>org.apidesign.bck2brwsr</groupId>
<artifactId>emul.pom</artifactId>
<version>0.20</version>
<version>0.21</version>
</parent>
<groupId>org.apidesign.bck2brwsr</groupId>
<artifactId>compacttest</artifactId>
<version>0.20</version>
<version>0.21</version>
<name>Bck2Brwsr API Profile Tests</name>
<url>http://maven.apache.org</url>
<properties>
@@ -4,7 +4,7 @@
<parent>
<groupId>org.apidesign.bck2brwsr</groupId>
<artifactId>emul.pom</artifactId>
<version>0.20</version>
<version>0.21</version>
</parent>
<artifactId>fake</artifactId>
<packaging>jar</packaging>
@@ -5,7 +5,7 @@
<parent>
<groupId>org.apidesign.bck2brwsr</groupId>
<artifactId>emul.pom</artifactId>
<version>1.0-SNAPSHOT</version>
<version>0.21</version>
</parent>
<groupId>org.apidesign.bck2brwsr</groupId>
<artifactId>kotlintest</artifactId>
@@ -4,11 +4,11 @@
<parent>
<groupId>org.apidesign.bck2brwsr</groupId>
<artifactId>emul.pom</artifactId>
<version>0.20</version>
<version>0.21</version>
</parent>
<groupId>org.apidesign.bck2brwsr</groupId>
<artifactId>emul.mini</artifactId>
<version>0.20</version>
<version>0.21</version>
<name>Minimal API Profile</name>
<url>http://maven.apache.org</url>
<properties>
@@ -18,7 +18,7 @@
<dependency>
<groupId>org.apidesign.bck2brwsr</groupId>
<artifactId>core</artifactId>
<version>0.20</version>
<version>0.21</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
@@ -951,7 +951,7 @@ public static long doubleToRawLongBits(double value) {
+ "}\n"
+ "var m = (hi & 0xfffff).next32(bits);\n"
+ "if (e === 0) {\n"
+ " m = m.shl64(1);\n"
+ " m = __shl64(m, 1);\n"
+ "} else {\n"
+ " m.hi = m.high32() | 0x100000;\n"
+ "}\n"
@@ -71,11 +71,19 @@ private static native void implement(
public static Proxy create(Class[] classes, InvocationHandler h) {
resetClass();
ProxiesImpl impl = new ProxiesImpl(h);
implementMethods(classes, impl);
return impl;
}

private static void implementMethods(Class[] classes, ProxiesImpl impl) {
if (classes == null) {
return;
}
for (Class c: classes) {
Object[] info = findProps(c);
implement(impl, c.getCanonicalName(), info);
implementMethods(c.getInterfaces(), impl);
}
return impl;
}

private static Object[] findProps(Class<?> annoClass) {
@@ -4,11 +4,11 @@
<parent>
<groupId>org.apidesign.bck2brwsr</groupId>
<artifactId>emul.pom</artifactId>
<version>1.0-SNAPSHOT</version>
<version>0.21</version>
</parent>
<groupId>org.apidesign.bck2brwsr</groupId>
<artifactId>minitest</artifactId>
<version>1.0-SNAPSHOT</version>
<version>0.21</version>
<name>Minimal API Profile Tests</name>
<url>http://maven.apache.org</url>
<properties>
@@ -437,6 +437,12 @@ private static char unpack(long packed, int word) { // word==0 => return a, ==3
long res = mul64shr64(16, 1561751147, -1);
return res;
}

@Compare public double longBitsToDouble() {
long res = mul64shr64(16, 1561751147, -1);
double ignore = Double.longBitsToDouble(res);
return 0.0;
}

@Factory
public static Object[] create() {
@@ -17,6 +17,7 @@
*/
package org.apidesign.bck2brwsr.mini.tck;

import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
@@ -43,6 +44,22 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
);
return anno.name();
}

@Compare public String castAnnoToAnnotation() throws Exception {
class InvHandler implements InvocationHandler {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
assert method.getName().equals("annotationType");
return Anno.class;
}
}
Annotation anno = (Annotation) Proxy.newProxyInstance(
Anno.class.getClassLoader(),
new Class[] { Anno.class },
new InvHandler()
);
return anno.annotationType().getName();
}

@Compare public int getPrimitiveType() throws Exception {
class InvHandler implements InvocationHandler {
@@ -4,11 +4,11 @@
<parent>
<groupId>org.apidesign.bck2brwsr</groupId>
<artifactId>rt</artifactId>
<version>0.20</version>
<version>0.21</version>
</parent>
<groupId>org.apidesign.bck2brwsr</groupId>
<artifactId>emul.pom</artifactId>
<version>0.20</version>
<version>0.21</version>
<packaging>pom</packaging>
<name>Emulation of Core Libraries</name>
<modules>
@@ -4,7 +4,7 @@
<parent>
<groupId>org.apidesign.bck2brwsr</groupId>
<artifactId>emul.pom</artifactId>
<version>0.20</version>
<version>0.21</version>
</parent>
<artifactId>emul.zip</artifactId>
<name>Unzip by JCraft for Bck2Brwsr</name>
@@ -4,11 +4,11 @@
<parent>
<groupId>org.apidesign.bck2brwsr</groupId>
<artifactId>rt</artifactId>
<version>0.20</version>
<version>0.21</version>
</parent>
<groupId>org.apidesign.bck2brwsr</groupId>
<artifactId>bck2brwsr-maven-plugin</artifactId>
<version>0.20</version>
<version>0.21</version>
<packaging>maven-plugin</packaging>
<name>Bck2Brwsr Maven Plugin</name>
<url>http://bck2brwsr.apidesign.org/</url>
@@ -3,13 +3,13 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.apidesign.bck2brwsr</groupId>
<artifactId>rt</artifactId>
<version>0.20</version>
<version>0.21</version>
<packaging>pom</packaging>
<name>Bck2Brwsr Runtime</name>
<parent>
<groupId>org.apidesign</groupId>
<artifactId>bck2brwsr</artifactId>
<version>0.20</version>
<version>0.21</version>
</parent>
<modules>
<module>core</module>
@@ -3,12 +3,12 @@
<parent>
<groupId>org.apidesign.bck2brwsr</groupId>
<artifactId>rt</artifactId>
<version>0.20</version>
<version>0.21</version>
</parent>

<groupId>org.apidesign.bck2brwsr</groupId>
<artifactId>vm4brwsr</artifactId>
<version>0.20</version>
<version>0.21</version>
<packaging>bundle</packaging>

<name>Virtual Machine for Browser</name>
@@ -44,7 +44,7 @@
<scm>
<connection>scm:hg:http://source.apidesign.org/hg/bck2brwsr</connection>
<url>http://source.apidesign.org/hg/bck2brwsr</url>
<tag>release-0.20</tag>
<tag>release-0.21</tag>
</scm>
<build>
<plugins>
@@ -19,6 +19,8 @@

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import org.apidesign.bck2brwsr.core.JavaScriptBody;
import org.apidesign.vm4brwsr.ByteCodeParser.ClassData;
import org.apidesign.vm4brwsr.ByteCodeParser.FieldData;
@@ -38,7 +40,7 @@ abstract class VM extends ByteCodeToJavaScript {
int exportedCount;

private VM(
Appendable out, Bck2Brwsr.Resources resources,
Appendable out, Bck2Brwsr.Resources resources,
StringArray explicitlyExported, StringArray asBinary
) {
super(out);
@@ -63,18 +65,18 @@ private VM(
boolean debug(Appendable out, String msg) throws IOException {
return false;
}
static void compile(Appendable out,

static void compile(Appendable out,
Bck2Brwsr config
) throws IOException {
String[] both = config.classes().toArray();

final StringArray fixedNames = new StringArray();
boolean addThree = false;

VM vm;
if (config.isExtension()) {
vm = new Extension(out,
vm = new Extension(out,
config.getResources(), both, config.exported(),
config.allResources(), config.classpath()
);
@@ -84,11 +86,11 @@ static void compile(Appendable out,
fixedNames.add(VM.class.getName().replace('.', '/'));
addThree = true;
}
vm = new Standalone(out,
vm = new Standalone(out,
config.getResources(), config.exported(),
config.allResources()
);
}
}
if (addThree) {
fixedNames.add(Object.class.getName().replace('.', '/'));
fixedNames.add(Class.class.getName().replace('.', '/'));
@@ -106,7 +108,7 @@ private void doCompile(Appendable out, StringArray names) throws IOException {
out.append("\n }");
generateBody(out, names);
out.append(invokerMethods);

for (String r : asBinary.toArray()) {
out.append("\n ").append(getExportsObject()).append("['registerResource']('");
out.append(r).append("', '");
@@ -137,7 +139,7 @@ private void doCompile(Appendable out, StringArray names) throws IOException {
out.append(btoa(arr));
out.append("');");
}

out.append("\n");
generateEpilogue(out);
}
@@ -156,7 +158,7 @@ private static String btoa(byte[] arr) {
protected abstract boolean isExternalClass(String className);

protected abstract void lazyReference(Appendable out, String n) throws IOException;

@Override
protected final void declareClass(Appendable out, ClassData classData, String mangledName)
throws IOException {
@@ -271,49 +273,44 @@ final void requireResourceImpl(Appendable out, boolean useEval, String resource)
if (useEval) {
out.append("(0 || eval)(\"");
}
readResource(useEval, emul, out);
try (Reader r = new InputStreamReader(emul, "UTF-8")) {
readResource(useEval, r, out);
}
if (useEval) {
out.append("\");");
}
out.append("\n");
}

private static void readResource(boolean escape, InputStream emul, Appendable out) throws IOException {
try {
for (;;) {
int ch = emul.read();
if (ch == -1) {
break;
}
if (ch < 0 || ch > 255) {
throw new IOException("Invalid char in emulation " + ch);
}
if (escape) {
switch (ch) {
case '"':
out.append("\\\"");
break;
case '\\':
out.append("\\\\");
break;
case '\n':
out.append("\\n\"\n + \"");
break;
case '\t':
out.append("\\t");
break;
case '\r':
out.append("\\r");
break;
default:
out.append((char)ch);
}
} else {
out.append((char)ch);
private static void readResource(boolean escape, Reader emul, Appendable out) throws IOException {
for (;;) {
int ch = emul.read();
if (ch == -1) {
break;
}
if (escape) {
switch (ch) {
case '"':
out.append("\\\"");
break;
case '\\':
out.append("\\\\");
break;
case '\n':
out.append("\\n\"\n + \"");
break;
case '\t':
out.append("\\t");
break;
case '\r':
out.append("\\r");
break;
default:
out.append((char)ch);
}
} else {
out.append((char)ch);
}
} finally {
emul.close();
}
}

@@ -325,7 +322,7 @@ static String toString(String name) throws IOException {

private StringArray scripts = new StringArray();
private StringArray references = new StringArray();

@Override
protected boolean requireReference(String cn) {
return references.addIfMissing(cn);
@@ -340,7 +337,7 @@ protected void requireScript(String resourcePath) {
String assignClass(String className) {
return "vm." + className + " = ";
}

@Override
String accessClass(String className) {
return "vm." + className;
@@ -382,9 +379,9 @@ protected String accessStaticMethod(

@Override
protected String accessVirtualMethod(
String object,
String mangledName,
String[] fieldInfoName,
String object,
String mangledName,
String[] fieldInfoName,
int params
) throws IOException {
final ClassData referencedClass =
@@ -406,7 +403,7 @@ protected String accessVirtualMethod(
return accessThroughInvoker(object, mangledName, params);
}

private String accessThroughInvoker(String object, String mangledName, int params)
private String accessThroughInvoker(String object, String mangledName, int params)
throws IOException {
String def = "\n invoker." + mangledName + " = function(target";
if (invokerMethods.indexOf(def) == -1) {
@@ -504,7 +501,7 @@ public MethodData getFound() {

private static final class Standalone extends VM {
private Standalone(Appendable out,
Bck2Brwsr.Resources resources,
Bck2Brwsr.Resources resources,
StringArray explicitlyExported, StringArray asBinary
) {
super(out, resources, explicitlyExported, asBinary);
@@ -760,7 +757,7 @@ protected String getExportsObject() {
protected boolean isExternalClass(String className) {
return false;
}

@Override
protected void lazyReference(Appendable out, String n) throws IOException {
String cls = n.replace('/', '_');
@@ -880,7 +877,7 @@ protected String getExportsObject() {
protected boolean isExternalClass(String className) {
return !extensionClasses.contains(className);
}

@Override
protected void lazyReference(Appendable out, String n) throws IOException {
String cls = n.replace('/', '_');
@@ -37,6 +37,15 @@ static Object retObj() {
return null;
}

@JavaScriptBody(args = {}, body = "return thisObj.yellowish_horse;")
static String retHorse() {
return null;
}

public static String getHorse() {
return retHorse();
}

public static boolean isObj() {
return retObj() != null;
}
@@ -52,6 +52,13 @@ public class ResourcesWithExtensionsTest {
Resources.class, "isObj__Z", 1.0
);
}

@Test public void yellowHorseFound() throws Exception {
assertExec("Non ASCII text properly transpiled",
Resources.class, "getHorse__Ljava_lang_String_2", "Žluťoučký kůň"
);
}

@Test public void objJSIsFound() throws Exception {
assertExec("The resources used as @JavaScriptResource aren't available",
Resources.class, "isResource__ZLjava_lang_String_2", 0.0, "obj"
@@ -16,5 +16,4 @@
* If not, see http://opensource.org/licenses/GPL-2.0.
*/
this.thisObj = {};


this.thisObj.yellowish_horse = 'Žluťoučký kůň';
@@ -4,7 +4,7 @@
<parent>
<groupId>org.apidesign.bck2brwsr</groupId>
<artifactId>rt</artifactId>
<version>1.0-SNAPSHOT</version>
<version>0.21</version>
</parent>
<artifactId>vm8</artifactId>
<name>Bck2Brwsr on JDK8</name>
@@ -4,11 +4,11 @@
<parent>
<groupId>org.apidesign.bck2brwsr</groupId>
<artifactId>rt</artifactId>
<version>0.20</version>
<version>0.21</version>
</parent>
<groupId>org.apidesign.bck2brwsr</groupId>
<artifactId>vmtest</artifactId>
<version>0.20</version>
<version>0.21</version>

<name>VM Testing APIs</name>
<url>http://bck2brwsr.apidesign.org</url>