diff --git a/packages/execution-environments/jest.config.js b/packages/execution-environments/jest.config.js index ddcc010140..ddbbfc85ef 100644 --- a/packages/execution-environments/jest.config.js +++ b/packages/execution-environments/jest.config.js @@ -7,9 +7,9 @@ module.exports = { coverageThreshold: { global: { branches: 34.69, - functions: 38.89, - lines: 34.62, - statements: 34.98, + functions: 35.29, + lines: 32, + statements: 32.41, }, }, moduleFileExtensions: ['js', 'json', 'jsx', 'ts', 'tsx', 'node'], diff --git a/packages/execution-environments/src/common/endowments/index.test.ts b/packages/execution-environments/src/common/endowments/index.test.ts index bee64629cf..e3b4cf2d6d 100644 --- a/packages/execution-environments/src/common/endowments/index.test.ts +++ b/packages/execution-environments/src/common/endowments/index.test.ts @@ -27,13 +27,13 @@ describe('createEndowments', () => { it('handles factory endowments', () => { const mockWallet = { foo: Symbol('bar') }; - const { endowments } = createEndowments(mockWallet as any, ['WebAssembly']); + const { endowments } = createEndowments(mockWallet as any, ['setTimeout']); expect(endowments).toStrictEqual({ wallet: mockWallet, - WebAssembly: expect.objectContaining(WebAssembly), + setTimeout: expect.any(Function), }); - expect(endowments.WebAssembly).not.toBe(WebAssembly); + expect(endowments.setTimeout).not.toBe(setTimeout); }); it('handles some endowments from the same factory', () => { @@ -80,17 +80,17 @@ describe('createEndowments', () => { Math, setTimeout: expect.any(Function), clearTimeout: expect.any(Function), - WebAssembly: { ...WebAssembly }, + WebAssembly, }); expect(endowments.wallet).toBe(mockWallet); expect(endowments.Buffer).toBe(Buffer); - expect(endowments.Math).toBe(Math); expect(endowments.console).toBe(console); + expect(endowments.Math).toBe(Math); + expect(endowments.WebAssembly).toBe(WebAssembly); expect(endowments.clearTimeout).not.toBe(clearTimeout); expect(endowments.setTimeout).not.toBe(setTimeout); - expect(endowments.WebAssembly).not.toBe(WebAssembly); }); it('throws for unknown endowments', () => { diff --git a/packages/execution-environments/src/common/endowments/index.ts b/packages/execution-environments/src/common/endowments/index.ts index de9a67d893..cafa84aac9 100644 --- a/packages/execution-environments/src/common/endowments/index.ts +++ b/packages/execution-environments/src/common/endowments/index.ts @@ -3,7 +3,6 @@ import { rootRealmGlobal } from '../globalObject'; import buffer from './buffer'; import timeout from './timeout'; import interval from './interval'; -import wasm from './wasm'; type EndowmentFactoryResult = { teardownFunction?: () => void; @@ -15,7 +14,7 @@ type EndowmentFactoryResult = { * the same factory function, but we only call each factory once for each snap. * See {@link createEndowments} for details. */ -const endowmentFactories = [buffer, timeout, interval, wasm].reduce( +const endowmentFactories = [buffer, timeout, interval].reduce( (factories, builder) => { builder.names.forEach((name) => { factories.set(name, builder.factory); diff --git a/packages/execution-environments/src/common/endowments/wasm.test.ts b/packages/execution-environments/src/common/endowments/wasm.test.ts deleted file mode 100644 index 0db085c0dc..0000000000 --- a/packages/execution-environments/src/common/endowments/wasm.test.ts +++ /dev/null @@ -1,30 +0,0 @@ -import wasm, { excludedProperties } from './wasm'; - -describe('createWASM', () => { - it('has expected properties', () => { - expect(wasm).toMatchObject({ - names: ['WebAssembly'], - factory: expect.any(Function), - }); - }); - - it('has expected factory output', () => { - const factoryOutput = wasm.factory(); - const enumerableKeys = Object.keys(factoryOutput.WebAssembly); - const allKeys = Reflect.ownKeys(factoryOutput.WebAssembly); - - expect(factoryOutput).toMatchObject({ WebAssembly: expect.any(Object) }); - expect(enumerableKeys).toStrictEqual( - Object.keys(WebAssembly).filter( - (key) => !excludedProperties.includes(key), - ), - ); - - expect(allKeys).toStrictEqual( - Reflect.ownKeys(WebAssembly).filter( - (key) => !excludedProperties.includes(key), - ), - ); - expect(allKeys.length).toBeGreaterThan(enumerableKeys.length); - }); -}); diff --git a/packages/execution-environments/src/common/endowments/wasm.ts b/packages/execution-environments/src/common/endowments/wasm.ts deleted file mode 100644 index 19234542c1..0000000000 --- a/packages/execution-environments/src/common/endowments/wasm.ts +++ /dev/null @@ -1,34 +0,0 @@ -type WebAssemblyKeys = keyof typeof WebAssembly; -type WebAssemblyValues = typeof WebAssembly[WebAssemblyKeys]; - -export const excludedProperties: readonly (string | symbol)[] = [ - 'compileStreaming', - 'instantiateStreaming', -]; - -/** - * Builds a cross-platform `WebAssembly` only consisting of functions present - * both in the browser and Node.js. - * - * @returns An object with a `WebAssembly` property without `compileStreaming` - * and `instantiateStreaming`. - */ -const createWasm = () => { - const wasm: Record = Object.create(null); - (Reflect.ownKeys(WebAssembly) as WebAssemblyKeys[]) - .filter((key) => !excludedProperties.includes(key)) - .forEach((key) => { - Object.defineProperty(wasm, key, { - ...Reflect.getOwnPropertyDescriptor(WebAssembly, key), - value: WebAssembly[key], - }); - }); - - return { WebAssembly: wasm } as const; -}; - -const endowmentModule = { - names: ['WebAssembly'] as const, - factory: createWasm, -}; -export default endowmentModule;