Skip to content

Commit

Permalink
Update inert constructor error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
rekmarks committed Jul 8, 2021
1 parent 757fc7c commit cc171c1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
4 changes: 3 additions & 1 deletion packages/ses/src/compartment-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ export const InertCompartment = function Compartment(
_modules = {},
_options = {},
) {
throw new TypeError('Not available');
throw new TypeError(
'Compartment.prototype.constructor is not a valid constructor.',
);
};

export const CompartmentPrototype = {
Expand Down
4 changes: 3 additions & 1 deletion packages/ses/src/tame-function-constructors.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ export default function tameFunctionConstructors() {
// prototype of functions.
// eslint-disable-next-line func-names
const InertConstructor = function() {
throw new TypeError('Not available');
throw new TypeError(
'Function.prototype.constructor is not a valid constructor.',
);
};
defineProperties(InertConstructor, {
prototype: { value: FunctionPrototype },
Expand Down
16 changes: 10 additions & 6 deletions packages/ses/test/test-whitelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,22 @@ x.slice;
);
});

test('Function constructor is inert', t => {
test('Function constructor should be inert', t => {
t.throws(
() => Function.prototype.constructor(),
{ message: 'Not available' },
'Function constructor is disabled',
{
message: 'Function.prototype.constructor is not a valid constructor.',
},
'Function constructor should be disabled',
);
});

test('Compartment constructor is inert', t => {
test('Compartment constructor should be inert', t => {
t.throws(
() => Compartment.prototype.constructor(),
{ message: 'Not available' },
'Compartment constructor is disabled',
{
message: 'Compartment.prototype.constructor is not a valid constructor.',
},
'Compartment constructor should be disabled',
);
});

0 comments on commit cc171c1

Please sign in to comment.