-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwasm_rustfmt.js
More file actions
155 lines (126 loc) · 4.59 KB
/
Copy pathwasm_rustfmt.js
File metadata and controls
155 lines (126 loc) · 4.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
(function() {
var wasm;
const __exports = {};
const __wbg_error_cc95a3d302735ca3_target = console.error;
let cachedDecoder = new TextDecoder('utf-8');
let cachegetUint8Memory = null;
function getUint8Memory() {
if (cachegetUint8Memory === null || cachegetUint8Memory.buffer !== wasm.memory.buffer) {
cachegetUint8Memory = new Uint8Array(wasm.memory.buffer);
}
return cachegetUint8Memory;
}
function getStringFromWasm(ptr, len) {
return cachedDecoder.decode(getUint8Memory().subarray(ptr, ptr + len));
}
__exports.__wbg_error_cc95a3d302735ca3 = function(arg0, arg1) {
let varg0 = getStringFromWasm(arg0, arg1);
varg0 = varg0.slice();
wasm.__wbindgen_free(arg0, arg1 * 1);
__wbg_error_cc95a3d302735ca3_target(varg0);
};
let cachedEncoder = new TextEncoder('utf-8');
function passStringToWasm(arg) {
const buf = cachedEncoder.encode(arg);
const ptr = wasm.__wbindgen_malloc(buf.length);
getUint8Memory().set(buf, ptr);
return [ptr, buf.length];
}
/**
* @param {string} arg0
* @returns {RustfmtResult}
*/
__exports.rustfmt = function(arg0) {
const [ptr0, len0] = passStringToWasm(arg0);
try {
return RustfmtResult.__construct(wasm.rustfmt(ptr0, len0));
} finally {
wasm.__wbindgen_free(ptr0, len0 * 1);
}
};
let cachedGlobalArgumentPtr = null;
function globalArgumentPtr() {
if (cachedGlobalArgumentPtr === null) {
cachedGlobalArgumentPtr = wasm.__wbindgen_global_argument_ptr();
}
return cachedGlobalArgumentPtr;
}
let cachegetUint32Memory = null;
function getUint32Memory() {
if (cachegetUint32Memory === null || cachegetUint32Memory.buffer !== wasm.memory.buffer) {
cachegetUint32Memory = new Uint32Array(wasm.memory.buffer);
}
return cachegetUint32Memory;
}
function freeRustfmtResult(ptr) {
wasm.__wbg_rustfmtresult_free(ptr);
}
/**
*/
class RustfmtResult {
static __construct(ptr) {
return new RustfmtResult(ptr);
}
constructor(ptr) {
this.ptr = ptr;
}
free() {
const ptr = this.ptr;
this.ptr = 0;
freeRustfmtResult(ptr);
}
/**
* @returns {string}
*/
code() {
if (this.ptr === 0) {
throw new Error('Attempt to use a moved value');
}
const retptr = globalArgumentPtr();
wasm.rustfmtresult_code(retptr, this.ptr);
const mem = getUint32Memory();
const rustptr = mem[retptr / 4];
const rustlen = mem[retptr / 4 + 1];
const realRet = getStringFromWasm(rustptr, rustlen).slice();
wasm.__wbindgen_free(rustptr, rustlen * 1);
return realRet;
}
/**
* @returns {string}
*/
error() {
if (this.ptr === 0) {
throw new Error('Attempt to use a moved value');
}
const retptr = globalArgumentPtr();
wasm.rustfmtresult_error(retptr, this.ptr);
const mem = getUint32Memory();
const rustptr = mem[retptr / 4];
const rustlen = mem[retptr / 4 + 1];
if (rustptr === 0) return;
const realRet = getStringFromWasm(rustptr, rustlen).slice();
wasm.__wbindgen_free(rustptr, rustlen * 1);
return realRet;
}
}
__exports.RustfmtResult = RustfmtResult;
__exports.__wbindgen_throw = function(ptr, len) {
throw new Error(getStringFromWasm(ptr, len));
};
function init(wasm_path) {
const fetchPromise = fetch(wasm_path);
let resultPromise;
if (typeof WebAssembly.instantiateStreaming === 'function') {
resultPromise = WebAssembly.instantiateStreaming(fetchPromise, { './wasm_rustfmt': __exports });
} else {
resultPromise = fetchPromise
.then(response => response.arrayBuffer())
.then(buffer => WebAssembly.instantiate(buffer, { './wasm_rustfmt': __exports }));
}
return resultPromise.then(({instance}) => {
wasm = init.wasm = instance.exports;
return;
});
};
self.wasm_bindgen = Object.assign(init, __exports);
})();