wasmcctx.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. function attach() {
  6. return new Promise(r => WScript.Attach(() => {
  7. r();
  8. }));
  9. }
  10. function detach() {
  11. return new Promise(r => WScript.Detach(() => {
  12. r();
  13. }));
  14. }
  15. const ccx = WScript.LoadScriptFile("wasmcctxmodule.js", "samethread");
  16. let exports;
  17. function createModule() {
  18. exports = ccx.createModule();
  19. const {mem, table, lastModule, lastInstance} = ccx;
  20. /**bp:locals();bp:evaluate('String(lastInstance)');bp:evaluate('String(lastModule)');bp:evaluate('String(mem)');bp:evaluate('String(table)')**/
  21. }
  22. let id = 0;
  23. function runTest(fn) {
  24. try {
  25. //debugger;
  26. fn(++id|0);
  27. } catch (e) {
  28. if (!(e instanceof (ccx.MyExceptionExport))) {
  29. print(`Unexpected error: ${e.stack}`);
  30. }
  31. } finally {
  32. if (ccx.testValue !== id) {
  33. print(`Expected ${ccx.testValue} to be ${id}`);
  34. }
  35. }
  36. }
  37. function runTests({a, c}) {
  38. runTest(a);
  39. runTest(c);
  40. }
  41. function run() {
  42. runTests(exports);
  43. }
  44. createModule();
  45. run();
  46. attach()
  47. .then(createModule)
  48. .then(detach)
  49. .then(run)
  50. .then(attach)
  51. .then(createModule)
  52. .then(run)
  53. .then(detach)
  54. .then(() => print("PASSED"), print);