tests for arity on javascript-exposed Racket functions

This commit is contained in:
Danny Yoo 2011-07-27 15:53:50 -04:00
parent 1451f1e755
commit 46ffe7d142
2 changed files with 12 additions and 8 deletions

View File

@ -51,12 +51,14 @@
MACHINE.env.push(arguments[arguments.length - 1 - i]);
}
// Check arity usage.
if (! plt.baselib.arity.isArityMatching(v.arity, args.length)) {
throw new Error("arity mismatch");
if (! plt.baselib.arity.isArityMatching(v.arity, MACHINE.argcount)) {
fail(new Error(plt.baselib.format.format(
"arity mismatch: expected ~s arguments, but received ~s",
[v.arity, MACHINE.argcount])));
return;
}
var result = v.apply(null, args);
var result = v.call(null, MACHINE);
MACHINE.argcount = oldArgcount;
for (var i = 0; i < arguments.length - 2; i++) {
MACHINE.env.pop();
@ -74,12 +76,14 @@
succ = succ || function(){};
fail = fail || function(){};
// Check arity usage.
if (! plt.baselib.arity.isArityMatching(v.arity, arguments.length - 2)) {
throw new Error("arity mismatch");
fail(new Error(
plt.baselib.format.format(
"arity mismatch: expected ~s argument(s) but received ~s",
[v.arity, arguments.length - 2])));
return;
}
var oldVal = MACHINE.val;
var oldArgcount = MACHINE.argcount;
var oldProc = MACHINE.proc;

View File

@ -19,7 +19,7 @@ plt.runtime.ready(function() {
function(err) {
$('#answer').text(err.message).css("color", "red");
},
10000
11
// "one-billion-dollars"
);
});