UNPKG

@metamask/snaps-utils

Version:
40 lines 1.72 kB
// eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - TypeScript complains about this being ESM in a CJS file, but // `ses/lockdown` has a CommonJS entry point. // eslint-disable-next-line import-x/no-unassigned-import import "ses/lockdown"; import { readFileSync } from "fs"; import { SNAP_EXPORT_NAMES } from "./handlers/index.mjs"; import { generateMockEndowments } from "./mock.mjs"; lockdown({ consoleTaming: 'unsafe', errorTaming: 'unsafe', mathTaming: 'unsafe', dateTaming: 'unsafe', overrideTaming: 'severe', // We disable domain taming, because it does not work in certain cases when // running tests. This is unlikely to be a problem in production, because // Node.js domains are deprecated. domainTaming: 'unsafe', }); const snapFilePath = process.argv[2]; const snapModule = { exports: {} }; const compartment = new Compartment({ ...generateMockEndowments(), module: snapModule, exports: snapModule.exports, }); // Mirror BaseSnapExecutor compartment.globalThis.self = compartment.globalThis; compartment.globalThis.global = compartment.globalThis; compartment.globalThis.window = compartment.globalThis; compartment.evaluate(readFileSync(snapFilePath, 'utf8')); const invalidExports = Object.keys(snapModule.exports).filter((snapExport) => !SNAP_EXPORT_NAMES.includes(snapExport)); if (invalidExports.length > 0) { // eslint-disable-next-line no-console console.warn(`Invalid snap exports detected:\n${invalidExports.join('\n')}`); } // To ensure the worker exits we explicitly call exit here // If we didn't the eval would wait for timers set during Compartment eval process.exit(0); //# sourceMappingURL=eval-worker.mjs.map