fix: bad check defaults
MODIFY
packages/marshal/src/encodeToCapData.js
packages/marshal/src/encodeToCapData.js
@@ -213,7 +213,7 @@ export const makeEncodeToCapData = ({
}
};
const encodeToCapData = passable => {
- if (ErrorHelper.canBeValid(passable)) {
+ if (ErrorHelper.canBeValid(passable, x => x)) {
// We pull out this special case to accommodate errors that are not
// valid Passables. For example, because they're not frozen.
// The special case can only ever apply at the root, and therefore

MODIFY
packages/marshal/src/helpers/copyArray.js
packages/marshal/src/helpers/copyArray.js
@@ -16,7 +16,7 @@ const { isArray, prototype: arrayPrototype } = Array;
export const CopyArrayHelper = harden({
styleName: 'copyArray',
- canBeValid: (candidate, check = x => x) =>
+ canBeValid: (candidate, check) =>
check(isArray(candidate), X`Array expected: ${candidate}`),
assertValid: (candidate, passStyleOfRecur) => {

MODIFY
packages/marshal/src/helpers/copyRecord.js
packages/marshal/src/helpers/copyRecord.js
@@ -23,7 +23,7 @@ const {
export const CopyRecordHelper = harden({
styleName: 'copyRecord',
- canBeValid: (candidate, check = x => x) => {
+ canBeValid: (candidate, check) => {
const proto = getPrototypeOf(candidate);
if (proto !== objectPrototype && proto !== null) {
return check(false, X`Unexpected prototype for: ${candidate}`);

MODIFY
packages/marshal/src/helpers/error.js
packages/marshal/src/helpers/error.js
@@ -35,7 +35,7 @@ harden(getErrorConstructor);
* complaints as notes on the error.
*
* To resolve this, such a malformed error object will still pass
- * `canBeValid(err)` with no check, so marshal can use this for top
+ * `canBeValid(err, x => x)` so marshal can use this for top
* level error to report from, even if it would not actually validate.
* Instead, the diagnostics that `assertError` would have reported are
* attached as notes to the malformed error. Thus, a malformed
@@ -46,7 +46,7 @@ harden(getErrorConstructor);
export const ErrorHelper = harden({
styleName: 'error',
- canBeValid: (candidate, check = x => x) => {
+ canBeValid: (candidate, check) => {
// TODO: Need a better test than instanceof
if (!(candidate instanceof Error)) {
return check(false, X`Error expected: ${candidate}`);

MODIFY
packages/marshal/src/helpers/internal-types.js
packages/marshal/src/helpers/internal-types.js
@@ -23,7 +23,7 @@ export {};
*
* @property {PassStyle} styleName
*
- * @property {(candidate: any, check?: Checker) => boolean} canBeValid
+ * @property {(candidate: any, check: Checker) => boolean} canBeValid
* If `canBeValid` returns true, then the candidate would
* definitely not be valid for any of the other helpers.
* `assertValid` still needs to be called to determine if it

MODIFY
packages/marshal/src/helpers/passStyle-helpers.js
packages/marshal/src/helpers/passStyle-helpers.js
@@ -57,17 +57,17 @@ harden(assertChecker);
/**
* @param {Object} candidate
* @param {string|number|symbol} propertyName
- * @param {string=} nameType
- * @param {boolean=} shouldBeEnumerable
- * @param {Checker=} check
+ * @param {string} nameType
+ * @param {boolean} shouldBeEnumerable
+ * @param {Checker} check
* @returns {boolean}
*/
export const checkNormalProperty = (
candidate,
propertyName,
- nameType = undefined,
- shouldBeEnumerable = true,
- check = x => x,
+ nameType,
+ shouldBeEnumerable,
+ check,
) => {
const desc = getOwnPropertyDescriptor(candidate, propertyName);
if (desc === undefined) {
@@ -106,10 +106,10 @@ harden(getTag);
/**
* @param {{ [PASS_STYLE]: string }} tagRecord
* @param {PassStyle} passStyle
- * @param {Checker} [check]
+ * @param {Checker} check
* @returns {boolean}
*/
-export const checkTagRecord = (tagRecord, passStyle, check = x => x) => {
+export const checkTagRecord = (tagRecord, passStyle, check) => {
return (
check(
typeof tagRecord === 'object' && tagRecord !== null,

MODIFY
packages/marshal/src/helpers/remotable.js
packages/marshal/src/helpers/remotable.js
@@ -31,9 +31,9 @@ const {
/**
* @param {InterfaceSpec} iface
- * @param {Checker=} check
+ * @param {Checker} check
*/
-const checkIface = (iface, check = x => x) => {
+const checkIface = (iface, check) => {
return (
// TODO other possible ifaces, once we have third party veracity
check(
@@ -64,10 +64,10 @@ harden(assertIface);
/**
* @param {any} original
- * @param {Checker} [check]
+ * @param {Checker} check
* @returns {boolean}
*/
-const checkRemotableProtoOf = (original, check = x => x) => {
+const checkRemotableProtoOf = (original, check) => {
// A valid remotable object must inherit from a "tag record" -- a
// plain-object prototype consisting of only
// a suitable `PASS_STYLE` property and a suitable `Symbol.toStringTag`
@@ -153,10 +153,10 @@ const checkRemotableProtoOf = (original, check = x => x) => {
/**
* @param {Remotable} val
- * @param {Checker} [check]
+ * @param {Checker} check
* @returns {boolean}
*/
-const checkRemotable = (val, check = x => x) => {
+const checkRemotable = (val, check) => {
const not = (cond, details) => !check(cond, details);
if (not(isFrozen(val), X`cannot serialize non-frozen objects like ${val}`)) {
return false;
@@ -168,6 +168,8 @@ const checkRemotable = (val, check = x => x) => {
return checkRemotableProtoOf(val, check);
};
+const isRemotable = val => checkRemotable(val, x => x);
+
/** @type {MarshalGetInterfaceOf} */
export const getInterfaceOf = val => {
const typestr = typeof val;
@@ -175,7 +177,7 @@ export const getInterfaceOf = val => {
(typestr !== 'object' && typestr !== 'function') ||
val === null ||
val[PASS_STYLE] !== 'remotable' ||
- !checkRemotable(val)
+ !isRemotable(val)
) {
return undefined;
}
@@ -190,7 +192,7 @@ harden(getInterfaceOf);
export const RemotableHelper = harden({
styleName: 'remotable',
- canBeValid: (candidate, check = x => x) => {
+ canBeValid: (candidate, check) => {
if (
!(
check(

MODIFY
packages/marshal/src/helpers/safe-promise.js
packages/marshal/src/helpers/safe-promise.js
@@ -13,10 +13,10 @@ const { ownKeys } = Reflect;
/**
* @param {Promise} pr The value to examine
- * @param {Checker} [check]
+ * @param {Checker} check
* @returns {pr is Promise} Whether it is a safe promise
*/
-const checkPromiseOwnKeys = (pr, check = x => x) => {
+const checkPromiseOwnKeys = (pr, check) => {
const keys = ownKeys(pr);
const unknownKeys = keys.filter(
@@ -58,10 +58,10 @@ const checkPromiseOwnKeys = (pr, check = x => x) => {
* use it here as well.
*
* @param {unknown} pr The value to examine
- * @param {Checker} [check]
+ * @param {Checker} check
* @returns {pr is Promise} Whether it is a safe promise
*/
-const checkSafePromise = (pr, check = x => x) =>
+const checkSafePromise = (pr, check) =>
check(isFrozen(pr), X`${pr} - Must be frozen`) &&
check(isPromise(pr), X`${pr} - Must be a promise`) &&
check(
@@ -77,7 +77,7 @@ harden(checkSafePromise);
* @param {unknown} pr The value to examine
* @returns {pr is Promise} Whether it is a promise
*/
-export const isSafePromise = pr => checkSafePromise(pr);
+export const isSafePromise = pr => checkSafePromise(pr, x => x);
harden(isSafePromise);
export const assertSafePromise = pr => checkSafePromise(pr, assertChecker);

MODIFY
packages/marshal/src/helpers/tagged.js
packages/marshal/src/helpers/tagged.js
@@ -20,8 +20,7 @@ const { getPrototypeOf, prototype: objectPrototype } = Object;
export const TaggedHelper = harden({
styleName: 'tagged',
- canBeValid: (candidate, check = x => x) =>
- checkTagRecord(candidate, 'tagged', check),
+ canBeValid: (candidate, check) => checkTagRecord(candidate, 'tagged', check),
assertValid: (candidate, passStyleOfRecur) => {
TaggedHelper.canBeValid(candidate, assertChecker);

MODIFY
packages/marshal/src/passStyleOf.js
packages/marshal/src/passStyleOf.js
@@ -169,7 +169,7 @@ const makePassStyleOf = passStyleHelpers => {
return /** @type {PassStyle} */ (passStyleTag);
}
for (const helper of passStyleHelpers) {
- if (helper.canBeValid(inner)) {
+ if (helper.canBeValid(inner, x => x)) {
helper.assertValid(inner, passStyleOfRecur);
return helper.styleName;
}

fix: bad check defaults (#1274)