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; import org.teavm.backend.javascript.spi.GeneratedBy;
/**
*
* @author Alexey Andreev
*/
public final class JavaScriptConv { public final class JavaScriptConv {
private 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.backend.javascript.spi.GeneratorContext;
import org.teavm.model.*; import org.teavm.model.*;
/**
*
* @author Alexey Andreev
*/
public class JavaScriptConvGenerator implements Generator { public class JavaScriptConvGenerator implements Generator {
static final MethodReference intValueMethod = new MethodReference(Integer.class, "intValue", int.class); static final MethodReference intValueMethod = new MethodReference(Integer.class, "intValue", int.class);
static final MethodReference booleanValueMethod = new MethodReference(Boolean.class, "booleanValue", boolean.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 { private void generateToJavaScript(GeneratorContext context, SourceWriter writer) throws IOException {
String obj = context.getParameterName(1); String obj = context.getParameterName(1);
writer.append("if (" + obj + " === null || " + obj + " === undefined) {").softNewLine().indent(); 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.outdent().append("} else if (typeof " + obj + " === 'number') {").indent().softNewLine();
writer.append("return " + obj + ";").softNewLine(); writer.append("return " + obj + ";").softNewLine();
@ -118,7 +114,7 @@ public class JavaScriptConvGenerator implements Generator {
String type = context.getParameterName(2); String type = context.getParameterName(2);
writer.append("if (" + obj + " === null || " + obj + " === undefined)").ws().append("{") writer.append("if (" + obj + " === null || " + obj + " === undefined)").ws().append("{")
.softNewLine().indent(); .softNewLine().indent();
writer.append("return " + obj + ";").softNewLine(); writer.append("return null;").softNewLine();
writer.outdent().append("} else if (" + type + ".$meta.item) {").indent().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("var arr = $rt_createArray(" + type + ".$meta.item, " + obj + ".length);").softNewLine();
writer.append("for (var i = 0; i < arr.data.length; ++i) {").indent().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 @Test @Override
public void callbackUnknownArray() { public void callbackUnknownArray() {
// super.callbackUnknownArray(); super.callbackUnknownArray();
} }
@Test @Override @Test @Override
public void callbackUnknown() { public void callbackUnknown() {
// super.callbackUnknown(); super.callbackUnknown();
} }
@Test @Override @Test @Override
@ -71,7 +71,7 @@ public class JavaScriptTCKTest extends JavaScriptBodyTest {
@Test @Override @Test @Override
public void returnUnknownArray() { public void returnUnknownArray() {
// super.returnUnknownArray(); super.returnUnknownArray();
} }
@Test @Override @Test @Override
@ -81,7 +81,7 @@ public class JavaScriptTCKTest extends JavaScriptBodyTest {
@Test @Override @Test @Override
public void returnUnknown() { public void returnUnknown() {
// super.returnUnknown(); super.returnUnknown();
} }
@Test @Override @Test @Override