load-wasm-and-print.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. var waitFor;
  2. if (typeof drainJobQueue !== 'undefined') {
  3. waitFor = function waitFor(p) { drainJobQueue(); return p; };
  4. } else {
  5. // JSC and V8 will drain promises before exiting and don't require a
  6. // specific waiter.
  7. waitFor = function waitFor(p) { return p; };
  8. }
  9. var args;
  10. if (typeof scriptArgs !== 'undefined') {
  11. args = scriptArgs;
  12. } else if (typeof arguments !== 'undefined') {
  13. args = arguments;
  14. } else {
  15. // No script arguments available
  16. args = [];
  17. }
  18. var log = print;
  19. var logErr = print;
  20. if (typeof printErr !== 'undefined') {
  21. logErr = printErr;
  22. }
  23. var _exit;
  24. if (typeof quit !== 'undefined') {
  25. _exit = quit.bind(this);
  26. } else if (typeof testRunner !== 'undefined') {
  27. _exit = testRunner.quit.bind(testRunner);
  28. }
  29. // V8 treats multiple arguments as files, unless -- is given, but
  30. // SpiderMonkey doesn't treat -- specially. This is a hack to allow
  31. // for -- on SpiderMonkey.
  32. if (args[0] == '--') {
  33. args.shift();
  34. }
  35. if (args.length != 3) {
  36. logErr('usage: load-wasm-and-print.js SRCDIR BUILDDIR FOO.WASM');
  37. _exit(1);
  38. }
  39. async function runTest(wasmFile) {
  40. try {
  41. for (let obj of await Scheme.load_main(wasmFile))
  42. log(repr(obj));
  43. } catch (e) {
  44. log(`error: ${e}`);
  45. _exit(1);
  46. }
  47. }
  48. var srcdir = args[0];
  49. var builddir = args[1];
  50. os.chdir(builddir);
  51. load(`${srcdir}/js-runtime/reflect.js`);
  52. waitFor(runTest(args[2]));