-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
nodejs-loader.mjs
96 lines (83 loc) · 1.95 KB
/
nodejs-loader.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import vm from "node:vm";
import url from "node:url";
import fs from "node:fs";
import path from "node:path";
import crypto from "node:crypto";
import perf_hooks from "node:perf_hooks";
const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
let files = [
"src/const.js",
"src/config.js",
"src/log.js",
"src/cpu.js",
"src/debug.js",
"src/io.js",
"src/main.js",
"src/lib.js",
"src/buffer.js",
"src/ide.js",
"src/pci.js",
"src/floppy.js",
"src/memory.js",
"src/dma.js",
"src/pit.js",
"src/vga.js",
"src/ps2.js",
"src/rtc.js",
"src/uart.js",
"src/acpi.js",
"src/apic.js",
"src/ioapic.js",
"src/state.js",
"src/ne2k.js",
"src/sb16.js",
"src/virtio.js",
"src/virtio_console.js",
"src/virtio_net.js",
//"src/virtio_balloon.js",
"src/bus.js",
"src/debug.js",
"src/elf.js",
"src/kernel.js",
"lib/9p.js",
"lib/filesystem.js",
"lib/jor1k.js",
"lib/marshall.js",
"src/browser/screen.js",
"src/browser/keyboard.js",
"src/browser/mouse.js",
"src/browser/speaker.js",
"src/browser/serial.js",
"src/browser/network.js",
"src/browser/fake_network.js",
"src/browser/fetch_network.js",
"src/browser/starter.js",
"src/browser/worker_bus.js",
"src/browser/dummy_screen.js",
"src/browser/print_stats.js",
"src/browser/filestorage.js"
];
let globals = Object.create(globalThis);
let v86 = {};
let ctx = vm.createContext(globals);
globals.DEBUG = false;
globals.module = {exports:v86};
Object.defineProperty(globals, "crypto", {value: crypto});
globals.require = (what) => {
return ({
perf_hooks,
fs
})[what];
};
for( let f of files ) {
vm.runInContext(fs.readFileSync(path.join(__dirname, f), "utf8"), ctx, {
filename: f
});
}
export let {
V86,
CPU,
FetchNetworkAdapter,
MemoryFileStorage,
ServerFileStorageWrapper,
} = globals;