Skip to content

Commit

Permalink
refactor(wasi): prefer explicit encoder/decoder names (denoland/deno#…
Browse files Browse the repository at this point in the history
…8622)

This renames a couple of identifiers from the ambigious name "text" to
the more explicit textEncoder and textDecoder depending on what they are.
  • Loading branch information
caspervonb committed Jan 24, 2021
1 parent 1f53a15 commit e5e1c99
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions 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

0 comments on commit e5e1c99

Please sign in to comment.