console_preamble.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * PANDA 3D SOFTWARE
  3. * Copyright (c) Carnegie Mellon University. All rights reserved.
  4. *
  5. * All use of this software is subject to the terms of the revised BSD
  6. * license. You should have received a copy of this license along
  7. * with this source code in a file named "LICENSE."
  8. *
  9. * @file console_preamble.js
  10. * @author rdb
  11. * @date 2025-02-03
  12. */
  13. if (ENVIRONMENT_IS_NODE) {
  14. Module["preInit"] = Module["preInit"] || [];
  15. Module["preInit"].push(function() {
  16. if (typeof process === "object" && typeof process.env === "object") {
  17. // These are made up by emscripten if we don't set them to undefined
  18. ENV['USER'] = undefined;
  19. ENV['LOGNAME'] = undefined;
  20. ENV['PATH'] = undefined;
  21. ENV['PWD'] = undefined;
  22. ENV['HOME'] = undefined;
  23. ENV['LANG'] = undefined;
  24. ENV['_'] = undefined;
  25. for (var variable in process.env) {
  26. ENV[variable] = process.env[variable];
  27. }
  28. }
  29. addOnPreMain(function preloadNodeEnv() {
  30. var sp = stackSave();
  31. var set_binary_name = wasmExports["_set_binary_name"];
  32. if (set_binary_name && typeof __filename === "string") {
  33. set_binary_name(stringToUTF8OnStack(__filename));
  34. }
  35. var set_env_var = wasmExports["_set_env_var"];
  36. if (set_env_var) {
  37. for (var variable in ENV) {
  38. var value = ENV[variable];
  39. if (value !== undefined) {
  40. set_env_var(stringToUTF8OnStack(variable), stringToUTF8OnStack(value));
  41. }
  42. }
  43. }
  44. stackRestore(sp);
  45. });
  46. });
  47. }