jso apis: improve support of XMLHttpRequest

This commit is contained in:
Ivan Hetman 2023-02-18 10:14:18 +02:00 committed by GitHub
parent 27713b78f8
commit a4b2199142
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 59 additions and 2 deletions

View File

@ -0,0 +1,30 @@
/*
* Copyright 2023 ihromant.
*
* 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.ajax;
import org.teavm.jso.JSProperty;
import org.teavm.jso.dom.events.Event;
public interface ProgressEvent extends Event {
@JSProperty
boolean isLengthComputable();
@JSProperty
int getLoaded();
@JSProperty
int getTotal();
}

View File

@ -18,9 +18,12 @@ package org.teavm.jso.ajax;
import org.teavm.jso.JSBody; import org.teavm.jso.JSBody;
import org.teavm.jso.JSObject; import org.teavm.jso.JSObject;
import org.teavm.jso.JSProperty; 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.EventTarget;
import org.teavm.jso.dom.xml.Document; import org.teavm.jso.dom.xml.Document;
public abstract class XMLHttpRequest implements JSObject { public abstract class XMLHttpRequest implements JSObject, EventTarget {
public static final int UNSET = 0; public static final int UNSET = 0;
public static final int OPENED = 1; public static final int OPENED = 1;
@ -54,6 +57,30 @@ public abstract class XMLHttpRequest implements JSObject {
@JSProperty("onreadystatechange") @JSProperty("onreadystatechange")
public abstract void setOnReadyStateChange(ReadyStateChangeHandler handler); public abstract void setOnReadyStateChange(ReadyStateChangeHandler handler);
@JSProperty("onreadystatechange")
public abstract void setOnReadyStateChange(EventListener<Event> handler);
@JSProperty("onabort")
public abstract void onAbort(EventListener<ProgressEvent> eventListener);
@JSProperty("onerror")
public abstract void onError(EventListener<ProgressEvent> eventListener);
@JSProperty("onload")
public abstract void onLoad(EventListener<ProgressEvent> eventListener);
@JSProperty("onloadstart")
public abstract void onLoadStart(EventListener<ProgressEvent> eventListener);
@JSProperty("onloadend")
public abstract void onLoadEnd(EventListener<ProgressEvent> eventListener);
@JSProperty("onprogress")
public abstract void onProgress(EventListener<ProgressEvent> eventListener);
@JSProperty("ontimeout")
public abstract void onTimeout(EventListener<ProgressEvent> eventListener);
public final void onComplete(Runnable runnable) { public final void onComplete(Runnable runnable) {
setOnReadyStateChange(() -> { setOnReadyStateChange(() -> {
if (getReadyState() == DONE) { if (getReadyState() == DONE) {

View File

@ -35,7 +35,7 @@ public abstract class WebSocket implements JSObject {
public abstract void onMessage(EventListener<MessageEvent> eventListener); public abstract void onMessage(EventListener<MessageEvent> eventListener);
@JSProperty("onopen") @JSProperty("onopen")
public abstract void onOpen(EventListener<MessageEvent> eventListener); public abstract void onOpen(EventListener<Event> eventListener);
@JSBody(params = "url", script = "return new WebSocket(url);") @JSBody(params = "url", script = "return new WebSocket(url);")
public static native WebSocket create(String url); public static native WebSocket create(String url);