Skip to content

Commit

Permalink
tab to space
Browse files Browse the repository at this point in the history
  • Loading branch information
oligamiq committed Sep 23, 2024
1 parent f773862 commit 80f8d74
Show file tree
Hide file tree
Showing 18 changed files with 5,172 additions and 5,176 deletions.
2,276 changes: 1,138 additions & 1,138 deletions src/wasi_farm/animals.ts

Large diffs are not rendered by default.

176 changes: 88 additions & 88 deletions src/wasi_farm/farm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,106 +6,106 @@ import type { WASIFarmRefObject } from "./ref.js";
import { WASIFarmParkUseArrayBuffer } from "./shared_array_buffer/index.js";

export class WASIFarm {
private fds: Array<Fd>;
private park: WASIFarmPark;
private fds: Array<Fd>;
private park: WASIFarmPark;

private can_array_buffer;
private can_array_buffer;

constructor(
stdin?: Fd,
stdout?: Fd,
stderr?: Fd,
fds: Array<Fd> = [],
options: Options & {
allocator_size?: number;
} = {},
) {
debug.enable(options.debug);
constructor(
stdin?: Fd,
stdout?: Fd,
stderr?: Fd,
fds: Array<Fd> = [],
options: Options & {
allocator_size?: number;
} = {},
) {
debug.enable(options.debug);

const new_fds = [];
let stdin_ = undefined;
let stdout_ = undefined;
let stderr_ = undefined;
if (stdin) {
new_fds.push(stdin);
stdin_ = new_fds.length - 1;
}
if (stdout) {
new_fds.push(stdout);
stdout_ = new_fds.length - 1;
}
if (stderr) {
new_fds.push(stderr);
stderr_ = new_fds.length - 1;
}
new_fds.push(...fds);
const new_fds = [];
let stdin_ = undefined;
let stdout_ = undefined;
let stderr_ = undefined;
if (stdin) {
new_fds.push(stdin);
stdin_ = new_fds.length - 1;
}
if (stdout) {
new_fds.push(stdout);
stdout_ = new_fds.length - 1;
}
if (stderr) {
new_fds.push(stderr);
stderr_ = new_fds.length - 1;
}
new_fds.push(...fds);

const default_allow_fds = [];
for (let i = 0; i < new_fds.length; i++) {
default_allow_fds.push(i);
}
const default_allow_fds = [];
for (let i = 0; i < new_fds.length; i++) {
default_allow_fds.push(i);
}

this.fds = new_fds;
this.fds = new_fds;

// WebAssembly.Memory can be used to create a SharedArrayBuffer, but it cannot be transferred by postMessage.
// Uncaught (in promise) DataCloneError:
// Failed to execute 'postMessage' on 'Worker':
// SharedArrayBuffer transfer requires self.crossOriginIsolated.
try {
new SharedArrayBuffer(4);
this.can_array_buffer = true;
} catch (e) {
this.can_array_buffer = false;
console.warn("SharedArrayBuffer is not supported:", e);
// WebAssembly.Memory can be used to create a SharedArrayBuffer, but it cannot be transferred by postMessage.
// Uncaught (in promise) DataCloneError:
// Failed to execute 'postMessage' on 'Worker':
// SharedArrayBuffer transfer requires self.crossOriginIsolated.
try {
new SharedArrayBuffer(4);
this.can_array_buffer = true;
} catch (e) {
this.can_array_buffer = false;
console.warn("SharedArrayBuffer is not supported:", e);

if (!crossOriginIsolated) {
console.warn(
"SharedArrayBuffer is not supported because crossOriginIsolated is not enabled.",
);
}
}
if (!crossOriginIsolated) {
console.warn(
"SharedArrayBuffer is not supported because crossOriginIsolated is not enabled.",
);
}
}

if (this.can_array_buffer) {
this.park = new WASIFarmParkUseArrayBuffer(
this.fds_ref(),
stdin_,
stdout_,
stderr_,
default_allow_fds,
options?.allocator_size,
);
} else {
throw new Error("Non SharedArrayBuffer is not supported yet");
}
if (this.can_array_buffer) {
this.park = new WASIFarmParkUseArrayBuffer(
this.fds_ref(),
stdin_,
stdout_,
stderr_,
default_allow_fds,
options?.allocator_size,
);
} else {
throw new Error("Non SharedArrayBuffer is not supported yet");
}

this.park.listen();
}
this.park.listen();
}

private fds_ref(): Array<Fd> {
const fds = new Proxy([] as Array<Fd>, {
get: (_, prop) => {
// console.log("fds", prop);
private fds_ref(): Array<Fd> {
const fds = new Proxy([] as Array<Fd>, {
get: (_, prop) => {
// console.log("fds", prop);

if (prop === "push") {
return (fd: Fd) => {
const len = this.fds.push(fd);
return len;
};
}
return this.fds[prop];
},
if (prop === "push") {
return (fd: Fd) => {
const len = this.fds.push(fd);
return len;
};
}
return this.fds[prop];
},

set: (_, prop, value) => {
// console.log("fds", prop, value);
this.fds[prop] = value;
return true;
},
});
set: (_, prop, value) => {
// console.log("fds", prop, value);
this.fds[prop] = value;
return true;
},
});

return fds;
}
return fds;
}

get_ref(): WASIFarmRefObject {
return this.park.get_ref();
}
get_ref(): WASIFarmRefObject {
return this.park.get_ref();
}
}
Loading

0 comments on commit 80f8d74

Please sign in to comment.