traceUtils.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.serializeClientSideCallMetadata = serializeClientSideCallMetadata;
  6. /**
  7. * Copyright (c) Microsoft Corporation.
  8. *
  9. * Licensed under the Apache License, Version 2.0 (the "License");
  10. * you may not use this file except in compliance with the License.
  11. * You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing, software
  16. * distributed under the License is distributed on an "AS IS" BASIS,
  17. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. * See the License for the specific language governing permissions and
  19. * limitations under the License.
  20. */
  21. function serializeClientSideCallMetadata(metadatas) {
  22. const fileNames = new Map();
  23. const stacks = [];
  24. for (const m of metadatas) {
  25. if (!m.stack || !m.stack.length) continue;
  26. const stack = [];
  27. for (const frame of m.stack) {
  28. let ordinal = fileNames.get(frame.file);
  29. if (typeof ordinal !== 'number') {
  30. ordinal = fileNames.size;
  31. fileNames.set(frame.file, ordinal);
  32. }
  33. const stackFrame = [ordinal, frame.line || 0, frame.column || 0, frame.function || ''];
  34. stack.push(stackFrame);
  35. }
  36. stacks.push([m.id, stack]);
  37. }
  38. return {
  39. files: [...fileNames.keys()],
  40. stacks
  41. };
  42. }