html4j: implement undefined-to-null conversion

This commit is contained in:
Alexey Andreev 2017-04-15 12:39:50 +03:00
parent 56a03e44b1
commit c4ada881d2
3 changed files with 7 additions and 15 deletions

View File

@ -17,10 +17,6 @@ package org.teavm.html4j;
import org.teavm.backend.javascript.spi.GeneratedBy;
/**
*
* @author Alexey Andreev
*/
public final class JavaScriptConv {
private JavaScriptConv() {
}

View File

@ -21,10 +21,6 @@ import org.teavm.backend.javascript.spi.Generator;
import org.teavm.backend.javascript.spi.GeneratorContext;
import org.teavm.model.*;
/**
*
* @author Alexey Andreev
*/
public class JavaScriptConvGenerator implements Generator {
static final MethodReference intValueMethod = new MethodReference(Integer.class, "intValue", int.class);
static final MethodReference booleanValueMethod = new MethodReference(Boolean.class, "booleanValue", boolean.class);
@ -66,7 +62,7 @@ public class JavaScriptConvGenerator implements Generator {
private void generateToJavaScript(GeneratorContext context, SourceWriter writer) throws IOException {
String obj = context.getParameterName(1);
writer.append("if (" + obj + " === null || " + obj + " === undefined) {").softNewLine().indent();
writer.append("return " + obj + ";").softNewLine();
writer.append("return null;").softNewLine();
writer.outdent().append("} else if (typeof " + obj + " === 'number') {").indent().softNewLine();
writer.append("return " + obj + ";").softNewLine();
@ -118,7 +114,7 @@ public class JavaScriptConvGenerator implements Generator {
String type = context.getParameterName(2);
writer.append("if (" + obj + " === null || " + obj + " === undefined)").ws().append("{")
.softNewLine().indent();
writer.append("return " + obj + ";").softNewLine();
writer.append("return null;").softNewLine();
writer.outdent().append("} else if (" + type + ".$meta.item) {").indent().softNewLine();
writer.append("var arr = $rt_createArray(" + type + ".$meta.item, " + obj + ".length);").softNewLine();
writer.append("for (var i = 0; i < arr.data.length; ++i) {").indent().softNewLine();

View File

@ -56,12 +56,12 @@ public class JavaScriptTCKTest extends JavaScriptBodyTest {
@Test @Override
public void callbackUnknownArray() {
// super.callbackUnknownArray();
super.callbackUnknownArray();
}
@Test @Override
public void callbackUnknown() {
// super.callbackUnknown();
super.callbackUnknown();
}
@Test @Override
@ -71,7 +71,7 @@ public class JavaScriptTCKTest extends JavaScriptBodyTest {
@Test @Override
public void returnUnknownArray() {
// super.returnUnknownArray();
super.returnUnknownArray();
}
@Test @Override
@ -81,7 +81,7 @@ public class JavaScriptTCKTest extends JavaScriptBodyTest {
@Test @Override
public void returnUnknown() {
// super.returnUnknown();
super.returnUnknown();
}
@Test @Override
@ -236,7 +236,7 @@ public class JavaScriptTCKTest extends JavaScriptBodyTest {
@Test @Override
public void toStringOfAnEnum() {
// super.toStringOfAnEnum();
//super.toStringOfAnEnum();
}
@Test @Override