Skip to content

Commit eff15a4

Browse files
erightskatelynsills
authored andcommitted
fix: somewhat tighter test for plain empty object (#1981)
1 parent 65952d4 commit eff15a4

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

packages/ERTP/src/displayInfo.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { assert, details, q } from '@agoric/assert';
2-
import { pureCopy, passStyleOf, REMOTE_STYLE } from '@agoric/marshal';
2+
import {
3+
pureCopy,
4+
passStyleOf,
5+
REMOTE_STYLE,
6+
getInterfaceOf,
7+
} from '@agoric/marshal';
38

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

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

0 commit comments

Comments
 (0)