Skip to content

Commit f5d2c57

Browse files
committed
fixup! review suggestions
1 parent 147e6b0 commit f5d2c57

File tree

6 files changed

+40
-39
lines changed

6 files changed

+40
-39
lines changed

packages/captp/src/trap.js

+18-12
Original file line numberDiff line numberDiff line change
@@ -58,27 +58,33 @@ const TrapProxyHandler = (x, trapImpl) => {
5858
});
5959
};
6060

61+
/**
62+
* `freeze` but not `harden` the proxy target so it remains trapping.
63+
* Thus, it should not be shared outside this module.
64+
*
65+
* @see https://github.com/endojs/endo/blob/master/packages/ses/docs/preparing-for-stabilize.md
66+
*/
67+
const funcTarget = freeze(() => {});
68+
69+
/**
70+
* `freeze` but not `harden` the proxy target so it remains trapping.
71+
* Thus, it should not be shared outside this module.
72+
*
73+
* @see https://github.com/endojs/endo/blob/master/packages/ses/docs/preparing-for-stabilize.md
74+
*/
75+
const objTarget = freeze({ __proto__: null });
76+
6177
/**
6278
* @param {import('./types.js').TrapImpl} trapImpl
6379
* @returns {import('./ts-types.js').Trap}
6480
*/
6581
export const makeTrap = trapImpl => {
6682
const Trap = x => {
67-
/**
68-
* `freeze` but not `harden` the proxy target so it remains trapping.
69-
* @see https://github.com/endojs/endo/blob/master/packages/ses/docs/preparing-for-stabilize.md
70-
*/
71-
const target = freeze(() => {});
7283
const handler = TrapProxyHandler(x, trapImpl);
73-
return new Proxy(target, handler);
84+
return new Proxy(funcTarget, handler);
7485
};
7586

7687
const makeTrapGetterProxy = x => {
77-
/**
78-
* `freeze` but not `harden` the proxy target so it remains trapping.
79-
* @see https://github.com/endojs/endo/blob/master/packages/ses/docs/preparing-for-stabilize.md
80-
*/
81-
const target = freeze(Object.create(null));
8288
const handler = harden({
8389
...baseFreezableProxyHandler,
8490
has(_target, _prop) {
@@ -89,7 +95,7 @@ export const makeTrap = trapImpl => {
8995
return trapImpl.get(x, prop);
9096
},
9197
});
92-
return new Proxy(target, handler);
98+
return new Proxy(objTarget, handler);
9399
};
94100
Trap.get = makeTrapGetterProxy;
95101

packages/eventual-send/src/E.js

+5-20
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { trackTurns } from './track-turns.js';
22
import { makeMessageBreakpointTester } from './message-breakpoints.js';
33

44
const { details: X, quote: q, Fail, error: makeError } = assert;
5-
const { assign, create, freeze } = Object;
5+
const { assign, freeze } = Object;
66

77
/**
88
* @import { HandledPromiseConstructor } from './types.js';
@@ -169,35 +169,20 @@ const makeEGetProxyHandler = (x, HandledPromise) =>
169169

170170
/**
171171
* `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.
172+
* Thus, it should not be shared outside this module.
181173
*
182174
* @see https://github.com/endojs/endo/blob/master/packages/ses/docs/preparing-for-stabilize.md
183175
*/
184176
const funcTarget = freeze(() => {});
185177

178+
/**
186179
/**
187180
* `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.
181+
* Thus, it should not be shared outside this module.
197182
*
198183
* @see https://github.com/endojs/endo/blob/master/packages/ses/docs/preparing-for-stabilize.md
199184
*/
200-
const objTarget = freeze(create(null));
185+
const objTarget = freeze({ __proto__: null });
201186

202187
/**
203188
* @param {HandledPromiseConstructor} HandledPromise

packages/marshal/src/marshal-stringify.js

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ const badArrayHandler = harden({
2727

2828
/**
2929
* `freeze` but not `harden` the proxy target so it remains trapping.
30+
* Thus, it should not be shared outside this module.
31+
*
3032
* @see https://github.com/endojs/endo/blob/master/packages/ses/docs/preparing-for-stabilize.md
3133
*/
3234
const arrayTarget = freeze(/** @type {any[]} */ ([]));

packages/ses/docs/preparing-for-stabilize.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,18 @@ Draft PR [feat(ses,pass-style): use non-trapping integrity trait for safety #267
1313

1414
## How proxy code should prepare
1515

16-
[#2673](https://github.com/endojs/endo/pull/2673) will *by default* produce proxies that refuse to be made non-trapping. An explicit handler trap (whose name is TBD) will need to be explicitly provided to make a proxy that allows itself to be made non-trapping. This is the right default, because proxies on frozen almost-empty objects can still have useful trap behavior for their `get`, `set`, `has`, and `apply` traps. Even on a frozen target
17-
- The `get`, `set`, and `has` traps applied to a non-own property name are still general traps that can have useful trapping behavior.
18-
- The `apply` trap can ignore the target's call behavior and just do its own thing.
16+
[#2673](https://github.com/endojs/endo/pull/2673) will *by default* produce proxies that refuse to be made non-trapping. An explicit handler trap (perhaps named `stabilize` or `suppressTrapping`) will need to be explicitly provided to make a proxy that allows itself to be made non-trapping. This is the right default, because proxies on frozen almost-empty objects can still have useful trap behavior for their `get`, `set`, `has`, and `apply` traps. Even on a frozen target
17+
- the `get`, `set`, and `has` traps applied to a non-own property name are still general traps that can have useful trapping behavior.
18+
- the `apply` trap can ignore the target's call behavior and just do its own thing.
1919

2020
However, to prepare for these changes, we need to avoid hardening both such proxies and their targets. We need to avoid hardening their target because this will bypass the traps. We need to avoid hardening the proxy because such proxies will *by default* refuse to be made non-trapping, and thus refuse to be hardened.
2121

22+
Some proxies, such as that returned by `E(...)`, exist only to provide such trapping behavior. Their targets will typically be trivial useless empty frozen objects or almost empty frozen functions. Such frozen targets can be safely shared between multiple proxy instances because they are encapsulated within the proxy.
23+
- Before `stabilize`/`suppressTrapping`, this is safe because they are already frozen, and so they cannot be damaged by the proxies that encapsulate them.
24+
- After `stabilize`/`suppressTrapping`, this is safe because the only damage that could be done would be by `stabilize`/`suppressTrapping`. These proxies do not explicitly provide such a trap, and thus will use the default behavior which is to refuse to be made non-trapping.
25+
26+
Because such trivial targets, when safely encapsulated, can be safely shared, their definitions should typically appear at top level of their module.
27+
2228
## How passable objects should prepare
2329

2430
Although we think of `passStyleOf` as requiring its input to be hardened, `passStyleOf` instead checked that each relevant object is frozen. Manually freezing all objects reachable from a root object had been equivalent to hardening that root object. With these changes, even such manual transitive freezing will not make an object passable. To prepare for these changes, use `harden` explicitly instead.

packages/ses/src/sloppy-globals-scope-terminator.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ import {
1313
/**
1414
* `freeze` but not `harden` the proxy target so it remains trapping.
1515
* Thus, it should not be shared outside this module.
16+
*
1617
* @see https://github.com/endojs/endo/blob/master/packages/ses/docs/preparing-for-stabilize.md
1718
*/
18-
const onlyFrozenObject = freeze(create(null));
19+
const objTarget = freeze({ __proto__: null });
1920

2021
/*
2122
* createSloppyGlobalsScopeTerminator()
@@ -51,7 +52,7 @@ export const createSloppyGlobalsScopeTerminator = globalObject => {
5152
);
5253

5354
const sloppyGlobalsScopeTerminator = new Proxy(
54-
onlyFrozenObject,
55+
objTarget,
5556
sloppyGlobalsScopeTerminatorHandler,
5657
);
5758

packages/ses/src/strict-scope-terminator.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ const { Fail, quote: q } = assert;
1515
/**
1616
* `freeze` but not `harden` the proxy target so it remains trapping.
1717
* Thus, it should not be shared outside this module.
18+
*
1819
* @see https://github.com/endojs/endo/blob/master/packages/ses/docs/preparing-for-stabilize.md
1920
*/
20-
const onlyFrozenObject = freeze(create(null));
21+
const objTarget = freeze({ __proto__: null });
2122

2223
/**
2324
* alwaysThrowHandler
@@ -27,7 +28,7 @@ const onlyFrozenObject = freeze(create(null));
2728
* create one and share it between all Proxy handlers.
2829
*/
2930
export const alwaysThrowHandler = new Proxy(
30-
onlyFrozenObject,
31+
objTarget,
3132
freeze({
3233
get(_shadow, prop) {
3334
Fail`Please report unexpected scope handler trap: ${q(String(prop))}`;

0 commit comments

Comments
 (0)