Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -180,27 +180,27 @@ describe('IframeExecutionService', () => {
snapId: MOCK_SNAP_ID,
sourceCode: `
module.exports.onRpcRequest = async ({ request }) => {
let result;
const promise = new Promise((resolve) => {
const xhr = new XMLHttpRequest();
xhr.open('GET', 'https://metamask.io/');
xhr.send();
xhr.onreadystatechange = (ev) => {
result = ev;
resolve();
};
const controller = new AbortController();
let result;
const promise = new Promise((resolve) => {
controller.signal.addEventListener('abort', (ev) => {
result = ev;
resolve();
});
await promise;

return {
targetIsUndefined: result.target === undefined,
currentTargetIsUndefined: result.target === undefined,
srcElementIsUndefined: result.target === undefined,
composedPathIsUndefined: result.target === undefined
};
});

controller.abort();
await promise;

return {
targetIsUndefined: result.target === undefined,
currentTargetIsUndefined: result.currentTarget === undefined,
srcElementIsUndefined: result.srcElement === undefined,
composedPathIsUndefined: result.composedPath === undefined,
};
};
`,
endowments: ['console', 'XMLHttpRequest'],
endowments: ['console', 'AbortController'],
});

const result = await service.handleRpcRequest(MOCK_SNAP_ID, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,6 @@ describe('Endowment utils', () => {
expect(result.endowments.snap).toBe(mockSnapAPI);
});

it('handles special cases where endowment is not available as part of a factory', () => {
const mockEndowment = {};
Object.assign(globalThis, { mockEndowment });
const { endowments } = createEndowments({
...mockOptions,
endowments: ['mockEndowment'],
});
expect(endowments.mockEndowment).toBeDefined();
});

it('handles special case for ethereum endowment', () => {
Object.assign(globalThis, { ethereum: {} });
const { endowments } = createEndowments({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { rpcErrors } from '@metamask/rpc-errors';
import type { SnapsEthereumProvider, SnapsProvider } from '@metamask/snaps-sdk';
import { logWarning } from '@metamask/snaps-utils';
import { hasProperty } from '@metamask/utils';

import type {
Expand All @@ -9,7 +8,6 @@ import type {
NotifyFunction,
} from './commonEndowmentFactory';
import buildCommonEndowments from './commonEndowmentFactory';
import { rootRealmGlobal } from '../globalObject';

/**
* Retrieve consolidated endowment factories for common endowments.
Expand Down Expand Up @@ -89,14 +87,6 @@ export function createEndowments({
} else if (endowmentName === 'ethereum') {
// Special case for adding the EIP-1193 provider.
allEndowments[endowmentName] = ethereum;
} else if (endowmentName in rootRealmGlobal) {
logWarning(`Access to unhardened global ${endowmentName}.`);
// If the endowment doesn't have a factory, just use whatever is on the
// global object.
const globalValue = (rootRealmGlobal as Record<string, unknown>)[
endowmentName
];
allEndowments[endowmentName] = globalValue;
} else {
// If we get to this point, we've been passed an endowment that doesn't
// exist in our current environment.
Expand Down
Loading