Skip to content

Commit 90db9c5

Browse files
committed
Wasm runtime: JavaScript clean-up
1 parent 7cd0e59 commit 90db9c5

File tree

3 files changed

+19
-22
lines changed

3 files changed

+19
-22
lines changed

biome.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
"$schema": "https://biomejs.dev/schemas/1.9.1/schema.json",
33
"files": {
44
"include": ["runtime"],
5-
"ignore": [
6-
"runtime/zstd.ts",
7-
"runtime/wasm/runtime.js",
8-
"runtime/wasm/deps.json"
9-
]
5+
"ignore": ["runtime/zstd.ts"]
106
},
117
"formatter": {
128
"enabled": true,
@@ -46,7 +42,8 @@
4642
"noDoubleEquals": "off",
4743
"noFallthroughSwitchClause": "off",
4844
"noRedeclare": "off",
49-
"noSelfCompare": "off"
45+
"noSelfCompare": "off",
46+
"noRedundantUseStrict": "off"
5047
}
5148
}
5249
},

runtime/wasm/deps.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
33
"name": "root",
4-
"reaches": ["init","exn","mem","strings"],
4+
"reaches": ["init", "exn", "mem", "strings"],
55
"root": true
66
},
77
{

runtime/wasm/runtime.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717

1818
((js) => async (args) => {
1919
"use strict";
20-
let {link, src, generated} = args;
20+
const {link, src, generated} = args;
2121

2222
const isNode = globalThis?.process?.versions?.node;
2323

24-
let math =
24+
const math =
2525
{cos:Math.cos, sin:Math.sin, tan:Math.tan,
2626
acos:Math.acos, asin:Math.asin, atan:Math.atan,
2727
cosh:Math.cosh, sinh:Math.sinh, tanh:Math.tanh,
@@ -31,16 +31,16 @@
3131
atan2:Math.atan2, hypot:Math.hypot, pow:Math.pow,
3232
fmod:(x, y) => x%y}
3333

34-
let typed_arrays =
34+
const typed_arrays =
3535
[Float32Array, Float64Array, Int8Array, Uint8Array, Int16Array,
3636
Uint16Array, Int32Array, Int32Array, Int32Array, Int32Array,
3737
Float32Array, Float64Array, Uint8Array, Uint8ClampedArray]
3838

39-
const fs = isNode&&require('fs')
39+
const fs = isNode&&require('node:fs')
4040

41-
let fs_cst = fs?.constants;
41+
const fs_cst = fs?.constants;
4242

43-
let open_flags =
43+
const open_flags =
4444
fs?[fs_cst.RDONLY,fs_cst.O_WRONLY,fs_cst.O_APPEND,fs_cst.O_CREAT,
4545
fs_cst.O_TRUNC,fs_cst.O_EXCL,fs_cst.O_NONBLOCK]:[]
4646

@@ -97,7 +97,7 @@
9797
return h ^ s.length;
9898
}
9999

100-
let bindings =
100+
const bindings =
101101
{jstag:
102102
WebAssembly.JSTag||
103103
// ZZZ not supported in Firefox yet
@@ -117,7 +117,7 @@
117117
new_obj:()=>({}),
118118
new:(c,args)=>new c(...args),
119119
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)},
121121
array_length:(a)=>a.length,
122122
array_get:(a,i)=>a[i],
123123
array_set:(a,i,v)=>a[i]=v,
@@ -128,8 +128,8 @@
128128
append_string:(s1,s2)=>s1+s2,
129129
write_string:(s)=>{
130130
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);
133133
len -= read;
134134
if (!len) return written;
135135
caml_extract_string(written);
@@ -227,7 +227,7 @@
227227
if (Math.abs(x) < 1.0) {
228228
return x.toFixed(dp);
229229
} else {
230-
var e = parseInt(x.toString().split('+')[1]);
230+
var e = Number.parseInt(x.toString().split('+')[1]);
231231
if (e > 20) {
232232
e -= 20;
233233
x /= Math.pow(10,e);
@@ -322,7 +322,7 @@
322322
argv:()=>isNode?process.argv.slice(1):['a.out'],
323323
getenv:(n)=>isNode?process.env[n]:null,
324324
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'});
326326
if(res.error)throw res.error; return res.signal?255:res.status
327327
},
328328
time:()=>performance.now(),
@@ -350,7 +350,7 @@
350350
map_delete:(m,x)=>m.delete(x),
351351
log:(x)=>console.log('ZZZZZ', x)
352352
}
353-
let string_ops =
353+
const string_ops =
354354
{test:(v)=>+(typeof v==="string"),
355355
compare:(s1,s2)=>(s1<s2)?-1:+(s1>s2),
356356
hash:hash_string,
@@ -366,9 +366,9 @@
366366
const options = { builtins: ['js-string', 'text-decoder', 'text-encoder'] }
367367

368368
function loadRelative(src) {
369-
const path = require('path');
369+
const path = require('node:path');
370370
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)
372372
}
373373
function fetchRelative(src) {
374374
const base = globalThis?.document?.currentScript?.src;

0 commit comments

Comments
 (0)