mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Adds a skeleton of a new native interface to JavaScript
This commit is contained in:
parent
6a626ec493
commit
b621b0524b
1
pom.xml
1
pom.xml
|
@ -17,6 +17,7 @@
|
||||||
<module>teavm-classlib</module>
|
<module>teavm-classlib</module>
|
||||||
<module>teavm-maven-plugin</module>
|
<module>teavm-maven-plugin</module>
|
||||||
<module>teavm-samples</module>
|
<module>teavm-samples</module>
|
||||||
|
<module>teavm-dom</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
/*
|
||||||
|
* 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.javascript;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import org.teavm.javascript.ni.JSObject;
|
||||||
|
import org.teavm.model.*;
|
||||||
|
import org.teavm.model.instructions.InvokeInstruction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
class JavascriptNativeProcessor {
|
||||||
|
private ClassHolderSource classSource;
|
||||||
|
private Map<String, Boolean> knownJavaScriptClasses = new HashMap<>();
|
||||||
|
|
||||||
|
public JavascriptNativeProcessor(ClassHolderSource classSource) {
|
||||||
|
this.classSource = classSource;
|
||||||
|
knownJavaScriptClasses.put(JSObject.class.getName(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void processProgram(Program program) {
|
||||||
|
for (int i = 0; i < program.basicBlockCount(); ++i) {
|
||||||
|
BasicBlock block = program.basicBlockAt(i);
|
||||||
|
List<Instruction> instructions = block.getInstructions();
|
||||||
|
for (int j = 0; j < instructions.size(); ++j) {
|
||||||
|
Instruction insn = instructions.get(j);
|
||||||
|
if (!(insn instanceof InvokeInstruction)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isJavaScriptClass(String className) {
|
||||||
|
Boolean known = knownJavaScriptClasses.get(className);
|
||||||
|
if (known == null) {
|
||||||
|
known = exploreIfJavaScriptClass(className);
|
||||||
|
knownJavaScriptClasses.put(className, known);
|
||||||
|
}
|
||||||
|
return known;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean exploreIfJavaScriptClass(String className) {
|
||||||
|
ClassHolder cls = classSource.getClassHolder(className);
|
||||||
|
if (cls == null || !cls.getModifiers().contains(ElementModifier.INTERFACE)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (String iface : cls.getInterfaces()) {
|
||||||
|
if (isJavaScriptClass(iface)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* 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.javascript.ni;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public interface JSArray<T extends JSObject> extends JSObject, Iterable<T> {
|
||||||
|
@JSProperty
|
||||||
|
int getLength();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
T get(int index);
|
||||||
|
|
||||||
|
<S extends T> JSArray<S> cast();
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* 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.javascript.ni;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public interface JSConstructor<T extends JSObject> extends JSFunction {
|
||||||
|
T construct();
|
||||||
|
|
||||||
|
T construct(JSObject a);
|
||||||
|
|
||||||
|
T construct(JSObject a, JSObject b);
|
||||||
|
|
||||||
|
T construct(JSObject a, JSObject b, JSObject c);
|
||||||
|
|
||||||
|
T construct(JSObject a, JSObject b, JSObject c, JSObject d);
|
||||||
|
|
||||||
|
T construct(JSObject a, JSObject b, JSObject c, JSObject d, JSObject e);
|
||||||
|
|
||||||
|
T construct(JSObject a, JSObject b, JSObject c, JSObject d, JSObject e, JSObject f);
|
||||||
|
|
||||||
|
T construct(JSObject a, JSObject b, JSObject c, JSObject d, JSObject e, JSObject f, JSObject g);
|
||||||
|
|
||||||
|
T construct(JSObject a, JSObject b, JSObject c, JSObject d, JSObject e, JSObject f, JSObject g, JSObject h);
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
/*
|
||||||
|
* 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.javascript.ni;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public interface JSFunction extends JSObject {
|
||||||
|
@JSProperty
|
||||||
|
int getLength();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
JSString getName();
|
||||||
|
|
||||||
|
JSObject call(JSObject thisArg);
|
||||||
|
|
||||||
|
JSObject call(JSObject thisArg, JSObject a);
|
||||||
|
|
||||||
|
JSObject call(JSObject thisArg, JSObject a, JSObject b);
|
||||||
|
|
||||||
|
JSObject call(JSObject thisArg, JSObject a, JSObject b, JSObject c);
|
||||||
|
|
||||||
|
JSObject call(JSObject thisArg, JSObject a, JSObject b, JSObject c,
|
||||||
|
JSObject d);
|
||||||
|
|
||||||
|
JSObject call(JSObject thisArg, JSObject a, JSObject b, JSObject c,
|
||||||
|
JSObject d, JSObject e);
|
||||||
|
|
||||||
|
JSObject call(JSObject thisArg, JSObject a, JSObject b, JSObject c,
|
||||||
|
JSObject d, JSObject e, JSObject f);
|
||||||
|
|
||||||
|
JSObject call(JSObject thisArg, JSObject a, JSObject b, JSObject c,
|
||||||
|
JSObject d, JSObject e, JSObject f, JSObject g);
|
||||||
|
|
||||||
|
JSObject call(JSObject thisArg, JSObject a, JSObject b, JSObject c,
|
||||||
|
JSObject d, JSObject e, JSObject f, JSObject g, JSObject h);
|
||||||
|
|
||||||
|
JSObject apply(JSObject thisArg, JSObject[] arguments);
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* 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.javascript.ni;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.TYPE)
|
||||||
|
public @interface JSFunctor {
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
/*
|
||||||
|
* 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.javascript.ni;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public interface JSGlobal extends JSObject {
|
||||||
|
@JSProperty
|
||||||
|
JSConstructor<JSArray<JSObject>> getArray();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
JSConstructor<JSObject> getObject();
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* 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.javascript.ni;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.METHOD)
|
||||||
|
public @interface JSMethod {
|
||||||
|
String value() default "";
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
* 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.javascript.ni;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public interface JSNumber extends JSObject {
|
||||||
|
}
|
|
@ -0,0 +1,97 @@
|
||||||
|
/*
|
||||||
|
* 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.javascript.ni;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public interface JSObject {
|
||||||
|
@JSProperty
|
||||||
|
JSObject getPrototype();
|
||||||
|
|
||||||
|
JSObject get(String name);
|
||||||
|
|
||||||
|
void set(String name, JSObject obj);
|
||||||
|
|
||||||
|
JSObject get(JSString name);
|
||||||
|
|
||||||
|
void set(JSString name, JSObject obj);
|
||||||
|
|
||||||
|
JSObject get(int index);
|
||||||
|
|
||||||
|
void set(int index, JSObject obj);
|
||||||
|
|
||||||
|
JSObject invoke(String method);
|
||||||
|
|
||||||
|
JSObject invoke(String method, JSObject a);
|
||||||
|
|
||||||
|
JSObject invoke(String method, JSObject a, JSObject b);
|
||||||
|
|
||||||
|
JSObject invoke(String method, JSObject a, JSObject b, JSObject c);
|
||||||
|
|
||||||
|
JSObject invoke(String method, JSObject a, JSObject b, JSObject c, JSObject d);
|
||||||
|
|
||||||
|
JSObject invoke(String method, JSObject a, JSObject b, JSObject c, JSObject d, JSObject e);
|
||||||
|
|
||||||
|
JSObject invoke(String method, JSObject a, JSObject b, JSObject c, JSObject d, JSObject e, JSObject f);
|
||||||
|
|
||||||
|
JSObject invoke(String method, JSObject a, JSObject b, JSObject c, JSObject d, JSObject e, JSObject f, JSObject g);
|
||||||
|
|
||||||
|
JSObject invoke(String method, JSObject a, JSObject b, JSObject c, JSObject d, JSObject e, JSObject f,
|
||||||
|
JSObject g, JSObject h);
|
||||||
|
|
||||||
|
JSObject invoke(JSString method);
|
||||||
|
|
||||||
|
JSObject invoke(JSString method, JSObject a);
|
||||||
|
|
||||||
|
JSObject invoke(JSString method, JSObject a, JSObject b);
|
||||||
|
|
||||||
|
JSObject invoke(JSString method, JSObject a, JSObject b, JSObject c);
|
||||||
|
|
||||||
|
JSObject invoke(JSString method, JSObject a, JSObject b, JSObject c, JSObject d);
|
||||||
|
|
||||||
|
JSObject invoke(JSString method, JSObject a, JSObject b, JSObject c, JSObject d, JSObject e);
|
||||||
|
|
||||||
|
JSObject invoke(JSString method, JSObject a, JSObject b, JSObject c, JSObject d, JSObject e, JSObject f);
|
||||||
|
|
||||||
|
JSObject invoke(JSString method, JSObject a, JSObject b, JSObject c, JSObject d, JSObject e, JSObject f,
|
||||||
|
JSObject g);
|
||||||
|
|
||||||
|
JSObject invoke(JSString method, JSObject a, JSObject b, JSObject c, JSObject d, JSObject e, JSObject f,
|
||||||
|
JSObject g, JSObject h);
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
boolean hasOwnProperty(String property);
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
boolean hasOwnProperty(JSString property);
|
||||||
|
|
||||||
|
boolean asBoolean();
|
||||||
|
|
||||||
|
int asInteger();
|
||||||
|
|
||||||
|
double asNumber();
|
||||||
|
|
||||||
|
String asString();
|
||||||
|
|
||||||
|
boolean isNull();
|
||||||
|
|
||||||
|
boolean isUndefined();
|
||||||
|
|
||||||
|
@JSMethod("toString")
|
||||||
|
JSString toJSString();
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* 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.javascript.ni;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.METHOD)
|
||||||
|
public @interface JSProperty {
|
||||||
|
String value() default "";
|
||||||
|
}
|
61
teavm-core/src/main/java/org/teavm/javascript/ni/JSRoot.java
Normal file
61
teavm-core/src/main/java/org/teavm/javascript/ni/JSRoot.java
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
/*
|
||||||
|
* 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.javascript.ni;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public final class JSRoot {
|
||||||
|
private JSRoot() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JSType getType(JSObject obj) {
|
||||||
|
switch (getTypeName(obj).asString()) {
|
||||||
|
case "boolean":
|
||||||
|
return JSType.OBJECT;
|
||||||
|
case "number":
|
||||||
|
return JSType.NUMBER;
|
||||||
|
case "string":
|
||||||
|
return JSType.STRING;
|
||||||
|
case "function":
|
||||||
|
return JSType.FUNCTION;
|
||||||
|
case "object":
|
||||||
|
return JSType.OBJECT;
|
||||||
|
case "undefined":
|
||||||
|
return JSType.UNDEFINED;
|
||||||
|
}
|
||||||
|
throw new AssertionError("Unexpected type");
|
||||||
|
}
|
||||||
|
|
||||||
|
@GeneratedBy(JSRootNativeGenerator.class)
|
||||||
|
public static native JSString getTypeName(JSObject obj);
|
||||||
|
|
||||||
|
@GeneratedBy(JSRootNativeGenerator.class)
|
||||||
|
public static native JSObject getGlobal();
|
||||||
|
|
||||||
|
@GeneratedBy(JSRootNativeGenerator.class)
|
||||||
|
public static native JSString wrap(String str);
|
||||||
|
|
||||||
|
@GeneratedBy(JSRootNativeGenerator.class)
|
||||||
|
public static native JSNumber wrap(int num);
|
||||||
|
|
||||||
|
@GeneratedBy(JSRootNativeGenerator.class)
|
||||||
|
public static native JSNumber wrap(float num);
|
||||||
|
|
||||||
|
@GeneratedBy(JSRootNativeGenerator.class)
|
||||||
|
public static native JSNumber wrap(double num);
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
/*
|
||||||
|
* 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.javascript.ni;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import org.teavm.codegen.SourceWriter;
|
||||||
|
import org.teavm.model.FieldReference;
|
||||||
|
import org.teavm.model.MethodReference;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public class JSRootNativeGenerator implements Generator {
|
||||||
|
@Override
|
||||||
|
public void generate(GeneratorContext context, SourceWriter writer, MethodReference methodRef)
|
||||||
|
throws IOException {
|
||||||
|
switch (methodRef.getName()) {
|
||||||
|
case "getTypeName":
|
||||||
|
writer.append("return typeof ").append(context.getParameterName(1)).append(";").softNewLine();
|
||||||
|
break;
|
||||||
|
case "getGlobal":
|
||||||
|
writer.append("return window;").softNewLine();
|
||||||
|
break;
|
||||||
|
case "wrap":
|
||||||
|
if (methodRef.getParameterTypes()[0].isObject("java.lang.String")) {
|
||||||
|
generateWrapString(context, writer);
|
||||||
|
} else {
|
||||||
|
writer.append("return ").append(context.getParameterName(1)).append(";").softNewLine();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void generateWrapString(GeneratorContext context, SourceWriter writer) throws IOException {
|
||||||
|
FieldReference charsField = new FieldReference("java.lang.String", "characters");
|
||||||
|
writer.append("var result = \"\";").softNewLine();
|
||||||
|
writer.append("var data = ").append(context.getParameterName(1))
|
||||||
|
.appendField(charsField).append(".data;").softNewLine();
|
||||||
|
writer.append("for (var i = 0; i < data.length; i = (i + 1) | 0) {").indent().softNewLine();
|
||||||
|
writer.append("result += String.fromCharCode(data[i]);").softNewLine();
|
||||||
|
writer.outdent().append("}").softNewLine();
|
||||||
|
writer.append("return result;").softNewLine();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
* 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.javascript.ni;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public interface JSString extends JSObject {
|
||||||
|
|
||||||
|
}
|
29
teavm-core/src/main/java/org/teavm/javascript/ni/JSType.java
Normal file
29
teavm-core/src/main/java/org/teavm/javascript/ni/JSType.java
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
* 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.javascript.ni;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public enum JSType {
|
||||||
|
UNDEFINED,
|
||||||
|
BOOLEAN,
|
||||||
|
NUMBER,
|
||||||
|
STRING,
|
||||||
|
FUNCTION,
|
||||||
|
OBJECT
|
||||||
|
}
|
4
teavm-dom/.gitignore
vendored
Normal file
4
teavm-dom/.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
/target
|
||||||
|
.classpath
|
||||||
|
.project
|
||||||
|
.settings
|
35
teavm-dom/pom.xml
Normal file
35
teavm-dom/pom.xml
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
<!--
|
||||||
|
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.
|
||||||
|
-->
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.teavm</groupId>
|
||||||
|
<artifactId>teavm</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<artifactId>teavm-dom</artifactId>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.teavm</groupId>
|
||||||
|
<artifactId>teavm-core</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
39
teavm-dom/src/main/java/org/teavm/dom/core/Attr.java
Normal file
39
teavm-dom/src/main/java/org/teavm/dom/core/Attr.java
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* 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.dom.core;
|
||||||
|
|
||||||
|
import org.teavm.javascript.ni.JSProperty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public interface Attr extends Node {
|
||||||
|
@JSProperty
|
||||||
|
String getName();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
boolean isSpecified();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
String getValue();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
void setValue(String value);
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
Element getOwnerElement();
|
||||||
|
}
|
24
teavm-dom/src/main/java/org/teavm/dom/core/CDATASection.java
Normal file
24
teavm-dom/src/main/java/org/teavm/dom/core/CDATASection.java
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
* 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.dom.core;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public interface CDATASection extends Node {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* 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.dom.core;
|
||||||
|
|
||||||
|
import org.teavm.javascript.ni.JSProperty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public interface CharacterData extends Node {
|
||||||
|
@JSProperty
|
||||||
|
String getData();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
void setData(String data);
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
int getLength();
|
||||||
|
|
||||||
|
String substringData(int offset, int count);
|
||||||
|
|
||||||
|
void appendData(String arg);
|
||||||
|
|
||||||
|
void insertData(int offset, String arg);
|
||||||
|
|
||||||
|
void deleteData(int offset, int count);
|
||||||
|
|
||||||
|
void replaceData(int offset, int count, String arg);
|
||||||
|
}
|
24
teavm-dom/src/main/java/org/teavm/dom/core/Comment.java
Normal file
24
teavm-dom/src/main/java/org/teavm/dom/core/Comment.java
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
* 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.dom.core;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public interface Comment extends Node {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
/*
|
||||||
|
* 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.dom.core;
|
||||||
|
|
||||||
|
import org.teavm.javascript.ni.JSObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public interface DOMImplementation extends JSObject {
|
||||||
|
}
|
61
teavm-dom/src/main/java/org/teavm/dom/core/Document.java
Normal file
61
teavm-dom/src/main/java/org/teavm/dom/core/Document.java
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
/*
|
||||||
|
* 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.dom.core;
|
||||||
|
|
||||||
|
import org.teavm.javascript.ni.JSProperty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public interface Document extends Node {
|
||||||
|
@JSProperty
|
||||||
|
DocumentType getDoctype();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
DOMImplementation getImplementation();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
Element getDocumentElement();
|
||||||
|
|
||||||
|
Element createElement(String tagName);
|
||||||
|
|
||||||
|
DocumentFragment createDocumentFragment();
|
||||||
|
|
||||||
|
Text createTextNode(String data);
|
||||||
|
|
||||||
|
Comment createComment(String data);
|
||||||
|
|
||||||
|
CDATASection createCDATASection(String data);
|
||||||
|
|
||||||
|
ProcessingInstruction createProcessingInstruction(String target, String data);
|
||||||
|
|
||||||
|
Attr createAttribute(String name);
|
||||||
|
|
||||||
|
EntityReference createEntityReference(String name);
|
||||||
|
|
||||||
|
NodeList<Element> getElementsByTagName();
|
||||||
|
|
||||||
|
<T extends Node> T importNode(T importedNode, boolean deep);
|
||||||
|
|
||||||
|
Element createElementNS(String namespaceURI, String qualifiedName);
|
||||||
|
|
||||||
|
Attr createAttributeNS(String namespaceURI, String qualifiedName);
|
||||||
|
|
||||||
|
NodeList<Element> getElementsByTagNameNS(String namespaceURI, String localName);
|
||||||
|
|
||||||
|
Element getElementById(String elementId);
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
* 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.dom.core;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public interface DocumentFragment extends Node {
|
||||||
|
|
||||||
|
}
|
24
teavm-dom/src/main/java/org/teavm/dom/core/DocumentType.java
Normal file
24
teavm-dom/src/main/java/org/teavm/dom/core/DocumentType.java
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
* 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.dom.core;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public interface DocumentType extends Node {
|
||||||
|
|
||||||
|
}
|
54
teavm-dom/src/main/java/org/teavm/dom/core/Element.java
Normal file
54
teavm-dom/src/main/java/org/teavm/dom/core/Element.java
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
/*
|
||||||
|
* 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.dom.core;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public interface Element extends Node {
|
||||||
|
String getTagName();
|
||||||
|
|
||||||
|
String getAttribute(String name);
|
||||||
|
|
||||||
|
void setAttribute(String name, String value);
|
||||||
|
|
||||||
|
void removeAttribute(String name);
|
||||||
|
|
||||||
|
Attr getAttributeNode(String name);
|
||||||
|
|
||||||
|
Attr setAttributeNode(Attr newAttr);
|
||||||
|
|
||||||
|
Attr removeAttributeNode(Attr oldAttr);
|
||||||
|
|
||||||
|
NodeList<Element> getElementsByTagName(String name);
|
||||||
|
|
||||||
|
String getAttributeNS(String namespaceURI, String localName);
|
||||||
|
|
||||||
|
void setAttributeNS(String namespaceURI, String qualifiedName, String value);
|
||||||
|
|
||||||
|
void removeAttributeNS(String namespaceURI, String localName);
|
||||||
|
|
||||||
|
Attr getAttributeNodeNS(String namespaceURI, String localName);
|
||||||
|
|
||||||
|
Attr setAttributeNodeNS(Attr newAttr);
|
||||||
|
|
||||||
|
NodeList<Element> getElementsByTagNameNS(String namespaceURI, String localName);
|
||||||
|
|
||||||
|
boolean hasAttribute(String name);
|
||||||
|
|
||||||
|
boolean hasAttributeNS(String namespaceURI, String localName);
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
* 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.dom.core;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public interface EntityReference extends Node {
|
||||||
|
}
|
44
teavm-dom/src/main/java/org/teavm/dom/core/NamedNodeMap.java
Normal file
44
teavm-dom/src/main/java/org/teavm/dom/core/NamedNodeMap.java
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* 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.dom.core;
|
||||||
|
|
||||||
|
import org.teavm.javascript.ni.JSArray;
|
||||||
|
import org.teavm.javascript.ni.JSObject;
|
||||||
|
import org.teavm.javascript.ni.JSProperty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public interface NamedNodeMap<T extends Node> extends JSObject, JSArray<T> {
|
||||||
|
T getNamedItem(String name);
|
||||||
|
|
||||||
|
T setNamedItem(T arg);
|
||||||
|
|
||||||
|
T removeNamedItem(String name);
|
||||||
|
|
||||||
|
T item(int index);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@JSProperty
|
||||||
|
int getLength();
|
||||||
|
|
||||||
|
T getNamedItemNS(String namespaceURI, String localName);
|
||||||
|
|
||||||
|
T setNamedItemNS(T arg);
|
||||||
|
|
||||||
|
T removeNamedItemNS(String namespaceURI, String localName);
|
||||||
|
}
|
103
teavm-dom/src/main/java/org/teavm/dom/core/Node.java
Normal file
103
teavm-dom/src/main/java/org/teavm/dom/core/Node.java
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
/*
|
||||||
|
* 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.dom.core;
|
||||||
|
|
||||||
|
import org.teavm.javascript.ni.JSObject;
|
||||||
|
import org.teavm.javascript.ni.JSProperty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public interface Node extends JSObject {
|
||||||
|
short ELEMENT_NODE = 1;
|
||||||
|
short ATTRIBUTE_NODE = 2;
|
||||||
|
short TEXT_NODE = 3;
|
||||||
|
short CDATA_SECTION_NODE = 4;
|
||||||
|
short ENTITY_REFERENCE_NODE = 5;
|
||||||
|
short ENTITY_NODE = 6;
|
||||||
|
short PROCESSING_INSTRUCTION_NODE = 7;
|
||||||
|
short COMMENT_NODE = 8;
|
||||||
|
short DOCUMENT_NODE = 9;
|
||||||
|
short DOCUMENT_TYPE_NODE = 10;
|
||||||
|
short DOCUMENT_FRAGMENT_NODE = 11;
|
||||||
|
short NOTATION_NODE = 12;
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
String getNodeName();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
String getNodeValue();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
void setNodeValue(String value);
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
short getNodeType();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
Node getParentNode();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
NodeList<Node> getChildNodes();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
Node getFirstChild();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
Node getLastChild();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
Node getPreviousSibling();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
Node getNextSibling();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
NamedNodeMap<Attr> getAttributes();
|
||||||
|
|
||||||
|
Node insertBefore(Node newChild, Node refChild);
|
||||||
|
|
||||||
|
Node replaceChild(Node newChild, Node oldChild);
|
||||||
|
|
||||||
|
Node removeChild(Node oldChild);
|
||||||
|
|
||||||
|
Node appendChild(Node newChild);
|
||||||
|
|
||||||
|
boolean hasChildNodes();
|
||||||
|
|
||||||
|
boolean hasChildNodesJS();
|
||||||
|
|
||||||
|
Node cloneNode(boolean deep);
|
||||||
|
|
||||||
|
void normalize();
|
||||||
|
|
||||||
|
boolean isSupported(String feature, String version);
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
String getNamespaceURI();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
String getPrefix();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
void setPrefix(String prefix);
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
String getLocalName();
|
||||||
|
|
||||||
|
boolean hasAttributes();
|
||||||
|
}
|
31
teavm-dom/src/main/java/org/teavm/dom/core/NodeList.java
Normal file
31
teavm-dom/src/main/java/org/teavm/dom/core/NodeList.java
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* 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.dom.core;
|
||||||
|
|
||||||
|
import org.teavm.javascript.ni.JSArray;
|
||||||
|
import org.teavm.javascript.ni.JSProperty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public interface NodeList<T extends Node> extends JSArray<Node> {
|
||||||
|
T item(int index);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@JSProperty
|
||||||
|
int getLength();
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
* 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.dom.core;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public interface ProcessingInstruction extends Node {
|
||||||
|
|
||||||
|
}
|
24
teavm-dom/src/main/java/org/teavm/dom/core/Text.java
Normal file
24
teavm-dom/src/main/java/org/teavm/dom/core/Text.java
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
* 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.dom.core;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public interface Text extends Node {
|
||||||
|
Text splitText(int offset);
|
||||||
|
}
|
36
teavm-dom/src/main/java/org/teavm/dom/core/Window.java
Normal file
36
teavm-dom/src/main/java/org/teavm/dom/core/Window.java
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* 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.dom.core;
|
||||||
|
|
||||||
|
import org.teavm.javascript.ni.JSGlobal;
|
||||||
|
import org.teavm.javascript.ni.JSObject;
|
||||||
|
import org.teavm.javascript.ni.JSProperty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public interface Window extends JSGlobal {
|
||||||
|
@JSProperty
|
||||||
|
Document getDocument();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
Element getBody();
|
||||||
|
|
||||||
|
void alert(JSObject message);
|
||||||
|
|
||||||
|
void alert(String message);
|
||||||
|
}
|
56
teavm-dom/src/main/java/org/teavm/dom/events/Event.java
Normal file
56
teavm-dom/src/main/java/org/teavm/dom/events/Event.java
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
/*
|
||||||
|
* 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.dom.events;
|
||||||
|
|
||||||
|
import org.teavm.javascript.ni.JSObject;
|
||||||
|
import org.teavm.javascript.ni.JSProperty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public interface Event extends JSObject {
|
||||||
|
short CAPTURING_PHASE = 1;
|
||||||
|
short AT_TARGET = 2;
|
||||||
|
short BUBBLING_PHASE = 3;
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
String getType();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
EventTarget getTarget();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
EventTarget getCurrentTarget();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
short getEventPhase();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
boolean isBubbles();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
boolean isCancelable();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
JSObject getTimeStamp();
|
||||||
|
|
||||||
|
void stopPropagation();
|
||||||
|
|
||||||
|
void preventDefault();
|
||||||
|
|
||||||
|
void initEvent(String eventTypeArg, boolean canBubbleArg, boolean cancelableArg);
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
* 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.dom.events;
|
||||||
|
|
||||||
|
import org.teavm.javascript.ni.JSFunctor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
@JSFunctor
|
||||||
|
public interface EventListener {
|
||||||
|
void handleEvent(Event evt);
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* 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.dom.events;
|
||||||
|
|
||||||
|
import org.teavm.javascript.ni.JSObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public interface EventTarget extends JSObject {
|
||||||
|
void addEventListener(String type, EventListener listener, boolean useCapture);
|
||||||
|
|
||||||
|
void removeEventListener(String type, EventListener listener, boolean useCapture);
|
||||||
|
|
||||||
|
boolean dispatchEvent(Event evt);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user