mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-23 00:24:11 -08:00
html4j: implement undefined-to-null conversion
This commit is contained in:
parent
56a03e44b1
commit
c4ada881d2
|
@ -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() {
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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
|
||||||
|
@ -236,7 +236,7 @@ public class JavaScriptTCKTest extends JavaScriptBodyTest {
|
||||||
|
|
||||||
@Test @Override
|
@Test @Override
|
||||||
public void toStringOfAnEnum() {
|
public void toStringOfAnEnum() {
|
||||||
// super.toStringOfAnEnum();
|
//super.toStringOfAnEnum();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test @Override
|
@Test @Override
|
||||||
|
|
Loading…
Reference in New Issue
Block a user