Skip to content

Commit

Permalink
fix: tolerate empty func.prototype (#1221)
Browse files Browse the repository at this point in the history
* fix: tolerate empty func.prototype

* fix: better tests
  • Loading branch information
erights committed Jun 18, 2022
1 parent 94c16f9 commit 4da7742
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/ses/src/whitelist-intrinsics.js
Expand Up @@ -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 {
Expand Down
25 changes: 25 additions & 0 deletions 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,
},
);
});

0 comments on commit 4da7742

Please sign in to comment.