source: trip-planner-front/node_modules/source-map/lib/wasm.js@ e29cc2e

Last change on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.2 KB
Line 
1const readWasm = require("../lib/read-wasm");
2
3/**
4 * Provide the JIT with a nice shape / hidden class.
5 */
6function Mapping() {
7 this.generatedLine = 0;
8 this.generatedColumn = 0;
9 this.lastGeneratedColumn = null;
10 this.source = null;
11 this.originalLine = null;
12 this.originalColumn = null;
13 this.name = null;
14}
15
16let cachedWasm = null;
17
18module.exports = function wasm() {
19 if (cachedWasm) {
20 return cachedWasm;
21 }
22
23 const callbackStack = [];
24
25 cachedWasm = readWasm().then(buffer => {
26 return WebAssembly.instantiate(buffer, {
27 env: {
28 mapping_callback(
29 generatedLine,
30 generatedColumn,
31
32 hasLastGeneratedColumn,
33 lastGeneratedColumn,
34
35 hasOriginal,
36 source,
37 originalLine,
38 originalColumn,
39
40 hasName,
41 name
42 ) {
43 const mapping = new Mapping();
44 // JS uses 1-based line numbers, wasm uses 0-based.
45 mapping.generatedLine = generatedLine + 1;
46 mapping.generatedColumn = generatedColumn;
47
48 if (hasLastGeneratedColumn) {
49 // JS uses inclusive last generated column, wasm uses exclusive.
50 mapping.lastGeneratedColumn = lastGeneratedColumn - 1;
51 }
52
53 if (hasOriginal) {
54 mapping.source = source;
55 // JS uses 1-based line numbers, wasm uses 0-based.
56 mapping.originalLine = originalLine + 1;
57 mapping.originalColumn = originalColumn;
58
59 if (hasName) {
60 mapping.name = name;
61 }
62 }
63
64 callbackStack[callbackStack.length - 1](mapping);
65 },
66
67 start_all_generated_locations_for() { console.time("all_generated_locations_for"); },
68 end_all_generated_locations_for() { console.timeEnd("all_generated_locations_for"); },
69
70 start_compute_column_spans() { console.time("compute_column_spans"); },
71 end_compute_column_spans() { console.timeEnd("compute_column_spans"); },
72
73 start_generated_location_for() { console.time("generated_location_for"); },
74 end_generated_location_for() { console.timeEnd("generated_location_for"); },
75
76 start_original_location_for() { console.time("original_location_for"); },
77 end_original_location_for() { console.timeEnd("original_location_for"); },
78
79 start_parse_mappings() { console.time("parse_mappings"); },
80 end_parse_mappings() { console.timeEnd("parse_mappings"); },
81
82 start_sort_by_generated_location() { console.time("sort_by_generated_location"); },
83 end_sort_by_generated_location() { console.timeEnd("sort_by_generated_location"); },
84
85 start_sort_by_original_location() { console.time("sort_by_original_location"); },
86 end_sort_by_original_location() { console.timeEnd("sort_by_original_location"); },
87 }
88 });
89 }).then(Wasm => {
90 return {
91 exports: Wasm.instance.exports,
92 withMappingCallback: (mappingCallback, f) => {
93 callbackStack.push(mappingCallback);
94 try {
95 f();
96 } finally {
97 callbackStack.pop();
98 }
99 }
100 };
101 }).then(null, e => {
102 cachedWasm = null;
103 throw e;
104 });
105
106 return cachedWasm;
107};
Note: See TracBrowser for help on using the repository browser.