Skip to content

Commit 1353460

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

17 files changed

+91
-139
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": {
@@ -26,7 +25,6 @@
2625
"noSubstr": "error"
2726
},
2827
"style": {
29-
"noArguments": "off",
3028
"noCommaOperator": "off",
3129
"noParameterAssign": "off",
3230
"noUselessElse": "off",

runtime/js/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/js/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/js/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/js/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/js/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/js/gc.js

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

runtime/js/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/js/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/js/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;
@@ -379,12 +377,8 @@ function caml_ojs_new_arr(c, a) {
379377
//Provides: caml_js_wrap_callback const (const)
380378
//Requires: caml_callback
381379
function caml_js_wrap_callback(f) {
382-
return function () {
383-
var len = arguments.length;
384-
if (len > 0) {
385-
var args = new Array(len);
386-
for (var i = 0; i < len; i++) args[i] = arguments[i];
387-
} else {
380+
return (...args) => {
381+
if (args.length <= 0) {
388382
args = [undefined];
389383
}
390384
var res = caml_callback(f, args);
@@ -395,76 +389,55 @@ function caml_js_wrap_callback(f) {
395389
//Provides: caml_js_wrap_callback_arguments
396390
//Requires: caml_callback
397391
function caml_js_wrap_callback_arguments(f) {
398-
return function () {
399-
var len = arguments.length;
400-
var args = new Array(len);
401-
for (var i = 0; i < len; i++) args[i] = arguments[i];
402-
return caml_callback(f, [args]);
403-
};
392+
return (...args) => caml_callback(f, [args]);
404393
}
405394
//Provides: caml_js_wrap_callback_strict const
406395
//Requires: caml_callback
407396
function caml_js_wrap_callback_strict(arity, f) {
408-
return function () {
409-
var n = arguments.length;
410-
var args = new Array(arity);
411-
var len = Math.min(arguments.length, arity);
412-
for (var i = 0; i < len; i++) args[i] = arguments[i];
397+
return (...args) => {
398+
args.length = arity;
413399
return caml_callback(f, args);
414400
};
415401
}
416402
//Provides: caml_js_wrap_callback_unsafe const (const)
417403
//Requires: caml_callback, caml_js_function_arity
418404
function caml_js_wrap_callback_unsafe(f) {
419-
return function () {
405+
return (...args) => {
420406
var len = caml_js_function_arity(f);
421-
var args = new Array(len);
422-
for (var i = 0; i < len; i++) args[i] = arguments[i];
407+
args.length = len;
423408
return caml_callback(f, args);
424409
};
425410
}
426411
//Provides: caml_js_wrap_meth_callback const (const)
427412
//Requires: caml_callback, caml_js_wrap_callback
428413
function caml_js_wrap_meth_callback(f) {
429-
return function () {
430-
var len = arguments.length;
431-
var args = new Array(len + 1);
432-
args[0] = this;
433-
for (var i = 0; i < len; i++) args[i + 1] = arguments[i];
434-
var res = caml_callback(f, args);
414+
return function (...args) {
415+
const res = caml_callback(f, [this].concat(args));
435416
return res instanceof Function ? caml_js_wrap_callback(res) : res;
436417
};
437418
}
438419
//Provides: caml_js_wrap_meth_callback_arguments const (const)
439420
//Requires: caml_callback
440421
function caml_js_wrap_meth_callback_arguments(f) {
441-
return function () {
442-
var len = arguments.length;
443-
var args = new Array(len);
444-
for (var i = 0; i < len; i++) args[i] = arguments[i];
422+
return function (...args) {
445423
return caml_callback(f, [this, args]);
446424
};
447425
}
448426
//Provides: caml_js_wrap_meth_callback_strict const
449427
//Requires: caml_callback
450428
function caml_js_wrap_meth_callback_strict(arity, f) {
451-
return function () {
452-
var args = new Array(arity + 1);
453-
var len = Math.min(arguments.length, arity);
454-
args[0] = this;
455-
for (var i = 0; i < len; i++) args[i + 1] = arguments[i];
456-
return caml_callback(f, args);
429+
return function (...args) {
430+
args.length = arity;
431+
return caml_callback(f, [this].concat(args));
457432
};
458433
}
459434
//Provides: caml_js_wrap_meth_callback_unsafe const (const)
460435
//Requires: caml_callback, caml_js_function_arity
461436
function caml_js_wrap_meth_callback_unsafe(f) {
462-
return function () {
463-
var len = caml_js_function_arity(f) - 1;
464-
var args = new Array(len + 1);
465-
args[0] = this;
466-
for (var i = 0; i < len; i++) args[i + 1] = arguments[i];
467-
return caml_callback(f, args);
437+
return function (...args) {
438+
const len = caml_js_function_arity(f) - 1;
439+
args.length = len;
440+
return caml_callback(f, [this].concat(args));
468441
};
469442
}
470443

runtime/js/marshal.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -309,17 +309,13 @@ var caml_custom_ops = {
309309
fixed_length: 4,
310310
},
311311
_bigarray: {
312-
deserialize: function (reader, sz) {
313-
return caml_ba_deserialize(reader, sz, "_bigarray");
314-
},
312+
deserialize: (reader, sz) => caml_ba_deserialize(reader, sz, "_bigarray"),
315313
serialize: caml_ba_serialize,
316314
compare: caml_ba_compare,
317315
hash: caml_ba_hash,
318316
},
319317
_bigarr02: {
320-
deserialize: function (reader, sz) {
321-
return caml_ba_deserialize(reader, sz, "_bigarr02");
322-
},
318+
deserialize: (reader, sz) => caml_ba_deserialize(reader, sz, "_bigarr02"),
323319
serialize: caml_ba_serialize,
324320
compare: caml_ba_compare,
325321
hash: caml_ba_hash,
@@ -625,7 +621,7 @@ function caml_marshal_data_size(s, ofs) {
625621
//Provides: MlObjectTable
626622
var MlObjectTable;
627623
if (typeof globalThis.Map === "undefined") {
628-
MlObjectTable = (function () {
624+
MlObjectTable = (() => {
629625
/* polyfill (using linear search) */
630626
function NaiveLookup(objs) {
631627
this.objs = objs;
@@ -635,7 +631,7 @@ if (typeof globalThis.Map === "undefined") {
635631
if (this.objs[i] === v) return i;
636632
}
637633
};
638-
NaiveLookup.prototype.set = function () {
634+
NaiveLookup.prototype.set = () => {
639635
// Do nothing here. [MlObjectTable.store] will push to [this.objs] directly.
640636
};
641637

@@ -670,7 +666,7 @@ MlObjectTable.prototype.recall = function (v) {
670666
//Requires: caml_is_ml_string, caml_ml_string_length, caml_string_unsafe_get
671667
//Requires: MlObjectTable, caml_list_to_js_array, caml_custom_ops
672668
//Requires: caml_invalid_argument,caml_string_of_jsbytes, caml_is_continuation_tag
673-
var caml_output_val = (function () {
669+
var caml_output_val = (() => {
674670
function Writer() {
675671
this.chunk = [];
676672
}
@@ -715,7 +711,7 @@ var caml_output_val = (function () {
715711
return this.chunk;
716712
},
717713
};
718-
return function (v, flags) {
714+
return (v, flags) => {
719715
flags = caml_list_to_js_array(flags);
720716

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

runtime/js/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)