Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix equality comparison and code consistency in web #15621

Merged
merged 3 commits into from
Aug 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion web/src/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export class CachedCallStack implements Disposable {
*/
reset(): void {
this.stackTop = 0;
assert(this.addressToSetTargetValue.length == 0);
assert(this.addressToSetTargetValue.length === 0);
while (this.tempArgs.length != 0) {
(this.tempArgs.pop() as Disposable).dispose();
}
Expand Down
36 changes: 18 additions & 18 deletions web/src/rpc_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export class RPCServer {
this.log(this.inst.runtimeStatsText());
this.inst.dispose();
}
if (this.state == RPCServerState.ReceivePacketHeader) {
if (this.state === RPCServerState.ReceivePacketHeader) {
this.log("Closing the server in clean state");
this.log("Automatic reconnecting..");
new RPCServer(
Expand Down Expand Up @@ -197,20 +197,20 @@ export class RPCServer {
this.currPacketHeader = this.readFromBuffer(SizeOf.I64);
const reader = new ByteStreamReader(this.currPacketHeader);
this.currPacketLength = reader.readU64();
assert(this.pendingBytes == 0);
assert(this.pendingBytes === 0);
this.requestBytes(this.currPacketLength);
this.state = RPCServerState.ReceivePacketBody;
break;
}
case RPCServerState.ReceivePacketBody: {
const body = this.readFromBuffer(this.currPacketLength);
assert(this.pendingBytes == 0);
assert(this.pendingBytes === 0);
assert(this.currPacketHeader !== undefined);
this.onPacketReady(this.currPacketHeader, body);
break;
}
case RPCServerState.WaitForCallback: {
assert(this.pendingBytes == 0);
assert(this.pendingBytes === 0);
break;
}
default: {
Expand All @@ -236,10 +236,10 @@ export class RPCServer {

for (let i = 0; i < nargs; ++i) {
const tcode = tcodes[i];
if (tcode == ArgTypeCode.TVMStr) {
if (tcode === ArgTypeCode.TVMStr) {
const str = Uint8ArrayToString(reader.readByteArray());
args.push(str);
} else if (tcode == ArgTypeCode.TVMBytes) {
} else if (tcode === ArgTypeCode.TVMBytes) {
args.push(reader.readByteArray());
} else {
throw new Error("cannot support type code " + tcode);
Expand All @@ -261,8 +261,8 @@ export class RPCServer {
body: Uint8Array
): void {
// start the server
assert(args[0] == "rpc.WasmSession");
assert(this.pendingBytes == 0);
assert(args[0] === "rpc.WasmSession");
assert(this.pendingBytes === 0);

const asyncInitServer = async (): Promise<void> => {
assert(args[1] instanceof Uint8Array);
Expand Down Expand Up @@ -293,10 +293,10 @@ export class RPCServer {
}

if (this.ndarrayCacheUrl.length != 0) {
if (this.ndarrayCacheDevice == "cpu") {
if (this.ndarrayCacheDevice === "cpu") {
await this.inst.fetchNDArrayCache(this.ndarrayCacheUrl, this.inst.cpu());
} else {
assert(this.ndarrayCacheDevice == "webgpu");
assert(this.ndarrayCacheDevice === "webgpu");
await this.inst.fetchNDArrayCache(this.ndarrayCacheUrl, this.inst.webgpu());
}
}
Expand All @@ -309,7 +309,7 @@ export class RPCServer {
const messageHandler = fcreate(
(cbytes: Uint8Array): runtime.Scalar => {
assert(this.inst !== undefined);
if (this.socket.readyState == 1) {
if (this.socket.readyState === 1) {
// WebSocket will automatically close the socket
// if we burst send data that exceeds its internal buffer
// wait a bit before we send next one.
Expand Down Expand Up @@ -349,10 +349,10 @@ export class RPCServer {
const writeFlag = this.inst.scalar(3, "int32");

this.serverRecvData = (header: Uint8Array, body: Uint8Array): void => {
if (messageHandler(header, writeFlag) == 0) {
if (messageHandler(header, writeFlag) === 0) {
this.socket.close();
}
if (messageHandler(body, writeFlag) == 0) {
if (messageHandler(body, writeFlag) === 0) {
this.socket.close();
}
};
Expand Down Expand Up @@ -396,14 +396,14 @@ export class RPCServer {
private handleInitHeader(): void {
const reader = new ByteStreamReader(this.readFromBuffer(SizeOf.I32 * 2));
const magic = reader.readU32();
if (magic == RPC_MAGIC + 1) {
if (magic === RPC_MAGIC + 1) {
throw new Error("key: " + this.key + " has already been used in proxy");
} else if (magic == RPC_MAGIC + 2) {
} else if (magic === RPC_MAGIC + 2) {
throw new Error("RPCProxy do not have matching client key " + this.key);
}
assert(magic == RPC_MAGIC, this.url + " is not an RPC Proxy");
assert(magic === RPC_MAGIC, this.url + " is not an RPC Proxy");
this.remoteKeyLength = reader.readU32();
assert(this.pendingBytes == 0);
assert(this.pendingBytes === 0);
this.requestBytes(this.remoteKeyLength);
this.state = RPCServerState.InitHeaderKey;
}
Expand All @@ -413,7 +413,7 @@ export class RPCServer {
const remoteKey = Uint8ArrayToString(
this.readFromBuffer(this.remoteKeyLength)
);
assert(this.pendingBytes == 0);
assert(this.pendingBytes === 0);
this.requestBytes(SizeOf.I64);
this.state = RPCServerState.ReceivePacketHeader;
}
Expand Down
Loading