await-call.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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: await-call.js REFLECT_JS_DIR REFLECT_WASM_DIR PROC.WASM ARG.WASM...');
  37. _exit(1);
  38. }
  39. async function runTest(call, opts) {
  40. try {
  41. let [procFile, ...argFiles] = call;
  42. let [proc] = await Scheme.load_main(procFile, opts);
  43. let argPromises =
  44. argFiles.map(file => proc.reflector.load_extension(file, opts));
  45. let args = [];
  46. for (let p of argPromises) {
  47. let [arg] = await p;
  48. args.push(arg);
  49. }
  50. log(repr(await proc.call_async(...args)));
  51. } catch (e) {
  52. log(`error: ${e} (${e.stack})`);
  53. _exit(1);
  54. }
  55. }
  56. var [reflect_js_dir, reflect_wasm_dir, ...test_call] = args;
  57. load(`${reflect_js_dir}/reflect.js`);
  58. waitFor(runTest(test_call, {reflect_wasm_dir}));