|
17 | 17 |
|
18 | 18 | ((js) => async (args) => { |
19 | 19 | "use strict"; |
20 | | - let {link, src, generated} = args; |
| 20 | + const {link, src, generated} = args; |
21 | 21 |
|
22 | 22 | const isNode = globalThis?.process?.versions?.node; |
23 | 23 |
|
24 | | - let math = |
| 24 | + const math = |
25 | 25 | {cos:Math.cos, sin:Math.sin, tan:Math.tan, |
26 | 26 | acos:Math.acos, asin:Math.asin, atan:Math.atan, |
27 | 27 | cosh:Math.cosh, sinh:Math.sinh, tanh:Math.tanh, |
|
31 | 31 | atan2:Math.atan2, hypot:Math.hypot, pow:Math.pow, |
32 | 32 | fmod:(x, y) => x%y} |
33 | 33 |
|
34 | | - let typed_arrays = |
| 34 | + const typed_arrays = |
35 | 35 | [Float32Array, Float64Array, Int8Array, Uint8Array, Int16Array, |
36 | 36 | Uint16Array, Int32Array, Int32Array, Int32Array, Int32Array, |
37 | 37 | Float32Array, Float64Array, Uint8Array, Uint8ClampedArray] |
38 | 38 |
|
39 | | - const fs = isNode&&require('fs') |
| 39 | + const fs = isNode&&require('node:fs') |
40 | 40 |
|
41 | | - let fs_cst = fs?.constants; |
| 41 | + const fs_cst = fs?.constants; |
42 | 42 |
|
43 | | - let open_flags = |
| 43 | + const open_flags = |
44 | 44 | fs?[fs_cst.RDONLY,fs_cst.O_WRONLY,fs_cst.O_APPEND,fs_cst.O_CREAT, |
45 | 45 | fs_cst.O_TRUNC,fs_cst.O_EXCL,fs_cst.O_NONBLOCK]:[] |
46 | 46 |
|
|
97 | 97 | return h ^ s.length; |
98 | 98 | } |
99 | 99 |
|
100 | | - let bindings = |
| 100 | + const bindings = |
101 | 101 | {jstag: |
102 | 102 | WebAssembly.JSTag|| |
103 | 103 | // ZZZ not supported in Firefox yet |
|
117 | 117 | new_obj:()=>({}), |
118 | 118 | new:(c,args)=>new c(...args), |
119 | 119 | global_this:globalThis, |
120 | | - iter_props:(o,f)=>{for (var nm in o) if(o.hasOwnProperty(nm)) f(nm)}, |
| 120 | + iter_props:(o,f)=>{for (var nm in o) if(o.hasOwn(nm)) f(nm)}, |
121 | 121 | array_length:(a)=>a.length, |
122 | 122 | array_get:(a,i)=>a[i], |
123 | 123 | array_set:(a,i,v)=>a[i]=v, |
|
128 | 128 | append_string:(s1,s2)=>s1+s2, |
129 | 129 | write_string:(s)=>{ |
130 | 130 | var start = 0, len = s.length; |
131 | | - while (1) { |
132 | | - let {read,written} = encoder.encodeInto(s.slice(start), out_buffer); |
| 131 | + for(;;) { |
| 132 | + const {read,written} = encoder.encodeInto(s.slice(start), out_buffer); |
133 | 133 | len -= read; |
134 | 134 | if (!len) return written; |
135 | 135 | caml_extract_string(written); |
|
227 | 227 | if (Math.abs(x) < 1.0) { |
228 | 228 | return x.toFixed(dp); |
229 | 229 | } else { |
230 | | - var e = parseInt(x.toString().split('+')[1]); |
| 230 | + var e = Number.parseInt(x.toString().split('+')[1]); |
231 | 231 | if (e > 20) { |
232 | 232 | e -= 20; |
233 | 233 | x /= Math.pow(10,e); |
|
322 | 322 | argv:()=>isNode?process.argv.slice(1):['a.out'], |
323 | 323 | getenv:(n)=>isNode?process.env[n]:null, |
324 | 324 | system:(c)=>{ |
325 | | - var res = require('child_process').spawnSync(c,{shell:true, stdio: 'inherit'}); |
| 325 | + var res = require('node:child_process').spawnSync(c,{shell:true, stdio: 'inherit'}); |
326 | 326 | if(res.error)throw res.error; return res.signal?255:res.status |
327 | 327 | }, |
328 | 328 | time:()=>performance.now(), |
|
350 | 350 | map_delete:(m,x)=>m.delete(x), |
351 | 351 | log:(x)=>console.log('ZZZZZ', x) |
352 | 352 | } |
353 | | - let string_ops = |
| 353 | + const string_ops = |
354 | 354 | {test:(v)=>+(typeof v==="string"), |
355 | 355 | compare:(s1,s2)=>(s1<s2)?-1:+(s1>s2), |
356 | 356 | hash:hash_string, |
|
366 | 366 | const options = { builtins: ['js-string', 'text-decoder', 'text-encoder'] } |
367 | 367 |
|
368 | 368 | function loadRelative(src) { |
369 | | - const path = require('path'); |
| 369 | + const path = require('node:path'); |
370 | 370 | const f = path.join(path.dirname(require.main.filename),src); |
371 | | - return require('fs/promises').readFile(f) |
| 371 | + return require('node:fs/promises').readFile(f) |
372 | 372 | } |
373 | 373 | function fetchRelative(src) { |
374 | 374 | const base = globalThis?.document?.currentScript?.src; |
|
0 commit comments