Skip to content

Commit

Permalink
Runtime: no longer use arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
hhugo committed Nov 21, 2024
1 parent 4680208 commit a9a2d8b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 67 deletions.
1 change: 0 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"noSubstr": "error"
},
"style": {
"noArguments": "off",
"noCommaOperator": "off",
"noParameterAssign": "off",
"noUselessElse": "off",
Expand Down
55 changes: 17 additions & 38 deletions runtime/js/jslib.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,8 @@ function caml_ojs_new_arr(c, a) {
//Provides: caml_js_wrap_callback const (const)
//Requires: caml_callback
function caml_js_wrap_callback(f) {
return function () {
var len = arguments.length;
if (len > 0) {
var args = new Array(len);
for (var i = 0; i < len; i++) args[i] = arguments[i];
} else {
return function (...args) {
if (args.length === 0) {
args = [undefined];
}
var res = caml_callback(f, args);
Expand All @@ -395,75 +391,58 @@ function caml_js_wrap_callback(f) {
//Provides: caml_js_wrap_callback_arguments
//Requires: caml_callback
function caml_js_wrap_callback_arguments(f) {
return function () {
var len = arguments.length;
var args = new Array(len);
for (var i = 0; i < len; i++) args[i] = arguments[i];
return function (...args) {
return caml_callback(f, [args]);
};
}
//Provides: caml_js_wrap_callback_strict const
//Requires: caml_callback
function caml_js_wrap_callback_strict(arity, f) {
return function () {
var n = arguments.length;
var args = new Array(arity);
var len = Math.min(arguments.length, arity);
for (var i = 0; i < len; i++) args[i] = arguments[i];
return function (...args) {
args.length = arity;
return caml_callback(f, args);
};
}
//Provides: caml_js_wrap_callback_unsafe const (const)
//Requires: caml_callback, caml_js_function_arity
function caml_js_wrap_callback_unsafe(f) {
return function () {
return function (...args) {
var len = caml_js_function_arity(f);
var args = new Array(len);
for (var i = 0; i < len; i++) args[i] = arguments[i];
args.length = len;
return caml_callback(f, args);
};
}
//Provides: caml_js_wrap_meth_callback const (const)
//Requires: caml_callback, caml_js_wrap_callback
function caml_js_wrap_meth_callback(f) {
return function () {
var len = arguments.length;
var args = new Array(len + 1);
args[0] = this;
for (var i = 0; i < len; i++) args[i + 1] = arguments[i];
var res = caml_callback(f, args);
return function (...args) {
var res = caml_callback(f, [this, ...args]);
return res instanceof Function ? caml_js_wrap_callback(res) : res;
};
}
//Provides: caml_js_wrap_meth_callback_arguments const (const)
//Requires: caml_callback
function caml_js_wrap_meth_callback_arguments(f) {
return function () {
var len = arguments.length;
var args = new Array(len);
for (var i = 0; i < len; i++) args[i] = arguments[i];
return function (...args) {
return caml_callback(f, [this, args]);
};
}
//Provides: caml_js_wrap_meth_callback_strict const
//Requires: caml_callback
function caml_js_wrap_meth_callback_strict(arity, f) {
return function () {
var args = new Array(arity + 1);
var len = Math.min(arguments.length, arity);
args[0] = this;
for (var i = 0; i < len; i++) args[i + 1] = arguments[i];
return function (...args) {
args = [this, ...args];
args.length = arity + 1;
return caml_callback(f, args);
};
}
//Provides: caml_js_wrap_meth_callback_unsafe const (const)
//Requires: caml_callback, caml_js_function_arity
function caml_js_wrap_meth_callback_unsafe(f) {
return function () {
var len = caml_js_function_arity(f) - 1;
var args = new Array(len + 1);
args[0] = this;
for (var i = 0; i < len; i++) args[i + 1] = arguments[i];
return function (...args) {
var len = caml_js_function_arity(f);
args = [this, ...args];
args.length = len;
return caml_callback(f, args);
};
}
Expand Down
21 changes: 7 additions & 14 deletions runtime/js/stdlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,9 @@ function caml_call_gen(f, args) {
break;
}
default: {
var g = function () {
var extra_args = arguments.length === 0 ? 1 : arguments.length;
var nargs = new Array(args.length + extra_args);
for (var i = 0; i < args.length; i++) nargs[i] = args[i];
for (var i = 0; i < arguments.length; i++)
nargs[args.length + i] = arguments[i];
return caml_call_gen(f, nargs);
var g = function (...extra_args) {
if (extra_args.length === 0) extra_args = [undefined];
return caml_call_gen(f, [...args, ...extra_args]);
};
}
}
Expand Down Expand Up @@ -112,13 +108,10 @@ function caml_call_gen(f, args) {
break;
}
default: {
var g = function () {
var extra_args = arguments.length === 0 ? 1 : arguments.length;
var nargs = new Array(argsLen + extra_args);
for (var i = 0; i < argsLen; i++) nargs[i] = args[i];
for (var i = 0; i < arguments.length; i++)
nargs[argsLen + i] = arguments[i];
return caml_call_gen(f, nargs);
args.length = argsLen;
var g = function (...extra_args) {
if (extra_args.length === 0) extra_args = [undefined];
return caml_call_gen(f, [...args, ...extra_args]);
};
}
}
Expand Down
21 changes: 7 additions & 14 deletions runtime/js/stdlib_modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,9 @@ function caml_call_gen(f, args) {
break;
}
default: {
var g = function () {
var extra_args = arguments.length === 0 ? 1 : arguments.length;
var nargs = new Array(args.length + extra_args);
for (var i = 0; i < args.length; i++) nargs[i] = args[i];
for (var i = 0; i < arguments.length; i++)
nargs[args.length + i] = arguments[i];
return caml_call_gen(f, nargs);
var g = function (...extra_args) {
if (extra_args.length === 0) extra_args = [undefined];
return caml_call_gen(f, [...args, ...extra_args]);
};
}
}
Expand Down Expand Up @@ -108,13 +104,10 @@ function caml_call_gen(f, args) {
break;
}
default: {
var g = function () {
var extra_args = arguments.length === 0 ? 1 : arguments.length;
var nargs = new Array(argsLen + extra_args);
for (var i = 0; i < argsLen; i++) nargs[i] = args[i];
for (var i = 0; i < arguments.length; i++)
nargs[argsLen + i] = arguments[i];
return caml_call_gen(f, nargs);
args.length = argsLen;
var g = function (...extra_args) {
if (extra_args.length === 0) extra_args = [undefined];
return caml_call_gen(f, [...args, ...extra_args]);
};
}
}
Expand Down

0 comments on commit a9a2d8b

Please sign in to comment.