Skip to content

Commit

Permalink
fixup! make shim opt-in via process.env
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Jan 25, 2025
1 parent c9b61ee commit 2b82131
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
4 changes: 4 additions & 0 deletions packages/non-trapping-shim/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"module": "./index.js",
"exports": {
"./shim.js": "./shim.js",
"./prepare-enable-shim.js": "./prepare-enable-shim.js",
"./package.json": "./package.json"
},
"scripts": {
Expand All @@ -35,6 +36,9 @@
"test:c8": "c8 $C8_OPTIONS ava --config=ava-nesm.config.js",
"test:xs": "exit 0"
},
"dependencies": {
"@endo/env-options": "workspace:^"
},
"devDependencies": {
"ava": "^6.1.3",
"c8": "^7.14.0",
Expand Down
7 changes: 7 additions & 0 deletions packages/non-trapping-shim/prepare-enable-shim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* global globalThis */

// TODO consider adding env option setting APIs to @endo/env-options
// TODO should set up globalThis.process.env if absent
const env = (globalThis.process || {}).env || {};

env.SES_NON_TRAPPING_SHIM = 'enabled';
22 changes: 17 additions & 5 deletions packages/non-trapping-shim/shim.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
/* global globalThis */
import { getEnvironmentOption } from '@endo/env-options';
import { ReflectPlus, ObjectPlus, ProxyPlus } from './src/non-trapping-pony.js';

globalThis.Reflect = ReflectPlus;
const nonTrappingShimOption = getEnvironmentOption(
'SES_NON_TRAPPING_SHIM',
'disabled',
['enabled'],
);

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

globalThis.Proxy = ProxyPlus;
globalThis.Object = ObjectPlus;
// eslint-disable-next-line no-extend-native
Object.prototype.constructor = ObjectPlus;

globalThis.Proxy = ProxyPlus;
}
1 change: 1 addition & 0 deletions packages/non-trapping-shim/test/non-trapping-shim.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import '../prepare-enable-shim.js';
// Uses 'ava' rather than @endo/ses-ava to avoid worries about cyclic
// dependencies. We will need similar tests is higher level packages, in order
// to test compat with ses and ses-ava.
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@endo/non-trapping-shim@workspace:packages/non-trapping-shim"
dependencies:
"@endo/env-options": "workspace:^"
ava: "npm:^6.1.3"
c8: "npm:^7.14.0"
tsd: "npm:^0.31.2"
Expand Down

0 comments on commit 2b82131

Please sign in to comment.