diff --git a/packages/ses/src/whitelist-intrinsics.js b/packages/ses/src/whitelist-intrinsics.js index 1819e803cd..4410d2793f 100644 --- a/packages/ses/src/whitelist-intrinsics.js +++ b/packages/ses/src/whitelist-intrinsics.js @@ -285,6 +285,15 @@ export default function whitelistIntrinsics( delete obj[prop]; } catch (err) { if (prop in obj) { + if (typeof obj === 'function' && prop === 'prototype') { + obj.prototype = undefined; + if (obj.prototype === undefined) { + // eslint-disable-next-line @endo/no-polymorphic-call + console.warn(`Tolerating undeletable ${subPath} === undefined`); + // eslint-disable-next-line no-continue + continue; + } + } // eslint-disable-next-line @endo/no-polymorphic-call console.error(`failed to delete ${subPath}`, err); } else { diff --git a/packages/ses/test/test-tolerate-empty-prototype.js b/packages/ses/test/test-tolerate-empty-prototype.js new file mode 100644 index 0000000000..7503c797db --- /dev/null +++ b/packages/ses/test/test-tolerate-empty-prototype.js @@ -0,0 +1,25 @@ +import test from 'ava'; +import '../index.js'; + +// See https://github.com/zloirock/core-js/issues/1092 +const originalPush = Array.prototype.push; +// eslint-disable-next-line no-extend-native +Array.prototype.push = function push(...args) { + return Reflect.apply(originalPush, this, args); +}; + +lockdown(); + +test('tolerate empty prototype', t => { + t.assert('prototype' in Array.prototype.push); + t.is(Array.prototype.push.prototype, undefined); + t.deepEqual( + Object.getOwnPropertyDescriptor(Array.prototype.push, 'prototype'), + { + value: undefined, + writable: false, + enumerable: false, + configurable: false, + }, + ); +});