Skip to content

Commit

Permalink
Function arity: use f.l everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
vouillon authored and hhugo committed Jan 13, 2023
1 parent e4f6d73 commit 7ea8780
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions runtime/jslib.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,15 +375,15 @@ function caml_js_wrap_meth_callback_unsafe(f) {
//Provides: caml_js_function_arity
//If: !effects
function caml_js_function_arity(f) {
return f.length
return (f.l >= 0)?f.l:(f.l = f.length)
}

//Provides: caml_js_function_arity
//If: effects
function caml_js_function_arity(f) {
// Functions have an additional continuation parameter. This should
// not be visible when calling them from JavaScript
return f.length - 1
return ((f.l >= 0)?f.l:(f.l = f.length)) - 1
}

//Provides: caml_js_equals mutable (const, const)
Expand Down
4 changes: 2 additions & 2 deletions runtime/stdlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function caml_call_gen(f, args) {
return caml_call_gen(f.fun, args);
//FIXME, can happen with too many arguments
if(typeof f !== "function") return f;
var n = f.length | 0;
var n = (f.l >= 0)?f.l:(f.l = f.length);
if(n === 0) return f.apply(null,args);
var argsLen = args.length | 0;
var d = n - argsLen | 0;
Expand Down Expand Up @@ -76,7 +76,7 @@ function caml_call_gen(f, args) {
if (f.fun)
return caml_call_gen(f.fun, args);
if (typeof f !== "function") return args[args.length-1](f);
var n = f.length | 0;
var n = (f.l >= 0)?f.l:(f.l = f.length);
if (n === 0) return f.apply(null, args);
var argsLen = args.length | 0;
var d = n - argsLen | 0;
Expand Down
4 changes: 2 additions & 2 deletions runtime/stdlib_modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function caml_call_gen(f, args) {
return caml_call_gen(f.fun, args);
//FIXME, can happen with too many arguments
if(typeof f !== "function") return f;
var n = f.length | 0;
var n = (f.l >= 0)?f.l:(f.l = f.length);
if(n === 0) return f(...args);
var argsLen = args.length | 0;
var d = n - argsLen | 0;
Expand Down Expand Up @@ -74,7 +74,7 @@ function caml_call_gen(f, args) {
return caml_call_gen(f.fun, args);
//FIXME, can happen with too many arguments
if(typeof f !== "function") return args[args.length-1](f);
var n = f.length | 0;
var n = (f.l >= 0)?f.l:(f.l = f.length);
if(n === 0) return f(...args);
var argsLen = args.length | 0;
var d = n - argsLen | 0;
Expand Down

0 comments on commit 7ea8780

Please sign in to comment.