mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-23 00:24:11 -08:00
Fix bug in timer support in html4j. Remove obsolete code.
Conflicts: teavm-html4j/src/main/java/org/teavm/html4j/HTML4JPlugin.java
This commit is contained in:
parent
699dbdfb83
commit
9e9f7dbee2
|
@ -1,88 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2014 Alexey Andreev.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.teavm.html4j;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import org.teavm.codegen.SourceWriter;
|
|
||||||
import org.teavm.dependency.*;
|
|
||||||
import org.teavm.javascript.Renderer;
|
|
||||||
import org.teavm.javascript.RenderingContext;
|
|
||||||
import org.teavm.model.CallLocation;
|
|
||||||
import org.teavm.vm.BuildTarget;
|
|
||||||
import org.teavm.vm.spi.AbstractRendererListener;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Alexey Andreev
|
|
||||||
*/
|
|
||||||
public class EntryPointGenerator extends AbstractRendererListener implements DependencyListener {
|
|
||||||
private List<String> classesToLoad = new ArrayList<>();
|
|
||||||
private SourceWriter writer;
|
|
||||||
|
|
||||||
public EntryPointGenerator(String classesToLoad) {
|
|
||||||
for (String className : classesToLoad.split(",| |;")) {
|
|
||||||
className = className.trim();
|
|
||||||
if (!className.isEmpty()) {
|
|
||||||
this.classesToLoad.add(className);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void begin(RenderingContext context, BuildTarget buildTarget) throws IOException {
|
|
||||||
writer = context.getWriter();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void complete() throws IOException {
|
|
||||||
if (classesToLoad.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
writer.append("function VM() {").softNewLine();
|
|
||||||
writer.append("}").newLine();
|
|
||||||
writer.append("VM.prototype.loadClass = function(className) {").softNewLine().indent();
|
|
||||||
writer.append("switch (className) {").indent().softNewLine();
|
|
||||||
for (String className : classesToLoad) {
|
|
||||||
writer.append("case \"").append(Renderer.escapeString(className)).append("\": ");
|
|
||||||
writer.appendClass(className).append(".$clinit(); break;").softNewLine();
|
|
||||||
}
|
|
||||||
writer.append("default: throw \"Can't load class \" + className;").softNewLine();
|
|
||||||
writer.outdent().append("}").softNewLine();
|
|
||||||
writer.outdent().append("}").newLine();
|
|
||||||
writer.append("function bck2brwsr() { return new VM(); }").newLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void started(DependencyAgent agent) {
|
|
||||||
for (String className : classesToLoad) {
|
|
||||||
agent.linkClass(className, null).initClass(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void classReached(DependencyAgent agent, String className, CallLocation location) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void methodReached(DependencyAgent agent, MethodDependency method, CallLocation location) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void fieldReached(DependencyAgent agent, FieldDependency field, CallLocation location) {
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -15,8 +15,6 @@
|
||||||
*/
|
*/
|
||||||
package org.teavm.html4j;
|
package org.teavm.html4j;
|
||||||
|
|
||||||
import org.teavm.dependency.DependencyListener;
|
|
||||||
import org.teavm.vm.spi.RendererListener;
|
|
||||||
import org.teavm.vm.spi.TeaVMHost;
|
import org.teavm.vm.spi.TeaVMHost;
|
||||||
import org.teavm.vm.spi.TeaVMPlugin;
|
import org.teavm.vm.spi.TeaVMPlugin;
|
||||||
|
|
||||||
|
@ -31,9 +29,5 @@ public class HTML4JPlugin implements TeaVMPlugin {
|
||||||
host.add(new JavaScriptBodyTransformer());
|
host.add(new JavaScriptBodyTransformer());
|
||||||
host.add(new JCLHacks());
|
host.add(new JCLHacks());
|
||||||
host.add(new JavaScriptResourceInterceptor());
|
host.add(new JavaScriptResourceInterceptor());
|
||||||
EntryPointGenerator entryPointGen = new EntryPointGenerator(host.getProperties()
|
|
||||||
.getProperty("html4j.entryPoints", ""));
|
|
||||||
host.add((DependencyListener) entryPointGen);
|
|
||||||
host.add((RendererListener) entryPointGen);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,10 +34,8 @@ public class JCLHacks implements ClassHolderTransformer {
|
||||||
private void installThreadMethods(ClassHolder cls) {
|
private void installThreadMethods(ClassHolder cls) {
|
||||||
cls.addMethod(createMethodThrowingSecurityException(new MethodDescriptor("setName", String.class, void.class),
|
cls.addMethod(createMethodThrowingSecurityException(new MethodDescriptor("setName", String.class, void.class),
|
||||||
false));
|
false));
|
||||||
cls.addMethod(createMethodThrowingSecurityException(new MethodDescriptor("start", void.class), false));
|
|
||||||
cls.addMethod(createMethodThrowingSecurityException(new MethodDescriptor("setDaemon",
|
cls.addMethod(createMethodThrowingSecurityException(new MethodDescriptor("setDaemon",
|
||||||
boolean.class, void.class), false));
|
boolean.class, void.class), false));
|
||||||
cls.addMethod(createThreadSleep());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private MethodHolder createMethodThrowingSecurityException(MethodDescriptor desc, boolean staticMethod) {
|
private MethodHolder createMethodThrowingSecurityException(MethodDescriptor desc, boolean staticMethod) {
|
||||||
|
@ -71,18 +69,4 @@ public class JCLHacks implements ClassHolderTransformer {
|
||||||
method.setProgram(program);
|
method.setProgram(program);
|
||||||
return method;
|
return method;
|
||||||
}
|
}
|
||||||
|
|
||||||
private MethodHolder createThreadSleep() {
|
|
||||||
MethodHolder method = new MethodHolder("sleep", ValueType.LONG, ValueType.VOID);
|
|
||||||
Program program = new Program();
|
|
||||||
program.createVariable();
|
|
||||||
program.createVariable();
|
|
||||||
BasicBlock block = program.createBasicBlock();
|
|
||||||
ExitInstruction exit = new ExitInstruction();
|
|
||||||
block.getInstructions().add(exit);
|
|
||||||
method.setProgram(program);
|
|
||||||
method.setLevel(AccessLevel.PUBLIC);
|
|
||||||
method.getModifiers().add(ElementModifier.STATIC);
|
|
||||||
return method;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user