wasm-idle 0.0.10 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,11 +9,12 @@ declare class Clang implements Sandbox {
9
9
  begin: number;
10
10
  elapse: number;
11
11
  uid: number;
12
+ log: boolean;
12
13
  load(path: string, code?: string, log?: boolean): Promise<void>;
13
14
  write(input: string): void;
14
15
  _write(input: string): void;
15
16
  eof(): void;
16
- run(code: string, prepare: boolean): Promise<string>;
17
+ run(code: string, prepare: boolean, log?: boolean): Promise<string>;
17
18
  terminate(): void;
18
19
  clear(): Promise<void>;
19
20
  }
@@ -8,16 +8,20 @@ class Clang {
8
8
  begin = 0;
9
9
  elapse = 0;
10
10
  uid = 0;
11
+ log = true;
11
12
  load(path, code = '', log = true) {
12
13
  return new Promise(async (resolve) => {
14
+ this.log = log;
13
15
  this.internalBuffer = [];
14
16
  if (!this.worker) {
15
17
  this.worker = new (await import('./worker/clang?worker')).default();
16
18
  this.worker.onmessage = () => resolve();
17
19
  this.worker.postMessage({ load: true, path, log, code });
18
20
  }
19
- else
21
+ else {
22
+ this.worker.postMessage({ log });
20
23
  resolve();
24
+ }
21
25
  });
22
26
  }
23
27
  write(input) {
@@ -35,7 +39,7 @@ class Clang {
35
39
  }
36
40
  eof() {
37
41
  }
38
- run(code, prepare) {
42
+ run(code, prepare, log = this.log) {
39
43
  return new Promise(async (resolve, reject) => {
40
44
  const interrupt = new Uint8Array(this.interruptBuffer), _uid = ++this.uid;
41
45
  const handler = (event) => {
@@ -65,7 +69,8 @@ class Clang {
65
69
  prepare,
66
70
  buffer: this.buffer,
67
71
  interrupt: this.interruptBuffer,
68
- context: {}
72
+ context: {},
73
+ log,
69
74
  });
70
75
  });
71
76
  }
@@ -16,8 +16,10 @@ class Python {
16
16
  this.worker.onmessage = () => resolve();
17
17
  this.worker.postMessage({ load: true, path, log, code });
18
18
  }
19
- else
19
+ else {
20
+ this.worker.postMessage({ log });
20
21
  resolve();
22
+ }
21
23
  });
22
24
  }
23
25
  write(input) {
@@ -2,7 +2,7 @@ interface sandbox {
2
2
  constructor: any;
3
3
  eof: () => void;
4
4
  load: (path: string, code?: string, log?: boolean) => Promise<void>;
5
- run: (code: string, prepare: boolean) => Promise<string>;
5
+ run: (code: string, prepare: boolean, log?: boolean) => Promise<string>;
6
6
  terminate: () => void;
7
7
  clear: () => Promise<void>;
8
8
  }
@@ -48,6 +48,7 @@ self.onmessage = async (event) => {
48
48
  }
49
49
  }
50
50
  else if (code) {
51
+ clang.log = log;
51
52
  stdinBufferClang = new Int32Array(buffer);
52
53
  interruptBufferClang = new Uint8Array(interrupt);
53
54
  try {
@@ -58,11 +58,11 @@ export const terminal = {
58
58
  },
59
59
  async prepare(language, code, log = true) {
60
60
  await Promise.all([initSandbox(language).then(() => sandbox.load(path, code, log)), initTerm(false)]);
61
- await runSandbox(sandbox.run(code, true));
61
+ await runSandbox(sandbox.run(code, true, log));
62
62
  },
63
63
  async run(language, code, log = true) {
64
64
  await Promise.all([initSandbox(language).then(() => sandbox.load(path, code, log)), initTerm()]);
65
- await runSandbox(sandbox.run(code, false));
65
+ await runSandbox(sandbox.run(code, false, log));
66
66
  },
67
67
  async destroy() {
68
68
  await wait();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wasm-idle",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "description": "A simple web app to run C++/Python code in the browser",
5
5
  "license": "MIT",
6
6
  "type": "module",