@agoric/internal
Advanced tools
Comparing version 0.2.2-dev-7844f69.0 to 0.2.2-dev-7897761.0
{ | ||
"name": "@agoric/internal", | ||
"version": "0.2.2-dev-7844f69.0+7844f69", | ||
"version": "0.2.2-dev-7897761.0+7897761", | ||
"description": "Externally unsupported utilities internal to agoric-sdk", | ||
@@ -39,3 +39,3 @@ "type": "module", | ||
}, | ||
"gitHead": "7844f693d638ea823e076589bf808309d242fd3c" | ||
"gitHead": "7897761d6e19e6bbba42e7bd0bd5befb507afa08" | ||
} |
@@ -6,3 +6,3 @@ export function fromUniqueEntries<K, V>(allEntries: Iterable<[K, V]>): {}; | ||
export function applyLabelingError<A, R>(func: (...args: A[]) => R, args: A[], label?: string | number | undefined): R; | ||
export function getMethodNames(obj: Record<string | symbol, unknown>): (string | symbol)[]; | ||
export function getMethodNames(val: any): (string | symbol)[]; | ||
export function bindAllMethods(obj: Remotable): Remotable; | ||
@@ -9,0 +9,0 @@ /** |
@@ -7,3 +7,9 @@ import { E } from '@endo/eventual-send'; | ||
const { getPrototypeOf, create, entries, fromEntries } = Object; | ||
const { | ||
getPrototypeOf, | ||
create, | ||
entries, | ||
fromEntries, | ||
getOwnPropertyDescriptors, | ||
} = Object; | ||
const { ownKeys, apply } = Reflect; | ||
@@ -148,26 +154,49 @@ | ||
/** | ||
* @param {unknown} a | ||
* @param {unknown} b | ||
* Prioritize symbols as earlier than strings. | ||
* | ||
* @param {string|symbol} a | ||
* @param {string|symbol} b | ||
* @returns {-1 | 0 | 1} | ||
*/ | ||
const compareStringified = (a, b) => { | ||
const left = String(a); | ||
const right = String(b); | ||
// eslint-disable-next-line no-nested-ternary | ||
return left < right ? -1 : left > right ? 1 : 0; | ||
if (typeof a === typeof b) { | ||
const left = String(a); | ||
const right = String(b); | ||
// eslint-disable-next-line no-nested-ternary | ||
return left < right ? -1 : left > right ? 1 : 0; | ||
} | ||
if (typeof a === 'symbol') { | ||
assert(typeof b === 'string'); | ||
return -1; | ||
} | ||
assert(typeof a === 'string'); | ||
assert(typeof b === 'symbol'); | ||
return 1; | ||
}; | ||
/** | ||
* @param {Record<string | symbol, unknown>} obj | ||
* TODO Consolidate with the `getMethodNames` in `@endo/eventual-send` | ||
* | ||
* @param {any} val | ||
* @returns {(string|symbol)[]} | ||
*/ | ||
export const getMethodNames = obj => { | ||
const result = []; | ||
while (obj !== null && obj !== Object.prototype) { | ||
const mNames = ownKeys(obj).filter(name => typeof obj[name] === 'function'); | ||
result.push(...mNames); | ||
obj = getPrototypeOf(obj); | ||
export const getMethodNames = val => { | ||
let layer = val; | ||
const names = new Set(); // Set to deduplicate | ||
while (layer !== null && layer !== Object.prototype) { | ||
// be tolerant of non-objects | ||
const descs = getOwnPropertyDescriptors(layer); | ||
for (const name of ownKeys(descs)) { | ||
// In case a method is overridden by a non-method, | ||
// test `val[name]` rather than `layer[name]` | ||
if (typeof val[name] === 'function') { | ||
names.add(name); | ||
} | ||
} | ||
if (!isObject(val)) { | ||
break; | ||
} | ||
layer = getPrototypeOf(layer); | ||
} | ||
result.sort(compareStringified); | ||
return harden(result); | ||
return harden([...names].sort(compareStringified)); | ||
}; | ||
@@ -174,0 +203,0 @@ harden(getMethodNames); |
Sorry, the diff of this file is not supported yet
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
31386
446