Skip to content

Commit 642154e

Browse files
committed
fixup! make shim opt-in via process.env
1 parent c9b61ee commit 642154e

File tree

5 files changed

+31
-6
lines changed

5 files changed

+31
-6
lines changed

packages/non-trapping-shim/package.json

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"module": "./index.js",
2121
"exports": {
2222
"./shim.js": "./shim.js",
23+
"./prepare-enable-shim.js": "./prepare-enable-shim.js",
2324
"./package.json": "./package.json"
2425
},
2526
"scripts": {
@@ -35,6 +36,9 @@
3536
"test:c8": "c8 $C8_OPTIONS ava --config=ava-nesm.config.js",
3637
"test:xs": "exit 0"
3738
},
39+
"dependencies": {
40+
"@endo/env-options": "^1.1.8"
41+
},
3842
"devDependencies": {
3943
"ava": "^6.1.3",
4044
"c8": "^7.14.0",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* global globalThis */
2+
3+
// TODO consider adding env option setting APIs to @endo/env-options
4+
// TODO should set up globalThis.process.env if absent
5+
const env = (globalThis.process || {}).env || {};
6+
7+
env.SES_NON_TRAPPING_SHIM = 'enabled';

packages/non-trapping-shim/shim.js

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
/* global globalThis */
2+
import { getEnvironmentOption } from '@endo/env-options';
23
import { ReflectPlus, ObjectPlus, ProxyPlus } from './src/non-trapping-pony.js';
34

4-
globalThis.Reflect = ReflectPlus;
5+
const nonTrappingShimOption = getEnvironmentOption(
6+
'SES_NON_TRAPPING_SHIM',
7+
'disabled',
8+
['enabled'],
9+
);
510

6-
globalThis.Object = ObjectPlus;
7-
// eslint-disable-next-line no-extend-native
8-
Object.prototype.constructor = ObjectPlus;
11+
if (nonTrappingShimOption === 'enabled') {
12+
// TODO figure this out, either remove directive or change to
13+
// at-ts-expect-error.
14+
// @ts-ignore type of ReflectPlus vs Reflect, I think
15+
globalThis.Reflect = ReflectPlus;
916

10-
globalThis.Proxy = ProxyPlus;
17+
globalThis.Object = ObjectPlus;
18+
// eslint-disable-next-line no-extend-native
19+
Object.prototype.constructor = ObjectPlus;
20+
21+
globalThis.Proxy = ProxyPlus;
22+
}

packages/non-trapping-shim/test/non-trapping-shim.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import '../prepare-enable-shim.js';
12
// Uses 'ava' rather than @endo/ses-ava to avoid worries about cyclic
23
// dependencies. We will need similar tests is higher level packages, in order
34
// to test compat with ses and ses-ava.

yarn.lock

+2-1
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ __metadata:
403403
languageName: unknown
404404
linkType: soft
405405

406-
"@endo/env-options@workspace:^, @endo/env-options@workspace:packages/env-options":
406+
"@endo/env-options@npm:^1.1.8, @endo/env-options@workspace:^, @endo/env-options@workspace:packages/env-options":
407407
version: 0.0.0-use.local
408408
resolution: "@endo/env-options@workspace:packages/env-options"
409409
dependencies:
@@ -706,6 +706,7 @@ __metadata:
706706
version: 0.0.0-use.local
707707
resolution: "@endo/non-trapping-shim@workspace:packages/non-trapping-shim"
708708
dependencies:
709+
"@endo/env-options": "npm:^1.1.8"
709710
ava: "npm:^6.1.3"
710711
c8: "npm:^7.14.0"
711712
tsd: "npm:^0.31.2"

0 commit comments

Comments
 (0)