Add some JS API declarations

This commit is contained in:
Alexey Andreev 2017-11-28 22:48:54 +03:00
parent f14990eaeb
commit ae68bc366b
12 changed files with 186 additions and 4 deletions

View File

@ -21,6 +21,6 @@ public final class Navigator {
private Navigator() {
}
@JSBody(script = "return window.navigator.onLine;")
@JSBody(script = "return (window || self).navigator.onLine;")
public static native boolean isOnline();
}

View File

@ -22,9 +22,9 @@ public final class Performance implements JSObject {
private Performance() {
}
@JSBody(script = "return window.performance.now();")
@JSBody(script = "return (window || self).performance.now();")
public static native double now();
@JSBody(script = "return typeof(window.performance) !== 'undefined';")
@JSBody(script = "return typeof((window || self).performance) !== 'undefined';")
public static native boolean isSupported();
}

View File

@ -149,6 +149,8 @@ public abstract class Window implements JSObject, WindowEventTarget, StorageProv
public abstract void stop();
public abstract void postMessage(JSObject message);
public abstract void postMessage(JSObject message, String targetOrigin);
public abstract void postMessage(JSObject message, String targetOrigin, JSArrayReader<JSObject> transfer);
@ -157,7 +159,7 @@ public abstract class Window implements JSObject, WindowEventTarget, StorageProv
postMessage(message, targetOrigin, JSArray.of(transfer));
}
@JSBody(script = "return window;")
@JSBody(script = "return window || self;")
public static native Window current();
@JSBody(params = "uri", script = "return encodeURI(uri);")

View File

@ -0,0 +1,35 @@
/*
* Copyright 2017 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.dom.events;
import org.teavm.jso.JSProperty;
public interface ErrorEvent extends Event {
@JSProperty
String getMessage();
@JSProperty
String getFileName();
@JSProperty("lineno")
int getLineNumber();
@JSProperty("colno")
int getColumnNumber();
@JSProperty
String getError();
}

View File

@ -20,6 +20,7 @@ import org.teavm.jso.JSProperty;
import org.teavm.jso.browser.Window;
import org.teavm.jso.dom.events.EventTarget;
import org.teavm.jso.dom.xml.Document;
import org.teavm.jso.dom.xml.NodeList;
public interface HTMLDocument extends Document, EventTarget {
@JSProperty
@ -53,4 +54,10 @@ public interface HTMLDocument extends Document, EventTarget {
static HTMLDocument current() {
return Window.current().getDocument();
}
@Override
HTMLElement querySelector(String selectors);
@Override
NodeList<? extends HTMLElement> querySelectorAll(String selectors);
}

View File

@ -159,4 +159,10 @@ public interface HTMLElement extends Element, ElementCSSInlineStyle, EventTarget
clear().appendChild(getOwnerDocument().createTextNode(content));
return this;
}
@Override
HTMLElement querySelector(String selectors);
@Override
NodeList<? extends HTMLElement> querySelectorAll(String selectors);
}

View File

@ -54,4 +54,8 @@ public interface Document extends Node {
NodeList<Element> getElementsByTagNameNS(String namespaceURI, String localName);
Element getElementById(String elementId);
Element querySelector(String selectors);
NodeList<? extends Element> querySelectorAll(String selectors);
}

View File

@ -47,4 +47,8 @@ public interface Element extends Node {
boolean hasAttribute(String name);
boolean hasAttributeNS(String namespaceURI, String localName);
Element querySelector(String selectors);
NodeList<? extends Element> querySelectorAll(String selectors);
}

View File

@ -0,0 +1,27 @@
/*
* Copyright 2017 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.workers;
import org.teavm.jso.JSObject;
import org.teavm.jso.JSProperty;
import org.teavm.jso.dom.events.ErrorEvent;
import org.teavm.jso.dom.events.EventListener;
import org.teavm.jso.dom.events.EventTarget;
public interface AbstractWorker extends JSObject, EventTarget {
@JSProperty("onerror")
void onError(EventListener<ErrorEvent> listener);
}

View File

@ -0,0 +1,36 @@
/*
* Copyright 2017 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.workers;
import org.teavm.jso.JSObject;
import org.teavm.jso.JSProperty;
import org.teavm.jso.dom.events.EventListener;
import org.teavm.jso.dom.events.EventTarget;
import org.teavm.jso.dom.events.MessageEvent;
public interface MessagePort extends EventTarget {
void postMessage(JSObject message);
void start();
void close();
@JSProperty("onmessage")
void onMessage(EventListener<MessageEvent> message);
@JSProperty("onmessageerror")
void onMessageError(EventListener<MessageEvent> message);
}

View File

@ -0,0 +1,27 @@
/*
* Copyright 2017 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.workers;
import org.teavm.jso.JSBody;
import org.teavm.jso.JSProperty;
public abstract class SharedWorker implements AbstractWorker {
@JSBody(params = "url", script = "return new SharedWorker(url);")
public static native Worker create(String url);
@JSProperty
public abstract MessagePort getPort();
}

View File

@ -0,0 +1,34 @@
/*
* Copyright 2017 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.workers;
import org.teavm.jso.JSBody;
import org.teavm.jso.JSObject;
import org.teavm.jso.JSProperty;
import org.teavm.jso.dom.events.EventListener;
import org.teavm.jso.dom.events.MessageEvent;
public abstract class Worker implements AbstractWorker {
@JSBody(params = "url", script = "return new Worker(url);")
public static native Worker create(String url);
@JSProperty("onmessage")
public abstract void onMessage(EventListener<MessageEvent> listener);
public abstract void postMessage(JSObject message);
public abstract void terminate();
}