test-call.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 < 2) {
  36. logErr('usage: test-call.js SRCDIR PROC.WASM ARG.WASM...');
  37. _exit(1);
  38. }
  39. async function runTest(call) {
  40. try {
  41. let [procFile, ...argFiles] = call;
  42. let [proc] = await Scheme.load_main(procFile);
  43. let argPromises =
  44. argFiles.map(file => proc.reflector.load_extension(file));
  45. let args = [];
  46. for (let p of argPromises) {
  47. let [arg] = await p;
  48. args.push(arg);
  49. }
  50. for (let result of proc.call(...args))
  51. log(repr(result));
  52. } catch (e) {
  53. log(`error: ${e} (${e.stack})`);
  54. _exit(1);
  55. }
  56. }
  57. var srcdir = args[0];
  58. os.chdir(srcdir);
  59. load('js-runtime/reflect.js');
  60. args.shift();
  61. waitFor(runTest(args));