Skip to content

Commit 4da7742

Browse files
authored
fix: tolerate empty func.prototype (#1221)
* fix: tolerate empty func.prototype * fix: better tests
1 parent 94c16f9 commit 4da7742

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

packages/ses/src/whitelist-intrinsics.js

+9
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,15 @@ export default function whitelistIntrinsics(
285285
delete obj[prop];
286286
} catch (err) {
287287
if (prop in obj) {
288+
if (typeof obj === 'function' && prop === 'prototype') {
289+
obj.prototype = undefined;
290+
if (obj.prototype === undefined) {
291+
// eslint-disable-next-line @endo/no-polymorphic-call
292+
console.warn(`Tolerating undeletable ${subPath} === undefined`);
293+
// eslint-disable-next-line no-continue
294+
continue;
295+
}
296+
}
288297
// eslint-disable-next-line @endo/no-polymorphic-call
289298
console.error(`failed to delete ${subPath}`, err);
290299
} else {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import test from 'ava';
2+
import '../index.js';
3+
4+
// See https://github.com/zloirock/core-js/issues/1092
5+
const originalPush = Array.prototype.push;
6+
// eslint-disable-next-line no-extend-native
7+
Array.prototype.push = function push(...args) {
8+
return Reflect.apply(originalPush, this, args);
9+
};
10+
11+
lockdown();
12+
13+
test('tolerate empty prototype', t => {
14+
t.assert('prototype' in Array.prototype.push);
15+
t.is(Array.prototype.push.prototype, undefined);
16+
t.deepEqual(
17+
Object.getOwnPropertyDescriptor(Array.prototype.push, 'prototype'),
18+
{
19+
value: undefined,
20+
writable: false,
21+
enumerable: false,
22+
configurable: false,
23+
},
24+
);
25+
});

0 commit comments

Comments
 (0)