load.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // -*- js-indent-level: 4 -*-
  2. var waitFor;
  3. if (typeof drainJobQueue !== 'undefined') {
  4. waitFor = function waitFor(p) { drainJobQueue(); return p; };
  5. } else {
  6. // JSC and V8 will drain promises before exiting and don't require a
  7. // specific waiter.
  8. waitFor = function waitFor(p) { return p; };
  9. }
  10. var args;
  11. if (typeof process !== 'undefined') {
  12. args = process.argv.slice(3);
  13. } else if (typeof scriptArgs !== 'undefined') {
  14. args = scriptArgs;
  15. } else if (typeof arguments !== 'undefined') {
  16. args = arguments;
  17. } else {
  18. // No script arguments available
  19. args = [];
  20. }
  21. var log;
  22. var logErr;
  23. if (typeof print !== 'undefined') {
  24. log = print;
  25. } else if (typeof console !== 'undefined') {
  26. log = console.log.bind(console);
  27. }
  28. if (typeof printErr !== 'undefined') {
  29. logErr = printErr;
  30. } else {
  31. logErr = log;
  32. }
  33. var _exit;
  34. if (typeof quit !== 'undefined') {
  35. _exit = quit.bind(this);
  36. } else if (typeof testRunner !== 'undefined') {
  37. _exit = testRunner.quit.bind(testRunner);
  38. } else if (typeof process !== 'undefined') {
  39. _exit = process.exit.bind(process);
  40. }
  41. var _load;
  42. if (typeof load !== 'undefined') {
  43. _load = load;
  44. } else if (typeof require !== 'undefined') {
  45. _load = require;
  46. }
  47. // V8 treats multiple arguments as files, unless -- is given, but
  48. // SpiderMonkey doesn't treat -- specially. This is a hack to allow
  49. // for -- on SpiderMonkey.
  50. if (args[0] == '--') {
  51. args.shift();
  52. }
  53. if (args.length != 3) {
  54. logErr('usage: load.js REFLECT_JS_DIR REFLECT_WASM_DIR FOO.WASM');
  55. _exit(1);
  56. }
  57. async function runTest(wasmFile, opts) {
  58. try {
  59. for (let obj of await Scheme.load_main(wasmFile, opts))
  60. log(repr(obj));
  61. } catch (e) {
  62. log(`error: ${e}`);
  63. _exit(1);
  64. }
  65. }
  66. var [reflect_js_dir, reflect_wasm_dir, test_wasm] = args;
  67. var hoot = _load(`${reflect_js_dir}/reflect.js`);
  68. if (typeof hoot !== 'undefined') {
  69. Scheme = hoot.Scheme;
  70. repr = hoot.repr;
  71. }
  72. waitFor(runTest(test_wasm, {reflect_wasm_dir}));