test-call.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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: test-call.js SRCDIR BUILDDIR 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. var builddir = args[1];
  59. os.chdir(builddir);
  60. load(`${srcdir}/js-runtime/reflect.js`);
  61. args.shift();
  62. args.shift();
  63. waitFor(runTest(args));