Skip to content

Commit 7ea59a4

Browse files
committed
runtime: fix useArrowFunction and noArguments
Signed-off-by: Sora Morimoto <[email protected]>
1 parent bd764f9 commit 7ea59a4

18 files changed

+92
-140
lines changed

biome.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"rules": {
1414
"recommended": true,
1515
"complexity": {
16-
"useArrowFunction": "off",
1716
"useOptionalChain": "off"
1817
},
1918
"correctness": {
@@ -28,7 +27,6 @@
2827
"noGlobalEval": "off"
2928
},
3029
"style": {
31-
"noArguments": "off",
3230
"noCommaOperator": "off",
3331
"noParameterAssign": "off",
3432
"noUselessElse": "off",

runtime/backtrace.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
//Requires: jsoo_sys_getenv
2020
var caml_record_backtrace_env_flag = FLAG("with-js-error");
2121

22-
(function () {
22+
(() => {
2323
var r = jsoo_sys_getenv("OCAMLRUNPARAM");
2424
if (r !== undefined) {
2525
var l = r.split(",");

runtime/blake2.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//Provides: blake2b
22
//Version: >= 5.2
3-
var blake2b = (function () {
3+
var blake2b = (() => {
44
// Blake2B in pure Javascript
55
// Adapted from the reference implementation in RFC7693
66
// Ported to Javascript by DC - https://github.com/dcposch
@@ -104,11 +104,7 @@ var blake2b = (function () {
104104
// These are offsets into a uint64 buffer.
105105
// Multiply them all by 2 to make them offsets into a uint32 buffer,
106106
// because this is Javascript and we don't have uint64s
107-
const SIGMA82 = new Uint8Array(
108-
SIGMA8.map(function (x) {
109-
return x * 2;
110-
}),
111-
);
107+
const SIGMA82 = new Uint8Array(SIGMA8.map((x) => x * 2));
112108

113109
// Compression function. 'last' flag indicates last block.
114110
// Note we're representing 16 uint64s as 32 uint32s

runtime/effect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function caml_push_trap(handler) {
6060
//If: effects
6161
function caml_pop_trap() {
6262
if (!caml_exn_stack)
63-
return function (x) {
63+
return (x) => {
6464
throw x;
6565
};
6666
var h = caml_exn_stack[1];

runtime/fs_fake.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ MlFakeDevice.prototype.create_dir_if_needed = function (name) {
4242
this.content[res] = Symbol("directory");
4343
}
4444
};
45-
MlFakeDevice.prototype.slash = function (name) {
46-
return /\/$/.test(name) ? name : name + "/";
47-
};
45+
MlFakeDevice.prototype.slash = (name) => (/\/$/.test(name) ? name : name + "/");
4846
MlFakeDevice.prototype.lookup = function (name) {
4947
if (!this.content[name] && this.lookupFun) {
5048
var res = this.lookupFun(
@@ -350,18 +348,14 @@ MlFakeFile.prototype.read = function (offset, buf, pos, len) {
350348
//Requires: caml_raise_sys_error
351349
function MlFakeFd_out(fd, flags) {
352350
MlFakeFile.call(this, caml_create_bytes(0));
353-
this.log = function (s) {
354-
return 0;
355-
};
351+
this.log = (s) => 0;
356352
if (fd == 1 && typeof console.log == "function") this.log = console.log;
357353
else if (fd == 2 && typeof console.error == "function")
358354
this.log = console.error;
359355
else if (typeof console.log == "function") this.log = console.log;
360356
this.flags = flags;
361357
}
362-
MlFakeFd_out.prototype.length = function () {
363-
return 0;
364-
};
358+
MlFakeFd_out.prototype.length = () => 0;
365359
MlFakeFd_out.prototype.write = function (offset, buf, pos, len) {
366360
if (this.log) {
367361
if (

runtime/fs_node.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ MlNodeDevice.prototype.opendir = function (name, raise_unix) {
189189
this.raise_nodejs_error(err, raise_unix);
190190
}
191191
};
192-
MlNodeDevice.prototype.raise_nodejs_error = function (err, raise_unix) {
192+
MlNodeDevice.prototype.raise_nodejs_error = (err, raise_unix) => {
193193
var unix_error = caml_named_value("Unix.Unix_error");
194194
if (raise_unix && unix_error) {
195195
var args = make_unix_err_args(err.code, err.syscall, err.path, err.errno);
@@ -198,7 +198,7 @@ MlNodeDevice.prototype.raise_nodejs_error = function (err, raise_unix) {
198198
caml_raise_sys_error(err.toString());
199199
}
200200
};
201-
MlNodeDevice.prototype.stats_from_js = function (js_stats) {
201+
MlNodeDevice.prototype.stats_from_js = (js_stats) => {
202202
/* ===Unix.file_kind===
203203
* type file_kind =
204204
* S_REG (** Regular file *)

runtime/gc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function caml_final_register() {
6565
var all_finalizers = new globalThis.Set();
6666
function caml_final_register_called_without_value(cb, a) {
6767
if (globalThis.FinalizationRegistry && a instanceof Object) {
68-
var x = new globalThis.FinalizationRegistry(function (x) {
68+
var x = new globalThis.FinalizationRegistry((x) => {
6969
all_finalizers.delete(x);
7070
cb(0);
7171
return;

runtime/graphics.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function caml_gr_open_graph(info) {
7676
canvas.width = w;
7777
canvas.height = h;
7878
var ctx = caml_gr_state_create(canvas, w, h);
79-
ctx.set_title = function (title) {
79+
ctx.set_title = (title) => {
8080
doc.title = title;
8181
};
8282
caml_gr_state_set(ctx);
@@ -460,7 +460,7 @@ function caml_gr_draw_image(im, x, y) {
460460
canvas.height = s.height;
461461
canvas.getContext("2d").putImageData(im, 0, 0);
462462
var image = new globalThis.Image();
463-
image.onload = function () {
463+
image.onload = () => {
464464
s.context.drawImage(image, x, s.height - im.height - y);
465465
im.image = image;
466466
};

runtime/io.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ function caml_sys_open(name, flags, _perms) {
9494
var file = root.device.open(root.rest, f);
9595
return caml_sys_open_internal(file, undefined);
9696
}
97-
(function () {
97+
(() => {
9898
function file(fd, flags) {
9999
if (fs_node_supported()) {
100100
return caml_sys_open_for_node(fd, flags);
@@ -284,7 +284,7 @@ function caml_ml_channel_size_64(chanid) {
284284
//Requires: caml_ml_channel_get
285285
function caml_ml_set_channel_output(chanid, f) {
286286
var chan = caml_ml_channel_get(chanid);
287-
chan.output = function (s) {
287+
chan.output = (s) => {
288288
f(s);
289289
};
290290
return 0;

runtime/jslib.js

Lines changed: 18 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,7 @@ function caml_callback(f, args) {
111111
};
112112
var res = {
113113
joo_tramp: f,
114-
joo_args: args.concat(function (x) {
115-
return x;
116-
}),
114+
joo_args: args.concat((x) => x),
117115
};
118116
do {
119117
caml_stack_depth = 40;
@@ -378,12 +376,8 @@ function caml_ojs_new_arr(c, a) {
378376
//Provides: caml_js_wrap_callback const (const)
379377
//Requires: caml_callback
380378
function caml_js_wrap_callback(f) {
381-
return function () {
382-
var len = arguments.length;
383-
if (len > 0) {
384-
var args = new Array(len);
385-
for (var i = 0; i < len; i++) args[i] = arguments[i];
386-
} else {
379+
return (...args) => {
380+
if (args.length <= 0) {
387381
args = [undefined];
388382
}
389383
var res = caml_callback(f, args);
@@ -394,76 +388,55 @@ function caml_js_wrap_callback(f) {
394388
//Provides: caml_js_wrap_callback_arguments
395389
//Requires: caml_callback
396390
function caml_js_wrap_callback_arguments(f) {
397-
return function () {
398-
var len = arguments.length;
399-
var args = new Array(len);
400-
for (var i = 0; i < len; i++) args[i] = arguments[i];
401-
return caml_callback(f, [args]);
402-
};
391+
return (...args) => caml_callback(f, [args]);
403392
}
404393
//Provides: caml_js_wrap_callback_strict const
405394
//Requires: caml_callback
406395
function caml_js_wrap_callback_strict(arity, f) {
407-
return function () {
408-
var n = arguments.length;
409-
var args = new Array(arity);
410-
var len = Math.min(arguments.length, arity);
411-
for (var i = 0; i < len; i++) args[i] = arguments[i];
396+
return (...args) => {
397+
args.length = arity;
412398
return caml_callback(f, args);
413399
};
414400
}
415401
//Provides: caml_js_wrap_callback_unsafe const (const)
416402
//Requires: caml_callback, caml_js_function_arity
417403
function caml_js_wrap_callback_unsafe(f) {
418-
return function () {
404+
return (...args) => {
419405
var len = caml_js_function_arity(f);
420-
var args = new Array(len);
421-
for (var i = 0; i < len; i++) args[i] = arguments[i];
406+
args.length = len;
422407
return caml_callback(f, args);
423408
};
424409
}
425410
//Provides: caml_js_wrap_meth_callback const (const)
426411
//Requires: caml_callback, caml_js_wrap_callback
427412
function caml_js_wrap_meth_callback(f) {
428-
return function () {
429-
var len = arguments.length;
430-
var args = new Array(len + 1);
431-
args[0] = this;
432-
for (var i = 0; i < len; i++) args[i + 1] = arguments[i];
433-
var res = caml_callback(f, args);
413+
return function (...args) {
414+
const res = caml_callback(f, [this].concat(args));
434415
return res instanceof Function ? caml_js_wrap_callback(res) : res;
435416
};
436417
}
437418
//Provides: caml_js_wrap_meth_callback_arguments const (const)
438419
//Requires: caml_callback
439420
function caml_js_wrap_meth_callback_arguments(f) {
440-
return function () {
441-
var len = arguments.length;
442-
var args = new Array(len);
443-
for (var i = 0; i < len; i++) args[i] = arguments[i];
421+
return function (...args) {
444422
return caml_callback(f, [this, args]);
445423
};
446424
}
447425
//Provides: caml_js_wrap_meth_callback_strict const
448426
//Requires: caml_callback
449427
function caml_js_wrap_meth_callback_strict(arity, f) {
450-
return function () {
451-
var args = new Array(arity + 1);
452-
var len = Math.min(arguments.length, arity);
453-
args[0] = this;
454-
for (var i = 0; i < len; i++) args[i + 1] = arguments[i];
455-
return caml_callback(f, args);
428+
return function (...args) {
429+
args.length = arity;
430+
return caml_callback(f, [this].concat(args));
456431
};
457432
}
458433
//Provides: caml_js_wrap_meth_callback_unsafe const (const)
459434
//Requires: caml_callback, caml_js_function_arity
460435
function caml_js_wrap_meth_callback_unsafe(f) {
461-
return function () {
462-
var len = caml_js_function_arity(f) - 1;
463-
var args = new Array(len + 1);
464-
args[0] = this;
465-
for (var i = 0; i < len; i++) args[i + 1] = arguments[i];
466-
return caml_callback(f, args);
436+
return function (...args) {
437+
const len = caml_js_function_arity(f) - 1;
438+
args.length = len;
439+
return caml_callback(f, [this].concat(args));
467440
};
468441
}
469442

runtime/marshal.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -307,17 +307,13 @@ var caml_custom_ops = {
307307
fixed_length: 4,
308308
},
309309
_bigarray: {
310-
deserialize: function (reader, sz) {
311-
return caml_ba_deserialize(reader, sz, "_bigarray");
312-
},
310+
deserialize: (reader, sz) => caml_ba_deserialize(reader, sz, "_bigarray"),
313311
serialize: caml_ba_serialize,
314312
compare: caml_ba_compare,
315313
hash: caml_ba_hash,
316314
},
317315
_bigarr02: {
318-
deserialize: function (reader, sz) {
319-
return caml_ba_deserialize(reader, sz, "_bigarr02");
320-
},
316+
deserialize: (reader, sz) => caml_ba_deserialize(reader, sz, "_bigarr02"),
321317
serialize: caml_ba_serialize,
322318
compare: caml_ba_compare,
323319
hash: caml_ba_hash,
@@ -623,7 +619,7 @@ function caml_marshal_data_size(s, ofs) {
623619
//Provides: MlObjectTable
624620
var MlObjectTable;
625621
if (typeof globalThis.Map === "undefined") {
626-
MlObjectTable = (function () {
622+
MlObjectTable = (() => {
627623
/* polyfill (using linear search) */
628624
function NaiveLookup(objs) {
629625
this.objs = objs;
@@ -633,7 +629,7 @@ if (typeof globalThis.Map === "undefined") {
633629
if (this.objs[i] === v) return i;
634630
}
635631
};
636-
NaiveLookup.prototype.set = function () {
632+
NaiveLookup.prototype.set = () => {
637633
// Do nothing here. [MlObjectTable.store] will push to [this.objs] directly.
638634
};
639635

@@ -668,7 +664,7 @@ MlObjectTable.prototype.recall = function (v) {
668664
//Requires: caml_is_ml_string, caml_ml_string_length, caml_string_unsafe_get
669665
//Requires: MlObjectTable, caml_list_to_js_array, caml_custom_ops
670666
//Requires: caml_invalid_argument,caml_string_of_jsbytes, caml_is_continuation_tag
671-
var caml_output_val = (function () {
667+
var caml_output_val = (() => {
672668
function Writer() {
673669
this.chunk = [];
674670
}
@@ -713,7 +709,7 @@ var caml_output_val = (function () {
713709
return this.chunk;
714710
},
715711
};
716-
return function (v, flags) {
712+
return (v, flags) => {
717713
flags = caml_list_to_js_array(flags);
718714

719715
var no_sharing = flags.indexOf(0 /*Marshal.No_sharing*/) !== -1,

runtime/md5.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function caml_md5_string(s, ofs, len) {
5353
}
5454

5555
//Provides: caml_MD5Transform
56-
var caml_MD5Transform = (function () {
56+
var caml_MD5Transform = (() => {
5757
function add(x, y) {
5858
return (x + y) | 0;
5959
}
@@ -74,7 +74,7 @@ var caml_MD5Transform = (function () {
7474
return xx(c ^ (b | ~d), a, b, x, s, t);
7575
}
7676

77-
return function (w, buffer) {
77+
return (w, buffer) => {
7878
var a = w[0],
7979
b = w[1],
8080
c = w[2],

0 commit comments

Comments
 (0)