|
9 | 9 | */ |
10 | 10 |
|
11 | 11 | globalThis.FOUR_GB = 4 * 1024 * 1024 * 1024; |
| 12 | +globalThis.WASM_PAGE_SIZE = 64 * 1024; |
| 13 | + |
12 | 14 | const FLOAT_TYPES = new Set(['float', 'double']); |
13 | 15 |
|
14 | 16 | // Does simple 'macro' substitution, using Django-like syntax, |
15 | 17 | // {{{ code }}} will be replaced with |eval(code)|. |
16 | 18 | // NOTE: Be careful with that ret check. If ret is |0|, |ret ? ret.toString() : ''| would result in ''! |
17 | | -function processMacros(text) { |
| 19 | +function processMacros(text, filename) { |
18 | 20 | // The `?` here in makes the regex non-greedy so it matches with the closest |
19 | 21 | // set of closing braces. |
20 | 22 | // `[\s\S]` works like `.` but include newline. |
21 | 23 | return text.replace(/{{{([\s\S]+?)}}}/g, (_, str) => { |
22 | | - try { |
23 | | - const ret = eval(str); |
24 | | - return ret !== null ? ret.toString() : ''; |
25 | | - } catch (ex) { |
26 | | - ex.stack = `In the following macro:\n\n${str}\n\n${ex.stack}`; |
27 | | - throw ex; |
28 | | - } |
| 24 | + const ret = vm.runInThisContext(str, { filename: filename }); |
| 25 | + return ret !== null ? ret.toString() : ''; |
29 | 26 | }); |
30 | 27 | } |
31 | 28 |
|
@@ -180,21 +177,21 @@ function needsQuoting(ident) { |
180 | 177 | globalThis.POINTER_SIZE = MEMORY64 ? 8 : 4; |
181 | 178 | globalThis.POINTER_MAX = MEMORY64 ? 'Number.MAX_SAFE_INTEGER' : '0xFFFFFFFF'; |
182 | 179 | globalThis.STACK_ALIGN = 16; |
183 | | -const POINTER_BITS = POINTER_SIZE * 8; |
184 | | -const POINTER_TYPE = `u${POINTER_BITS}`; |
185 | | -const POINTER_JS_TYPE = MEMORY64 ? "'bigint'" : "'number'"; |
186 | | -const POINTER_SHIFT = MEMORY64 ? '3' : '2'; |
187 | | -const POINTER_HEAP = MEMORY64 ? 'HEAP64' : 'HEAP32'; |
188 | | -const LONG_TYPE = `i${POINTER_BITS}`; |
| 180 | +globalThis.POINTER_BITS = POINTER_SIZE * 8; |
| 181 | +globalThis.POINTER_TYPE = `u${POINTER_BITS}`; |
| 182 | +globalThis.POINTER_JS_TYPE = MEMORY64 ? "'bigint'" : "'number'"; |
| 183 | +globalThis.POINTER_SHIFT = MEMORY64 ? '3' : '2'; |
| 184 | +globalThis.POINTER_HEAP = MEMORY64 ? 'HEAP64' : 'HEAP32'; |
| 185 | +globalThis.LONG_TYPE = `i${POINTER_BITS}`; |
189 | 186 |
|
190 | | -const SIZE_TYPE = POINTER_TYPE; |
| 187 | +globalThis.SIZE_TYPE = POINTER_TYPE; |
191 | 188 |
|
192 | 189 |
|
193 | 190 | // Similar to POINTER_TYPE, but this is the actual wasm type that is |
194 | 191 | // used in practice, while POINTER_TYPE is the more refined internal |
195 | 192 | // type (that is unsigned, where as core wasm does not have unsigned |
196 | 193 | // types). |
197 | | -const POINTER_WASM_TYPE = `i${POINTER_BITS}`; |
| 194 | +globalThis.POINTER_WASM_TYPE = `i${POINTER_BITS}`; |
198 | 195 |
|
199 | 196 | function isPointerType(type) { |
200 | 197 | return type[type.length - 1] == '*'; |
@@ -699,9 +696,6 @@ function makeRetainedCompilerSettings() { |
699 | 696 | return ret; |
700 | 697 | } |
701 | 698 |
|
702 | | -// In wasm, the heap size must be a multiple of 64KiB. |
703 | | -const WASM_PAGE_SIZE = 65536; |
704 | | - |
705 | 699 | // Receives a function as text, and a function that constructs a modified |
706 | 700 | // function, to which we pass the parsed-out arguments, body, and possible |
707 | 701 | // "async" prefix of the input function. Returns the output of that function. |
|
0 commit comments