nodejs-loader.mjs 1.9 KB

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