wasmutils.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 i64ToString(val, optHigh = 0) {
  6. let high, low;
  7. if (typeof val === "object") {
  8. high = val.high;
  9. low = val.low;
  10. } else {
  11. low = val;
  12. high = optHigh;
  13. }
  14. const convert = (a, doPad) => {
  15. let s = (a >>> 0).toString(16);
  16. if (doPad) {
  17. s = s.padStart(8, "0");
  18. }
  19. return s;
  20. }
  21. if (high !== 0) {
  22. return `0x${convert(high)}${convert(low, true)}`;
  23. }
  24. return `0x${convert(low)}`;
  25. }
  26. function fixupI64Return(exports, fnNames) {
  27. if (!Array.isArray(fnNames)) {
  28. fnNames = [fnNames];
  29. }
  30. fnNames.forEach(name => {
  31. const oldI64Fn = exports[name];
  32. exports[name] = function(...args) {
  33. const val = oldI64Fn(...args);
  34. return i64ToString(val);
  35. };
  36. })
  37. }