Adds a skeleton of a new native interface to JavaScript

This commit is contained in:
konsoletyper 2014-02-06 13:00:46 +04:00
parent 6a626ec493
commit b621b0524b
36 changed files with 1363 additions and 0 deletions

View File

@ -17,6 +17,7 @@
<module>teavm-classlib</module>
<module>teavm-maven-plugin</module>
<module>teavm-samples</module>
<module>teavm-dom</module>
</modules>
<build>

View File

@ -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;
}
}

View File

@ -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();
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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 {
}

View File

@ -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();
}

View 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.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 "";
}

View File

@ -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 {
}

View File

@ -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();
}

View 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.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 "";
}

View 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);
}

View File

@ -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();
}
}

View 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.javascript.ni;
/**
*
* @author Alexey Andreev
*/
public interface JSString extends JSObject {
}

View 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
View File

@ -0,0 +1,4 @@
/target
.classpath
.project
.settings

35
teavm-dom/pom.xml Normal file
View 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>

View 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();
}

View 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 {
}

View File

@ -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);
}

View 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 {
}

View File

@ -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 {
}

View 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);
}

View 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 DocumentFragment extends Node {
}

View 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 {
}

View 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);
}

View File

@ -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 {
}

View 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);
}

View 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();
}

View 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();
}

View 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 ProcessingInstruction extends Node {
}

View 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);
}

View 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);
}

View 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);
}

View File

@ -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);
}

View File

@ -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);
}