-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(store): reject empty-object keys which might not retain identity
When #2018 changes the interpretation of `harden({})` to become pass-by-copy, any code which was previously using that to make a "handle" will break, because the things they send will be treated as pass-by-copy. To catch cases where this is happening, we forbid such keys from being used in store/weakstore. Clients should use `Far('interfacename')` to create handles, and these will be accepted by store/weakstore as keys.
- Loading branch information
Showing
5 changed files
with
81 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// @ts-check | ||
|
||
import { getInterfaceOf } from '@agoric/marshal'; | ||
|
||
/** | ||
* Helper function to reject keys which are empty objects but not marked as | ||
* Remotable. This is intended to catch code which uses harden({}) (which | ||
* will become pass-by-copy, see #2018) as a "handle" or "marker object" | ||
* when they should have used Far(). | ||
* | ||
* @param { unknown } key | ||
*/ | ||
export function isEmptyNonRemotableObject(key) { | ||
return ( | ||
typeof key === 'object' && | ||
key !== null && | ||
Reflect.ownKeys(key).length === 0 && | ||
getInterfaceOf(key) === undefined | ||
); | ||
} | ||
harden(isEmptyNonRemotableObject); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters