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

refactor(std/wasi): prefer explicit encoder/decoder names #8622

Merged
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
54 changes: 27 additions & 27 deletions std/wasi/snapshot_preview1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,15 +341,15 @@ export default class Context {
argvBufferOffset: number,
): number => {
const args = this.args;
const text = new TextEncoder();
const textEncoder = new TextEncoder();
const memoryData = new Uint8Array(this.memory.buffer);
const memoryView = new DataView(this.memory.buffer);

for (const arg of args) {
memoryView.setUint32(argvOffset, argvBufferOffset, true);
argvOffset += 4;

const data = text.encode(`${arg}\0`);
const data = textEncoder.encode(`${arg}\0`);
memoryData.set(data, argvBufferOffset);
argvBufferOffset += data.length;
}
Expand All @@ -362,14 +362,14 @@ export default class Context {
argvBufferSizeOffset: number,
): number => {
const args = this.args;
const text = new TextEncoder();
const textEncoder = new TextEncoder();
const memoryView = new DataView(this.memory.buffer);

memoryView.setUint32(argcOffset, args.length, true);
memoryView.setUint32(
argvBufferSizeOffset,
args.reduce(function (acc, arg) {
return acc + text.encode(`${arg}\0`).length;
return acc + textEncoder.encode(`${arg}\0`).length;
}, 0),
true,
);
Expand All @@ -382,15 +382,15 @@ export default class Context {
environBufferOffset: number,
): number => {
const entries = Object.entries(this.env);
const text = new TextEncoder();
const textEncoder = new TextEncoder();
const memoryData = new Uint8Array(this.memory.buffer);
const memoryView = new DataView(this.memory.buffer);

for (const [key, value] of entries) {
memoryView.setUint32(environOffset, environBufferOffset, true);
environOffset += 4;

const data = text.encode(`${key}=${value}\0`);
const data = textEncoder.encode(`${key}=${value}\0`);
memoryData.set(data, environBufferOffset);
environBufferOffset += data.length;
}
Expand All @@ -403,14 +403,14 @@ export default class Context {
environBufferSizeOffset: number,
): number => {
const entries = Object.entries(this.env);
const text = new TextEncoder();
const textEncoder = new TextEncoder();
const memoryView = new DataView(this.memory.buffer);

memoryView.setUint32(environcOffset, entries.length, true);
memoryView.setUint32(
environBufferSizeOffset,
entries.reduce(function (acc, [key, value]) {
return acc + text.encode(`${key}=${value}\0`).length;
return acc + textEncoder.encode(`${key}=${value}\0`).length;
}, 0),
true,
);
Expand Down Expand Up @@ -1021,9 +1021,9 @@ export default class Context {
return ERRNO_INVAL;
}

const text = new TextDecoder();
const textDecoder = new TextDecoder();
const data = new Uint8Array(this.memory.buffer, pathOffset, pathLength);
const path = resolve(entry.path!, text.decode(data));
const path = resolve(entry.path!, textDecoder.decode(data));

Deno.mkdirSync(path);

Expand All @@ -1046,9 +1046,9 @@ export default class Context {
return ERRNO_INVAL;
}

const text = new TextDecoder();
const textDecoder = new TextDecoder();
const data = new Uint8Array(this.memory.buffer, pathOffset, pathLength);
const path = resolve(entry.path!, text.decode(data));
const path = resolve(entry.path!, textDecoder.decode(data));

const memoryView = new DataView(this.memory.buffer);

Expand Down Expand Up @@ -1140,9 +1140,9 @@ export default class Context {
return ERRNO_INVAL;
}

const text = new TextDecoder();
const textDecoder = new TextDecoder();
const data = new Uint8Array(this.memory.buffer, pathOffset, pathLength);
const path = resolve(entry.path!, text.decode(data));
const path = resolve(entry.path!, textDecoder.decode(data));

if ((fstflags & FSTFLAGS_ATIM_NOW) == FSTFLAGS_ATIM_NOW) {
atim = BigInt(Date.now()) * BigInt(1e6);
Expand Down Expand Up @@ -1176,19 +1176,19 @@ export default class Context {
return ERRNO_INVAL;
}

const text = new TextDecoder();
const textDecoder = new TextDecoder();
const oldData = new Uint8Array(
this.memory.buffer,
oldPathOffset,
oldPathLength,
);
const oldPath = resolve(oldEntry.path!, text.decode(oldData));
const oldPath = resolve(oldEntry.path!, textDecoder.decode(oldData));
const newData = new Uint8Array(
this.memory.buffer,
newPathOffset,
newPathLength,
);
const newPath = resolve(newEntry.path!, text.decode(newData));
const newPath = resolve(newEntry.path!, textDecoder.decode(newData));

Deno.linkSync(oldPath, newPath);

Expand Down Expand Up @@ -1392,9 +1392,9 @@ export default class Context {
return ERRNO_INVAL;
}

const text = new TextDecoder();
const textDecoder = new TextDecoder();
const data = new Uint8Array(this.memory.buffer, pathOffset, pathLength);
const path = resolve(entry.path!, text.decode(data));
const path = resolve(entry.path!, textDecoder.decode(data));

if (!Deno.statSync(path).isDirectory) {
return ERRNO_NOTDIR;
Expand Down Expand Up @@ -1423,19 +1423,19 @@ export default class Context {
return ERRNO_INVAL;
}

const text = new TextDecoder();
const textDecoder = new TextDecoder();
const oldData = new Uint8Array(
this.memory.buffer,
oldPathOffset,
oldPathLength,
);
const oldPath = resolve(oldEntry.path!, text.decode(oldData));
const oldPath = resolve(oldEntry.path!, textDecoder.decode(oldData));
const newData = new Uint8Array(
this.memory.buffer,
newPathOffset,
newPathLength,
);
const newPath = resolve(newEntry.path!, text.decode(newData));
const newPath = resolve(newEntry.path!, textDecoder.decode(newData));

Deno.renameSync(oldPath, newPath);

Expand All @@ -1458,19 +1458,19 @@ export default class Context {
return ERRNO_INVAL;
}

const text = new TextDecoder();
const textDecoder = new TextDecoder();
const oldData = new Uint8Array(
this.memory.buffer,
oldPathOffset,
oldPathLength,
);
const oldPath = text.decode(oldData);
const oldPath = textDecoder.decode(oldData);
const newData = new Uint8Array(
this.memory.buffer,
newPathOffset,
newPathLength,
);
const newPath = resolve(entry.path!, text.decode(newData));
const newPath = resolve(entry.path!, textDecoder.decode(newData));

Deno.symlinkSync(oldPath, newPath);

Expand All @@ -1491,9 +1491,9 @@ export default class Context {
return ERRNO_INVAL;
}

const text = new TextDecoder();
const textDecoder = new TextDecoder();
const data = new Uint8Array(this.memory.buffer, pathOffset, pathLength);
const path = resolve(entry.path!, text.decode(data));
const path = resolve(entry.path!, textDecoder.decode(data));

Deno.removeSync(path);

Expand Down