Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: somewhat tighter test for plain empty object #1981

Merged
merged 1 commit into from
Nov 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion packages/ERTP/src/displayInfo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { assert, details, q } from '@agoric/assert';
import { pureCopy, passStyleOf, REMOTE_STYLE } from '@agoric/marshal';
import {
pureCopy,
passStyleOf,
REMOTE_STYLE,
getInterfaceOf,
} from '@agoric/marshal';

// TODO: assertSubset and assertKeysAllowed are copied from Zoe. Move
// this code to a location where it can be used by ERTP and Zoe
Expand Down Expand Up @@ -44,6 +49,18 @@ export const assertDisplayInfo = allegedDisplayInfo => {

export const coerceDisplayInfo = allegedDisplayInfo => {
if (passStyleOf(allegedDisplayInfo) === REMOTE_STYLE) {
// These condition together try to ensure that `allegedDisplayInfo`
// is a plain empty object. It will accept all plain empty objects
// that it should. It will reject most things we want to reject including
// remotables that are explicitly declared `Remotable`. But a normal
// HandledPromise presence not explicitly declared `Remotable` will
// be mistaken for a plain empty object. Even in this case, the copy
// has a new identity, so the only danger is that we didn't reject
// with a diagnostic, potentially masking a programmer error.
assert(Object.isFrozen(allegedDisplayInfo));
assert.equal(Reflect.ownKeys(allegedDisplayInfo).length, 0);
assert.equal(Object.getPrototypeOf(allegedDisplayInfo), Object.prototype);
assert.equal(getInterfaceOf(allegedDisplayInfo), undefined);
return harden({});
}
allegedDisplayInfo = pureCopy(allegedDisplayInfo);
Expand Down