From 46ffe7d142c0e1f89d53bfa5cc0f7025e208f6f4 Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Wed, 27 Jul 2011 15:53:50 -0400 Subject: [PATCH] tests for arity on javascript-exposed Racket functions --- js-assembler/runtime-src/baselib-functions.js | 18 +++++++++++------- tests/coersing/index.html | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/js-assembler/runtime-src/baselib-functions.js b/js-assembler/runtime-src/baselib-functions.js index d1bd773..da71ce9 100644 --- a/js-assembler/runtime-src/baselib-functions.js +++ b/js-assembler/runtime-src/baselib-functions.js @@ -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; diff --git a/tests/coersing/index.html b/tests/coersing/index.html index 9e9559f..0f132ac 100644 --- a/tests/coersing/index.html +++ b/tests/coersing/index.html @@ -19,7 +19,7 @@ plt.runtime.ready(function() { function(err) { $('#answer').text(err.message).css("color", "red"); }, - 10000 + 11 // "one-billion-dollars" ); });