-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjs_hello_world.js
More file actions
203 lines (170 loc) · 7.09 KB
/
js_hello_world.js
File metadata and controls
203 lines (170 loc) · 7.09 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/* tslint:disable */
import * as wasm from './js_hello_world_bg';
const TextDecoder = typeof window === 'object' && window.TextDecoder
? window.TextDecoder
: require('util').TextDecoder;
let cachedDecoder = null;
function textDecoder() {
if (cachedDecoder)
return cachedDecoder;
cachedDecoder = new TextDecoder('utf-8');
return cachedDecoder;
}
let cachedUint8Memory = null;
function getUint8Memory() {
if (cachedUint8Memory === null ||
cachedUint8Memory.buffer !== wasm.memory.buffer)
cachedUint8Memory = new Uint8Array(wasm.memory.buffer);
return cachedUint8Memory;
}
function getStringFromWasm(ptr, len) {
return textDecoder().decode(getUint8Memory().slice(ptr, ptr + len));
}
let cachedUint32Memory = null;
function getUint32Memory() {
if (cachedUint32Memory === null ||
cachedUint32Memory.buffer !== wasm.memory.buffer)
cachedUint32Memory = new Uint32Array(wasm.memory.buffer);
return cachedUint32Memory;
}
let cachedGlobalArgumentPtr = null;
function globalArgumentPtr() {
if (cachedGlobalArgumentPtr === null)
cachedGlobalArgumentPtr = wasm.__wbindgen_global_argument_ptr();
return cachedGlobalArgumentPtr;
}
function getGlobalArgument(arg) {
const idx = globalArgumentPtr() / 4 + arg;
return getUint32Memory()[idx];
}
export function __wbg_f_alert_alert_n (arg0) {
let len0 = getGlobalArgument(0);
let v0 = getStringFromWasm(arg0, len0);
alert(v0)
}
const TextEncoder = typeof window === 'object' && window.TextEncoder
? window.TextEncoder
: require('util').TextEncoder;
let cachedEncoder = null;
function textEncoder() {
if (cachedEncoder)
return cachedEncoder;
cachedEncoder = new TextEncoder('utf-8');
return cachedEncoder;
}
function passStringToWasm(arg) {
const buf = textEncoder().encode(arg);
const ptr = wasm.__wbindgen_malloc(buf.length);
getUint8Memory().set(buf, ptr);
return [ptr, buf.length];
}
function setGlobalArgument(arg, i) {
const idx = globalArgumentPtr() / 4 + i;
getUint32Memory()[idx] = arg;
}
export function greet (arg0) {
const [ptr0, len0] = passStringToWasm(arg0);
setGlobalArgument(len0, 0);
try {
const ret = wasm.greet(ptr0);
return ret;
} finally {
wasm.__wbindgen_free(ptr0, len0 * 1);
}
}
let slab = [];
let slab_next = 0;
function addHeapObject(obj) {
if (slab_next === slab.length)
slab.push(slab.length + 1);
const idx = slab_next;
const next = slab[idx];
slab_next = next;
slab[idx] = { obj, cnt: 1 };
return idx << 1;
}
let stack = [];
function getObject(idx) {
if ((idx & 1) === 1) {
return stack[idx >> 1];
} else {
const val = slab[idx >> 1];
return val.obj;
}
}
export function __wbindgen_object_clone_ref (idx) {
// If this object is on the stack promote it to the heap.
if ((idx & 1) === 1)
return addHeapObject(getObject(idx));
// Otherwise if the object is on the heap just bump the
// refcount and move on
const val = slab[idx >> 1];
val.cnt += 1;
return idx;
}
function dropRef(idx) {
let obj = slab[idx >> 1];
obj.cnt -= 1;
if (obj.cnt > 0)
return;
// If we hit 0 then free up our space in the slab
slab[idx >> 1] = slab_next;
slab_next = idx >> 1;
}
export function __wbindgen_object_drop_ref (i) { dropRef(i); }
export function __wbindgen_string_new (p, l) {
return addHeapObject(getStringFromWasm(p, l));
}
export function __wbindgen_number_new (i) { return addHeapObject(i); }
export function __wbindgen_number_get (n, invalid) {
let obj = getObject(n);
if (typeof(obj) === 'number')
return obj;
getUint8Memory()[invalid] = 1;
return 0;
}
export function __wbindgen_undefined_new () { return addHeapObject(undefined); }
export function __wbindgen_null_new () {
return addHeapObject(null);
}
export function __wbindgen_is_null (idx) {
return getObject(idx) === null ? 1 : 0;
}
export function __wbindgen_is_undefined (idx) {
return getObject(idx) === undefined ? 1 : 0;
}
export function __wbindgen_boolean_new (v) {
return addHeapObject(v === 1);
}
export function __wbindgen_boolean_get (i) {
let v = getObject(i);
if (typeof(v) === 'boolean') {
return v ? 1 : 0;
} else {
return 2;
}
}
export function __wbindgen_symbol_new (ptr, len) {
let a;
console.log(ptr, len);
if (ptr === 0) {
a = Symbol();
} else {
a = Symbol(getStringFromWasm(ptr, len));
}
return addHeapObject(a);
}
export function __wbindgen_is_symbol (i) {
return typeof(getObject(i)) === 'symbol' ? 1 : 0;
}
export function __wbindgen_throw (ptr, len) {
throw new Error(getStringFromWasm(ptr, len));
}
export function __wbindgen_string_get (i, len_ptr) {
let obj = getObject(i);
if (typeof(obj) !== 'string')
return 0;
const [ptr, len] = passStringToWasm(obj);
getUint32Memory()[len_ptr / 4] = len;
return ptr;
}