JS: add more API declarations

This commit is contained in:
Alexey Andreev 2019-01-27 23:46:09 +03:00
parent f734603255
commit fc9a53bdd3
12 changed files with 255 additions and 1 deletions

View File

@ -90,4 +90,9 @@ public abstract class XMLHttpRequest implements JSObject {
@JSBody(script = "return new XMLHttpRequest();") @JSBody(script = "return new XMLHttpRequest();")
public static native XMLHttpRequest create(); public static native XMLHttpRequest create();
public abstract void abort();
@JSProperty
public abstract String getResponseURL();
} }

View File

@ -30,4 +30,10 @@ public final class Navigator {
@JSBody(script = "return (\"geolocation\" in navigator);") @JSBody(script = "return (\"geolocation\" in navigator);")
public static native boolean isGeolocationAvailable(); public static native boolean isGeolocationAvailable();
@JSBody(script = "return navigator.language;")
public static native String getLanguage();
@JSBody(script = "return navigator.languages;")
public static native String[] getLanguages();
} }

View File

@ -41,7 +41,6 @@ public abstract class Window implements JSObject, WindowEventTarget, StorageProv
@JSProperty @JSProperty
public abstract int getScreenY(); public abstract int getScreenY();
@JSProperty @JSProperty
public abstract Location getLocation(); public abstract Location getLocation();
@ -184,4 +183,10 @@ public abstract class Window implements JSObject, WindowEventTarget, StorageProv
@JSProperty @JSProperty
public abstract double getDevicePixelRatio(); public abstract double getDevicePixelRatio();
@JSBody(params = "s", script = "return window.atob(s);")
public static native String atob(String s);
@JSBody(params = "s", script = "return window.btoa(s);")
public static native String btoa(String s);
} }

View File

@ -0,0 +1,27 @@
/*
* Copyright 2019 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.jso.core;
import org.teavm.jso.JSIndexer;
import org.teavm.jso.JSObject;
public interface JSMapLike<T extends JSObject> extends JSObject {
@JSIndexer
T get(String key);
@JSIndexer
void set(String key, T object);
}

View File

@ -0,0 +1,30 @@
/*
* Copyright 2019 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.jso.core;
import org.teavm.jso.JSBody;
import org.teavm.jso.JSObject;
public final class JSON {
private JSON() {
}
@JSBody(params = "s", script = "return JSON.parse(s);")
public static native <T extends JSObject> T parse(String s);
@JSBody(params = "o", script = "JSON.stringify(o);")
public static native String stringify(JSObject o);
}

View File

@ -0,0 +1,42 @@
/*
* Copyright 2019 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.jso.core;
import org.teavm.jso.JSBody;
import org.teavm.jso.JSObject;
public final class JSObjects {
private JSObjects() {
}
@JSBody(params = "object", script = "return Object.getOwnPropertyNames(object);")
public static native String[] getOwnPropertyNames(JSObject object);
@JSBody(script = "return Object.create(null);")
public static native <T extends JSObject> T create();
@JSBody(params = "object", script = "return typeof object === 'undefined';")
public static native boolean isUndefined(JSObject object);
@JSBody(params = "object", script = "return typeof object;")
public static native String typeOf(JSObject object);
@JSBody(params = "object", script = "return object.toString();")
public static native String toString(JSObject object);
@JSBody(params = { "object", "name" }, script = "return name in object;")
public static native boolean hasProperty(JSObject object, String name);
}

View File

@ -59,6 +59,12 @@ public interface MouseEvent extends Event {
@JSProperty @JSProperty
EventTarget getRelatedTarget(); EventTarget getRelatedTarget();
@JSProperty
double getMovementX();
@JSProperty
double getMovementY();
void initMouseEvent(String type, boolean canBubble, boolean cancelable, JSObject view, int detail, int screenX, void initMouseEvent(String type, boolean canBubble, boolean cancelable, JSObject view, int detail, int screenX,
int screenY, int clientX, int clientY, boolean ctrlKey, boolean altKey, boolean shiftKey, boolean metaKey, int screenY, int clientX, int clientY, boolean ctrlKey, boolean altKey, boolean shiftKey, boolean metaKey,
short button, EventTarget relatedTarget); short button, EventTarget relatedTarget);

View File

@ -63,4 +63,10 @@ public interface HTMLAnchorElement extends HTMLElement {
@JSProperty @JSProperty
void setText(String value); void setText(String value);
@JSProperty
String getDownload();
@JSProperty
void setDownload(String download);
} }

View File

@ -73,4 +73,19 @@ public interface HTMLDocument extends Document, EventTarget {
void execCommand(String commandName, boolean showDefaultUI, String valueArgument); void execCommand(String commandName, boolean showDefaultUI, String valueArgument);
void execCommand(String commandName); void execCommand(String commandName);
@JSProperty
String getCookie();
@JSProperty
void setCookie(String cookie);
@JSProperty
String getTitle();
@JSProperty
void setTitle(String title);
@JSProperty
HTMLElement getPointerLockElement();
} }

View File

@ -186,4 +186,8 @@ public interface HTMLElement extends Element, ElementCSSInlineStyle, EventTarget
@Override @Override
NodeList<? extends HTMLElement> querySelectorAll(String selectors); NodeList<? extends HTMLElement> querySelectorAll(String selectors);
void requestPointerLock();
void exitPointerLock();
} }

View File

@ -0,0 +1,30 @@
/*
* Copyright 2019 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.jso.websocket;
import org.teavm.jso.JSProperty;
import org.teavm.jso.dom.events.Event;
public interface CloseEvent extends Event {
@JSProperty
int getCode();
@JSProperty
String getReason();
@JSProperty("wasClean")
boolean wasClean();
}

View File

@ -0,0 +1,78 @@
/*
* Copyright 2019 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.jso.websocket;
import org.teavm.jso.JSBody;
import org.teavm.jso.JSObject;
import org.teavm.jso.JSProperty;
import org.teavm.jso.dom.events.Event;
import org.teavm.jso.dom.events.EventListener;
import org.teavm.jso.dom.events.MessageEvent;
public abstract class WebSocket implements JSObject {
@JSProperty("onclose")
public abstract void onClose(EventListener<CloseEvent> eventListener);
@JSProperty("onerror")
public abstract void onError(EventListener<Event> eventListener);
@JSProperty("onmessage")
public abstract void onMessage(EventListener<MessageEvent> eventListener);
@JSProperty("onopen")
public abstract void onOpen(EventListener<MessageEvent> eventListener);
@JSBody(params = "url", script = "return new WebSocket(url);")
public static native WebSocket create(String url);
@JSBody(params = { "url", "protocols" }, script = "return new WebSocket(url, protocols);")
public static native WebSocket create(String url, String protocols);
@JSBody(params = { "url", "protocols" }, script = "return new WebSocket(url, protocols);")
public static native WebSocket create(String url, String[] protocols);
public abstract void close();
public abstract void close(int code);
public abstract void close(int code, String reason);
public abstract void send(String data);
@JSProperty
public abstract String getBinaryType();
@JSProperty
public abstract void setBinaryType(String binaryType);
@JSProperty
public abstract int getBufferedAmount();
@JSProperty
public abstract String getExtensions();
@JSProperty
public abstract String getProtocol();
@JSProperty
public abstract int getReadyState();
@JSProperty
public abstract String getUrl();
@JSBody(script = "return typeof WebSocket !== 'undefined';")
protected static native boolean isSupported();
}