fix: Patterns and Keys
MODIFY
index.js
index.js
@@ -4,6 +4,7 @@ export {
isObject,
assertChecker,
getTag,
+ hasOwnPropertyOf,
} from './src/helpers/passStyle-helpers.js';
export { getErrorConstructor, toPassableError } from './src/helpers/error.js';
@@ -17,12 +18,7 @@ export {
passableSymbolForName,
} from './src/helpers/symbol.js';
-export {
- passStyleOf,
- assertPassable,
- everyPassableChild,
- somePassableChild,
-} from './src/passStyleOf.js';
+export { passStyleOf, assertPassable } from './src/passStyleOf.js';
export { pureCopy, sameValueZero } from './src/pureCopy.js';
export { deeplyFulfilled } from './src/deeplyFulfilled.js';

MODIFY
src/assertPassStyleOf.js
src/assertPassStyleOf.js
@@ -4,19 +4,11 @@ import { passStyleOf } from './passStyleOf.js';
const { details: X, quote: q } = assert;
-/**
- * @typedef {Array} CopyArray
- */
-
-/**
- * @typedef {Record<string, Passable>} CopyRecord
- */
-
/**
* Check whether the argument is a pass-by-copy array, AKA a "copyArray"
* in @agoric/marshal terms
*
- * @param {CopyArray} array
+ * @param {CopyArray<any>} array
* @returns {boolean}
*/
const isCopyArray = array => passStyleOf(array) === 'copyArray';
@@ -26,7 +18,7 @@ harden(isCopyArray);
* Check whether the argument is a pass-by-copy record, AKA a
* "copyRecord" in @agoric/marshal terms
*
- * @param {CopyRecord} record
+ * @param {CopyRecord<any>} record
* @returns {boolean}
*/
const isRecord = record => passStyleOf(record) === 'copyRecord';
@@ -45,7 +37,7 @@ harden(isRemotable);
* Assert that the argument is a pass-by-copy array, AKA a "copyArray"
* in @agoric/marshal terms
*
- * @param {CopyArray} array
+ * @param {CopyArray<any>} array
* @param {string=} optNameOfArray
* @returns {void}
*/
@@ -64,7 +56,7 @@ harden(assertCopyArray);
* Assert that the argument is a pass-by-copy record, or a
* "copyRecord" in @agoric/marshal terms
*
- * @param {CopyRecord} record
+ * @param {CopyRecord<any>} record
* @param {string=} optNameOfRecord
* @returns {void}
*/

MODIFY
src/helpers/copyArray.js
src/helpers/copyArray.js
@@ -44,11 +44,6 @@ export const CopyArrayHelper = harden({
TypeError,
);
// Recursively validate that each member is passable.
- CopyArrayHelper.every(candidate, v => !!passStyleOfRecur(v));
+ candidate.every(v => !!passStyleOfRecur(v));
},
-
- every: (passable, fn) =>
- // Note that we explicitly call `fn` with only the arguments we want
- // to provide.
- passable.every((v, i) => fn(v, i)),
});

MODIFY
src/helpers/copyRecord.js
src/helpers/copyRecord.js
@@ -18,7 +18,6 @@ const { ownKeys } = Reflect;
const {
getPrototypeOf,
getOwnPropertyDescriptors,
- entries,
prototype: objectPrototype,
} = Object;
@@ -62,11 +61,6 @@ export const CopyRecordHelper = harden({
checkNormalProperty(candidate, name, 'string', true, assertChecker);
}
// Recursively validate that each member is passable.
- CopyRecordHelper.every(candidate, v => !!passStyleOfRecur(v));
+ Object.values(candidate).every(v => !!passStyleOfRecur(v));
},
-
- every: (passable, fn) =>
- // Note that we explicitly call `fn` with only the arguments we want
- // to provide.
- entries(passable).every(([k, v]) => fn(v, k)),
});

MODIFY
src/helpers/error.js
src/helpers/error.js
@@ -95,8 +95,6 @@ export const ErrorHelper = harden({
assertValid: candidate => {
ErrorHelper.canBeValid(candidate, assertChecker);
},
-
- every: (_passable, _fn) => true,
});
/**

MODIFY
src/helpers/internal-types.js
src/helpers/internal-types.js
* @property {(candidate: any,
* passStyleOfRecur: PassStyleOf
* ) => void} assertValid
- *
- * @property {(passable: Passable,
- * fn: (passable: Passable, index: any) => boolean
- * ) => boolean} every
- * For recuring through the nested passable structure. Like
- * `Array.prototype.every`, return `false` to stop early.
*/

MODIFY
src/helpers/tagged.js
src/helpers/tagged.js
@@ -51,8 +51,6 @@ export const TaggedHelper = harden({
checkNormalProperty(candidate, 'payload', 'string', true, assertChecker);
// Recursively validate that each member is passable.
- TaggedHelper.every(candidate, v => !!passStyleOfRecur(v));
+ !!passStyleOfRecur(candidate.payload);
},
-
- every: (passable, fn) => fn(passable.payload, 'payload'),
});

MODIFY
src/passStyleOf.js
src/passStyleOf.js
@@ -28,9 +28,9 @@ const { isFrozen } = Object;
* does what it is supposed to do. `makePassStyleOf` is not trying to defend
* itself against malicious helpers, though it does defend against some
* accidents.
- * @returns {{passStyleOf: PassStyleOf, HelperTable: any}}
+ * @returns {PassStyleOf}
*/
-const makePassStyleOfKit = passStyleHelpers => {
+const makePassStyleOf = passStyleHelpers => {
const HelperTable = {
__proto__: null,
copyArray: undefined,
@@ -179,35 +179,18 @@ const makePassStyleOfKit = passStyleHelpers => {
return passStyleOfRecur(passable);
};
- return harden({ passStyleOf, HelperTable });
+ return harden(passStyleOf);
};
-const { passStyleOf, HelperTable } = makePassStyleOfKit([
+export const passStyleOf = makePassStyleOf([
CopyArrayHelper,
CopyRecordHelper,
TaggedHelper,
RemotableHelper,
ErrorHelper,
]);
-export { passStyleOf };
export const assertPassable = val => {
passStyleOf(val); // throws if val is not a passable
};
harden(assertPassable);
-
-export const everyPassableChild = (passable, fn) => {
- const passStyle = passStyleOf(passable);
- const helper = HelperTable[passStyle];
- if (helper) {
- // everyPassable guards .every so that each helper only gets a
- // genuine passable of its own flavor.
- return helper.every(passable, fn);
- }
- return true;
-};
-harden(everyPassableChild);
-
-export const somePassableChild = (passable, fn) =>
- !everyPassableChild(passable, (v, i) => !fn(v, i));
-harden(somePassableChild);

MODIFY
src/types.js
src/types.js
* The leaves of a Passable's pass-by-copy superstructure.
*/
+/**
+ * @template T
+ * @typedef {T[]} CopyArray
+ */
+
+/**
+ * @template T
+ * @typedef {Record<string, T>} CopyRecord
+ */
+
/**
* @typedef {{
* [PASS_STYLE]: 'tagged',

fix: Patterns and Keys (#4210)