mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2026-09-21 00:28:50 +00:00
Update TeaVM version
We no longer require any patches against TeaVM. Still shipping our own for now, until 0.14 is stable. <3 konsoletyper
This commit is contained in:
@@ -72,7 +72,7 @@ modDevGradle = "2.0.124"
|
||||
nullAway = "0.12.11"
|
||||
shadow = "9.2.2"
|
||||
spotless = "8.0.0"
|
||||
teavm = "0.13.0-SQUID.2"
|
||||
teavm = "0.14.0-SQUID.1"
|
||||
vanillaExtract = "0.3.1"
|
||||
versionCatalogUpdate = "1.0.1"
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.teavm.jso.JSObject;
|
||||
import org.teavm.jso.core.JSString;
|
||||
import org.teavm.jso.typedarrays.ArrayBuffer;
|
||||
import org.teavm.jso.typedarrays.Int8Array;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
@@ -161,7 +162,7 @@ class EmulatedComputer implements ComputerEnvironment, ComputerHandle {
|
||||
public void transferFiles(FileContents[] files) {
|
||||
computer.queueEvent(TransferredFiles.EVENT, new Object[]{ new TransferredFiles(
|
||||
Arrays.stream(files)
|
||||
.map(x -> new TransferredFile(x.getName(), new ArrayByteChannel(bytesOfBuffer(x.getContents()))))
|
||||
.map(x -> new TransferredFile(x.getName(), new ArrayByteChannel(new Int8Array(x.getContents()).copyToJavaArray())))
|
||||
.toList()
|
||||
) });
|
||||
}
|
||||
@@ -186,8 +187,8 @@ class EmulatedComputer implements ComputerEnvironment, ComputerHandle {
|
||||
@Override
|
||||
public void addFile(String path, JSObject contents) {
|
||||
byte[] bytes;
|
||||
if (JavascriptConv.isArrayBuffer(contents)) {
|
||||
bytes = bytesOfBuffer((ArrayBuffer) contents);
|
||||
if (contents instanceof ArrayBuffer buffer) {
|
||||
bytes = new Int8Array(buffer).copyToJavaArray();
|
||||
} else {
|
||||
var string = (JSString) contents;
|
||||
bytes = string.stringValue().getBytes(StandardCharsets.UTF_8);
|
||||
@@ -195,9 +196,4 @@ class EmulatedComputer implements ComputerEnvironment, ComputerHandle {
|
||||
|
||||
mount.addFile(path, bytes);
|
||||
}
|
||||
|
||||
private byte[] bytesOfBuffer(ArrayBuffer buffer) {
|
||||
var oldBytes = JavascriptConv.asByteArray(buffer);
|
||||
return Arrays.copyOf(oldBytes, oldBytes.length);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,17 +6,10 @@ package cc.tweaked.web.js;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
import org.teavm.jso.JSBody;
|
||||
import org.teavm.jso.JSByRef;
|
||||
import org.teavm.jso.JSObject;
|
||||
import org.teavm.jso.core.JSBoolean;
|
||||
import org.teavm.jso.core.JSNumber;
|
||||
import org.teavm.jso.core.JSObjects;
|
||||
import org.teavm.jso.core.JSString;
|
||||
import org.teavm.jso.typedarrays.ArrayBuffer;
|
||||
import org.teavm.jso.typedarrays.Int8Array;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* Utility methods for converting between Java and Javascript representations.
|
||||
@@ -44,46 +37,9 @@ public class JavascriptConv {
|
||||
*/
|
||||
public static @Nullable Object toJava(@Nullable JSObject value) {
|
||||
if (value == null) return null;
|
||||
return switch (JSObjects.typeOf(value)) {
|
||||
case "string" -> ((JSString) value).stringValue();
|
||||
case "number" -> ((JSNumber) value).doubleValue();
|
||||
case "boolean" -> ((JSBoolean) value).booleanValue();
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an arbitrary object is a {@link ArrayBuffer}.
|
||||
*
|
||||
* @param object The object ot check
|
||||
* @return Whether this is an {@link ArrayBuffer}.
|
||||
*/
|
||||
@JSBody(params = "data", script = "return data instanceof ArrayBuffer;")
|
||||
public static native boolean isArrayBuffer(JSObject object);
|
||||
|
||||
/**
|
||||
* Wrap a JS {@link Int8Array} into a {@code byte[]}.
|
||||
*
|
||||
* @param view The array to wrap.
|
||||
* @return The wrapped array.
|
||||
*/
|
||||
@JSByRef
|
||||
@JSBody(params = "x", script = "return x;")
|
||||
public static native byte[] asByteArray(Int8Array view);
|
||||
|
||||
/**
|
||||
* Wrap a JS {@link ArrayBuffer} into a {@code byte[]}.
|
||||
*
|
||||
* @param view The array to wrap.
|
||||
* @return The wrapped array.
|
||||
*/
|
||||
public static byte[] asByteArray(ArrayBuffer view) {
|
||||
return asByteArray(new Int8Array(view));
|
||||
}
|
||||
|
||||
public static Int8Array toArray(ByteBuffer buffer) {
|
||||
var array = new Int8Array(buffer.remaining());
|
||||
for (var i = 0; i < array.getLength(); i++) array.set(i, buffer.get(i));
|
||||
return array;
|
||||
if (value instanceof JSString v) return v.stringValue();
|
||||
if (value instanceof JSNumber v) return v.doubleValue();
|
||||
if (value instanceof JSBoolean v) return v.booleanValue();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -5,7 +5,6 @@
|
||||
package dan200.computercraft.core.apis.http.request;
|
||||
|
||||
import cc.tweaked.web.Main;
|
||||
import cc.tweaked.web.js.JavascriptConv;
|
||||
import dan200.computercraft.core.Logging;
|
||||
import dan200.computercraft.core.apis.IAPIEnvironment;
|
||||
import dan200.computercraft.core.apis.handles.ArrayByteChannel;
|
||||
@@ -21,6 +20,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.teavm.jso.ajax.XMLHttpRequest;
|
||||
import org.teavm.jso.typedarrays.ArrayBuffer;
|
||||
import org.teavm.jso.typedarrays.Int8Array;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
@@ -102,7 +102,7 @@ public class THttpRequest extends Resource<THttpRequest> {
|
||||
request.setRequestHeader(header.getKey(), header.getValue());
|
||||
}
|
||||
request.setRequestHeader("X-CC-Redirect", followRedirects ? "true" : "false");
|
||||
request.send(postBuffer == null ? null : JavascriptConv.toArray(postBuffer));
|
||||
request.send(postBuffer == null ? null : Int8Array.fromJavaBuffer(postBuffer));
|
||||
checkClosed();
|
||||
} catch (Exception e) {
|
||||
failure("Could not connect");
|
||||
@@ -118,7 +118,7 @@ public class THttpRequest extends Resource<THttpRequest> {
|
||||
}
|
||||
|
||||
var buffer = (ArrayBuffer) request.getResponse();
|
||||
SeekableByteChannel contents = new ArrayByteChannel(JavascriptConv.asByteArray(buffer));
|
||||
SeekableByteChannel contents = new ArrayByteChannel(new Int8Array(buffer).copyToJavaArray());
|
||||
var reader = new ReadHandle(contents, binary);
|
||||
|
||||
Map<String, String> responseHeaders = new HashMap<>();
|
||||
|
||||
+4
-6
@@ -5,7 +5,6 @@
|
||||
package dan200.computercraft.core.apis.http.websocket;
|
||||
|
||||
import cc.tweaked.web.js.Console;
|
||||
import cc.tweaked.web.js.JavascriptConv;
|
||||
import com.google.common.base.Strings;
|
||||
import dan200.computercraft.core.apis.IAPIEnvironment;
|
||||
import dan200.computercraft.core.apis.http.Resource;
|
||||
@@ -14,6 +13,7 @@ import dan200.computercraft.core.apis.http.options.Action;
|
||||
import dan200.computercraft.core.apis.http.options.Options;
|
||||
import io.netty.handler.codec.http.HttpHeaders;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
import org.teavm.jso.typedarrays.ArrayBuffer;
|
||||
import org.teavm.jso.typedarrays.Int8Array;
|
||||
import org.teavm.jso.websocket.WebSocket;
|
||||
|
||||
@@ -49,10 +49,8 @@ public class TWebsocket extends Resource<TWebsocket> implements WebsocketClient
|
||||
});
|
||||
client.onMessage(e -> {
|
||||
if (isClosed()) return;
|
||||
if (JavascriptConv.isArrayBuffer(e.getData())) {
|
||||
var array = new Int8Array(e.getDataAsArray());
|
||||
var contents = new byte[array.getLength()];
|
||||
for (var i = 0; i < contents.length; i++) contents[i] = array.get(i);
|
||||
if (e.getData() instanceof ArrayBuffer buffer) {
|
||||
var contents = new Int8Array(buffer).copyToJavaArray();
|
||||
environment.queueEvent("websocket_message", address, contents, true);
|
||||
} else {
|
||||
environment.queueEvent("websocket_message", address, e.getDataAsString(), false);
|
||||
@@ -70,7 +68,7 @@ public class TWebsocket extends Resource<TWebsocket> implements WebsocketClient
|
||||
@Override
|
||||
public void sendBinary(ByteBuffer message) {
|
||||
if (websocket == null) return;
|
||||
websocket.send(JavascriptConv.toArray(message));
|
||||
websocket.send(Int8Array.fromJavaBuffer(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user