Skip to content

Commit

Permalink
fix(exo)!: reject extra args by default
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Dec 11, 2023
1 parent c64bc4e commit 7242a8d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
17 changes: 9 additions & 8 deletions packages/exo/src/exo-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ const PassableMethodGuard = M.call().rest(M.any()).returns(M.any());
* @param {Passable[]} syncArgs
* @param {MatchConfig} matchConfig
* @param {string} [label]
* @returns {Passable[]} Returns the args that should be passed to the
* raw method
* @returns {import('@endo/pass-style').Passable[]}
* Returns the args that should be passed to the raw method.
*/
const defendSyncArgs = (syncArgs, matchConfig, label = undefined) => {
const {
Expand All @@ -69,7 +69,8 @@ const defendSyncArgs = (syncArgs, matchConfig, label = undefined) => {
redactedIndices,
} = matchConfig;

// Use syncArgs if possible, but copy it when necessary to implement redactions.
// Use syncArgs if possible, but copy it when necessary to implement
// redactions.
let matchableArgs = syncArgs;
if (restArgGuardIsRaw && syncArgs.length > declaredLen) {
const restLen = syncArgs.length - declaredLen;
Expand All @@ -96,11 +97,11 @@ const defendSyncArgs = (syncArgs, matchConfig, label = undefined) => {
if (hasRestArgGuard) {
return syncArgs;
}
if (syncArgs.length <= declaredLen) {
return syncArgs;
}
// Ignore extraneous arguments, as a JS function call would do.
return syncArgs.slice(0, declaredLen);
syncArgs.length <= declaredLen ||
Fail`${q(label)} accepts at most ${q(declaredLen)} arguments, not ${q(
syncArgs.length,
)}: ${syncArgs}`;
return syncArgs;
};

/**
Expand Down
7 changes: 5 additions & 2 deletions packages/exo/test/test-heap-classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ const NoExtraI = M.interface('NoExtra', {
});

test('what happens with extra arguments', t => {
const exo = makeExo('WithExtra', NoExtraI, {
const exo = makeExo('NoExtraArgs', NoExtraI, {
foo(x) {
t.is(x, undefined);
},
});
exo.foo('an extra arg');
t.throws(() => exo.foo('an extra arg'), {
message:
'"In \\"foo\\" method of (NoExtraArgs)" accepts at most 0 arguments, not 1: ["an extra arg"]',
});
});

const OptionalArrayI = M.interface('OptionalArray', {
Expand Down
14 changes: 7 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5099,7 +5099,7 @@ error-ex@^1.3.1:
dependencies:
is-arrayish "^0.2.1"

es-abstract@^1.17.2, es-abstract@^1.19.0, es-abstract@^1.19.2, es-abstract@^1.20.1, es-abstract@^1.20.4, es-abstract@^1.22.1:
es-abstract@^1.17.2, es-abstract@^1.19.2, es-abstract@^1.20.1, es-abstract@^1.20.4, es-abstract@^1.22.1:
version "1.22.3"
resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.22.3.tgz#48e79f5573198de6dee3589195727f4f74bc4f32"
integrity sha512-eiiY8HQeYfYH2Con2berK+To6GrK2RxbPawDkGq4UiCQQfZHb6wX9qQqkbpPqaxQFcl8d9QzZqo0tGE0VcrdwA==
Expand Down Expand Up @@ -6016,7 +6016,7 @@ function-bind@^1.1.1, function-bind@^1.1.2:
resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.2.tgz#2c02d864d97f3ea6c8830c464cbd11ab6eab7a1c"
integrity sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==

function.prototype.name@^1.1.5, function.prototype.name@^1.1.6:
function.prototype.name@^1.1.6:
version "1.1.6"
resolved "https://registry.yarnpkg.com/function.prototype.name/-/function.prototype.name-1.1.6.tgz#cdf315b7d90ee77a4c6ee216c3c3362da07533fd"
integrity sha512-Z5kx79swU5P27WEayXM1tBi5Ze/lbIyiNgU3qyXUOf9b2rgXYyF9Dy9Cx+IQv/Lc8WCG6L82zwUPpSS9hGehIg==
Expand All @@ -6026,7 +6026,7 @@ function.prototype.name@^1.1.5, function.prototype.name@^1.1.6:
es-abstract "^1.22.1"
functions-have-names "^1.2.3"

functions-have-names@^1.2.2, functions-have-names@^1.2.3:
functions-have-names@^1.2.3:
version "1.2.3"
resolved "https://registry.yarnpkg.com/functions-have-names/-/functions-have-names-1.2.3.tgz#0404fe4ee2ba2f607f0e0ec3c80bae994133b834"
integrity sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==
Expand Down Expand Up @@ -8935,7 +8935,7 @@ object-copy@^0.1.0:
define-property "^0.2.5"
kind-of "^3.0.3"

object-inspect@^1.12.2, object-inspect@^1.12.3, object-inspect@^1.13.1, object-inspect@^1.9.0:
object-inspect@^1.12.3, object-inspect@^1.13.1, object-inspect@^1.9.0:
version "1.13.1"
resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.13.1.tgz#b96c6109324ccfef6b12216a956ca4dc2ff94bc2"
integrity sha512-5qoj1RUiKOMsCCNLV1CBiPYE10sziTsnmNxkAI/rZhiD63CF7IqdFGC/XzjWjpSgLf0LxXX3bDFIh0E18f6UhQ==
Expand Down Expand Up @@ -10498,7 +10498,7 @@ regex-not@^1.0.0, regex-not@^1.0.2:
extend-shallow "^3.0.2"
safe-regex "^1.1.0"

regexp.prototype.flags@^1.4.3, regexp.prototype.flags@^1.5.0, regexp.prototype.flags@^1.5.1:
regexp.prototype.flags@^1.5.0, regexp.prototype.flags@^1.5.1:
version "1.5.1"
resolved "https://registry.yarnpkg.com/regexp.prototype.flags/-/regexp.prototype.flags-1.5.1.tgz#90ce989138db209f81492edd734183ce99f9677e"
integrity sha512-sy6TXMN+hnP/wMy+ISxg3krXx7BAtWVO4UouuCN/ziM9UEne0euamVNafDfvC83bRNr95y0V5iijeDQFUNpvrg==
Expand Down Expand Up @@ -11511,7 +11511,7 @@ string.prototype.trim@^1.2.7, string.prototype.trim@^1.2.8:
define-properties "^1.2.0"
es-abstract "^1.22.1"

string.prototype.trimend@^1.0.6, string.prototype.trimend@^1.0.7:
string.prototype.trimend@^1.0.7:
version "1.0.7"
resolved "https://registry.yarnpkg.com/string.prototype.trimend/-/string.prototype.trimend-1.0.7.tgz#1bb3afc5008661d73e2dc015cd4853732d6c471e"
integrity sha512-Ni79DqeB72ZFq1uH/L6zJ+DKZTkOtPIHovb3YZHQViE+HDouuU4mBrLOLDn5Dde3RF8qw5qVETEjhu9locMLvA==
Expand All @@ -11520,7 +11520,7 @@ string.prototype.trimend@^1.0.6, string.prototype.trimend@^1.0.7:
define-properties "^1.2.0"
es-abstract "^1.22.1"

string.prototype.trimstart@^1.0.6, string.prototype.trimstart@^1.0.7:
string.prototype.trimstart@^1.0.7:
version "1.0.7"
resolved "https://registry.yarnpkg.com/string.prototype.trimstart/-/string.prototype.trimstart-1.0.7.tgz#d4cdb44b83a4737ffbac2d406e405d43d0184298"
integrity sha512-NGhtDFu3jCEm7B4Fy0DpLewdJQOZcQ0rGbwQ/+stjnrp2i+rlKeCvos9hOIeCmqwratM47OBxY7uFZzjxHXmrg==
Expand Down

0 comments on commit 7242a8d

Please sign in to comment.