Skip to content

Commit e8ac65b

Browse files
committed
fixup! review suggestions
1 parent c14e776 commit e8ac65b

File tree

2 files changed

+76
-13
lines changed

2 files changed

+76
-13
lines changed

packages/eventual-send/src/E.js

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -167,20 +167,42 @@ const makeEGetProxyHandler = (x, HandledPromise) =>
167167
get: (_target, prop) => HandledPromise.get(x, prop),
168168
});
169169

170+
/**
171+
* `freeze` but not `harden` the proxy target so it remains trapping.
172+
* This is safe to share between proxy instances because they are encapsulated
173+
* within the proxy.
174+
* - Before stabilize/suppressTrapping, this is safe
175+
* because they are already frozen, and so they cannot be damaged by the
176+
* proxies that encapsulate them.
177+
* - After stabilize/suppressTrapping, this is safe because the only damage
178+
* that could be done would be by stabilize/suppressTrapping. These proxies
179+
* do not explicitly provide such a trap, and thus will use the default
180+
* behavior which is to refuse to be made non-trapping.
181+
*
182+
* @see https://github.com/endojs/endo/blob/master/packages/ses/docs/preparing-for-stabilize.md
183+
*/
184+
const funcTarget = freeze(() => {});
185+
186+
/**
187+
* `freeze` but not `harden` the proxy target so it remains trapping.
188+
* This is safe to share between proxy instances because they are encapsulated
189+
* within the proxy.
190+
* - Before stabilize/suppressTrapping, this is safe
191+
* because they are already frozen, and so they cannot be damaged by the
192+
* proxies that encapsulate them.
193+
* - After stabilize/suppressTrapping, this is safe because the only damage
194+
* that could be done would be by stabilize/suppressTrapping. These proxies
195+
* do not explicitly provide such a trap, and thus will use the default
196+
* behavior which is to refuse to be made non-trapping.
197+
*
198+
* @see https://github.com/endojs/endo/blob/master/packages/ses/docs/preparing-for-stabilize.md
199+
*/
200+
const objTarget = freeze(create(null));
201+
170202
/**
171203
* @param {HandledPromiseConstructor} HandledPromise
172204
*/
173205
const makeE = HandledPromise => {
174-
/**
175-
* `freeze` but not `harden` the proxy target so it remains trapping.
176-
* @see https://github.com/endojs/endo/blob/master/packages/ses/docs/preparing-for-stabilize.md
177-
*/
178-
const funcTarget = freeze(() => {});
179-
/**
180-
* `freeze` but not `harden` the proxy target so it remains trapping.
181-
* @see https://github.com/endojs/endo/blob/master/packages/ses/docs/preparing-for-stabilize.md
182-
*/
183-
const objTarget = freeze(create(null));
184206
return harden(
185207
assign(
186208
/**

packages/pass-style/test/passStyleOf.test.js

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,17 @@ test('some passStyleOf rejections', t => {
110110
});
111111

112112
/**
113-
* For testing purposes, makes a TagRecord-like object with
113+
* For testing purposes, makes a *non-frozen* TagRecord-like object with
114114
* non-enumerable PASS_STYLE and Symbol.toStringTag properties.
115115
* A valid Remotable must inherit from a valid TagRecord.
116+
* - Before stabilize/suppressTrapping, a valid TagRecord must be frozen.
117+
* - After stabilize/suppressTrapping, a valid TagRecord must also be
118+
* stable/non-trapping, for example, because it was hardened.
116119
*
117120
* @param {string} [tag]
118121
* @param {object|null} [proto]
119122
* @returns {{ [PASS_STYLE]: 'remotable', [Symbol.toStringTag]: string }}
123+
* @see https://github.com/endojs/endo/blob/master/packages/ses/docs/preparing-for-stabilize.md
120124
*/
121125
const makeTagishRecord = (tag = 'Remotable', proto = undefined) => {
122126
return Object.create(proto === undefined ? Object.prototype : proto, {
@@ -193,16 +197,21 @@ test('passStyleOf testing remotables', t => {
193197

194198
const tagRecord1 = harden(makeTagishRecord('Alleged: manually constructed'));
195199
/** @type {any} UNTIL https://github.com/microsoft/TypeScript/issues/38385 */
200+
// TODO Once we have support for explicit non-trapping, this should change
201+
// from `harden` to `suppressTrapping` or `stabilize`.
196202
const farObj1 = harden({ __proto__: tagRecord1 });
197203
t.is(passStyleOf(farObj1), 'remotable');
198204

199205
const tagRecord2 = makeTagishRecord('Alleged: tagRecord not hardened');
200206
/**
207+
* Do not freeze `tagRecord2` in order to test that an object with
208+
* a non-frozen __proto__ is not passable.
209+
*
201210
* TODO In order to run this test before we have explicit support for a
202211
* non-trapping integrity trait, we have to `freeze` here but not `harden`.
203212
* However, once we do have that support, and `passStyleOf` checks that
204213
* its argument is also non-trapping, we still need to avoid `harden`
205-
* because that would also hardden `__proto__`. So we will need to
214+
* because that would also harden `__proto__`. So we will need to
206215
* explicitly make this non-trapping, which we cannot yet express.
207216
* @see https://github.com/endojs/endo/blob/master/packages/ses/docs/preparing-for-stabilize.md
208217
*
@@ -220,24 +229,34 @@ test('passStyleOf testing remotables', t => {
220229

221230
const tagRecord3 = harden(makeTagishRecord('Alleged: both manually frozen'));
222231
/** @type {any} UNTIL https://github.com/microsoft/TypeScript/issues/38385 */
232+
// TODO Once we have support for explicit non-trapping, this should change
233+
// from `harden` to `suppressTrapping` or `stabilize`.
223234
const farObj3 = harden({ __proto__: tagRecord3 });
224235
t.is(passStyleOf(farObj3), 'remotable');
225236

226237
const tagRecord4 = harden(makeTagishRecord('Remotable'));
227238
/** @type {any} UNTIL https://github.com/microsoft/TypeScript/issues/38385 */
239+
// TODO Once we have support for explicit non-trapping, this should change
240+
// from `harden` to `suppressTrapping` or `stabilize`.
228241
const farObj4 = harden({ __proto__: tagRecord4 });
229242
t.is(passStyleOf(farObj4), 'remotable');
230243

231244
const tagRecord5 = harden(makeTagishRecord('Not alleging'));
245+
// TODO Once we have support for explicit non-trapping, this should change
246+
// from `harden` to `suppressTrapping` or `stabilize`.
232247
const farObj5 = harden({ __proto__: tagRecord5 });
233248
t.throws(() => passStyleOf(farObj5), {
234249
message:
235250
/For now, iface "Not alleging" must be "Remotable" or begin with "Alleged: " or "DebugName: "; unimplemented/,
236251
});
237252

238253
const tagRecord6 = harden(makeTagishRecord('Alleged: manually constructed'));
254+
// TODO Once we have support for explicit non-trapping, this should change
255+
// from `harden` to `suppressTrapping` or `stabilize`.
239256
const farObjProto6 = harden({ __proto__: tagRecord6 });
240257
/** @type {any} UNTIL https://github.com/microsoft/TypeScript/issues/38385 */
258+
// TODO Once we have support for explicit non-trapping, this should change
259+
// from `harden` to `suppressTrapping` or `stabilize`.
241260
const farObj6 = harden({ __proto__: farObjProto6 });
242261
t.is(passStyleOf(farObj6), 'remotable', 'tagRecord grandproto is accepted');
243262

@@ -292,6 +311,8 @@ test('passStyleOf testing remotables', t => {
292311
const tagRecordA1 = harden(
293312
makeTagishRecord('Alleged: null-proto tagRecord proto', null),
294313
);
314+
// TODO Once we have support for explicit non-trapping, this should change
315+
// from `harden` to `suppressTrapping` or `stabilize`.
295316
const farObjA1 = harden({ __proto__: tagRecordA1 });
296317
t.throws(
297318
() => passStyleOf(farObjA1),
@@ -302,7 +323,11 @@ test('passStyleOf testing remotables', t => {
302323
const tagRecordA2 = harden(
303324
makeTagishRecord('Alleged: null-proto tagRecord grandproto', null),
304325
);
326+
// TODO Once we have support for explicit non-trapping, this should change
327+
// from `harden` to `suppressTrapping` or `stabilize`.
305328
const farObjProtoA2 = harden({ __proto__: tagRecordA2 });
329+
// TODO Once we have support for explicit non-trapping, this should change
330+
// from `harden` to `suppressTrapping` or `stabilize`.
306331
const farObjA2 = harden({ __proto__: farObjProtoA2 });
307332
t.throws(
308333
() => passStyleOf(farObjA2),
@@ -317,7 +342,11 @@ test('passStyleOf testing remotables', t => {
317342
const fauxTagRecordB = harden(
318343
makeTagishRecord('Alleged: manually constructed', harden({})),
319344
);
345+
// TODO Once we have support for explicit non-trapping, this should change
346+
// from `harden` to `suppressTrapping` or `stabilize`.
320347
const farObjProtoB = harden({ __proto__: fauxTagRecordB });
348+
// TODO Once we have support for explicit non-trapping, this should change
349+
// from `harden` to `suppressTrapping` or `stabilize`.
321350
const farObjB = harden({ __proto__: farObjProtoB });
322351
t.throws(() => passStyleOf(farObjB), {
323352
message:
@@ -329,6 +358,8 @@ test('passStyleOf testing remotables', t => {
329358
);
330359
Object.defineProperty(farObjProtoWithExtra, 'extra', { value: () => {} });
331360
harden(farObjProtoWithExtra);
361+
// TODO Once we have support for explicit non-trapping, this should change
362+
// from `harden` to `suppressTrapping` or `stabilize`.
332363
const badFarObjExtraProtoProp = harden({ __proto__: farObjProtoWithExtra });
333364
t.throws(() => passStyleOf(badFarObjExtraProtoProp), {
334365
message: 'Unexpected properties on Remotable Proto ["extra"]',
@@ -378,11 +409,17 @@ test('remotables - safety from the gibson042 attack', t => {
378409
);
379410

380411
/**
412+
* Do not freeze `mercurialProto` in order to test that an object with
413+
* a non-frozen __proto__ is not passable. Once we have support for
414+
* non-trapping, we should generalize this test (or add a new one) where
415+
* `mercurialProto` is frozen but still trapping. This test would then
416+
* test that a valid TagRecord must be non-trapping.
417+
*
381418
* TODO In order to run this test before we have explicit support for a
382419
* non-trapping integrity trait, we have to `freeze` here but not `harden`.
383420
* However, once we do have that support, and `passStyleOf` checks that
384421
* its argument is also non-trapping, we still need to avoid `harden`
385-
* because that would also hardden `__proto__`. So we will need to
422+
* because that would also harden `__proto__`. So we will need to
386423
* explicitly make this non-trapping, which we cannot yet express.
387424
* @see https://github.com/endojs/endo/blob/master/packages/ses/docs/preparing-for-stabilize.md
388425
*/
@@ -448,12 +485,16 @@ test('Allow toStringTag overrides', t => {
448485
t.is(`${q(alice)}`, '"[DebugName: Allison]"');
449486

450487
/** @type {any} UNTIL https://github.com/microsoft/TypeScript/issues/38385 */
488+
// TODO Once we have support for explicit non-trapping, this should change
489+
// from `harden` to `suppressTrapping` or `stabilize`.
451490
const carol = harden({ __proto__: alice });
452491
t.is(passStyleOf(carol), 'remotable');
453492
t.is(`${carol}`, '[object DebugName: Allison]');
454493
t.is(`${q(carol)}`, '"[DebugName: Allison]"');
455494

456495
/** @type {any} UNTIL https://github.com/microsoft/TypeScript/issues/38385 */
496+
// TODO Once we have support for explicit non-trapping, this should change
497+
// from `harden` to `suppressTrapping` or `stabilize`.
457498
const bob = harden({
458499
__proto__: carol,
459500
[Symbol.toStringTag]: 'DebugName: Robert',

0 commit comments

Comments
 (0)