Skip to content

Commit 8ed8a8b

Browse files
committed
fix(ses): warn on unsupported lockdownOptions mathTaming + dateTaming
1 parent b3f0c56 commit 8ed8a8b

File tree

8 files changed

+34
-20
lines changed

8 files changed

+34
-20
lines changed

packages/ses/NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
User-visible changes in `ses`:
22

3+
# Next version
4+
5+
- Specifying the long discontinued `mathTaming` or `dateTaming` options logs a warning.
6+
37
# v1.10.0 (2024-11-13)
48

59
- Permit [Promise.try](https://github.com/tc39/proposal-promise-try),

packages/ses/src/lockdown.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ export const repairIntrinsics = (options = {}) => {
194194
'safe',
195195
),
196196
__hardenTaming__ = getenv('LOCKDOWN_HARDEN_TAMING', 'safe'),
197-
dateTaming = 'safe', // deprecated
198-
mathTaming = 'safe', // deprecated
197+
dateTaming, // deprecated
198+
mathTaming, // deprecated
199199
...extraOptions
200200
} = options;
201201

@@ -215,6 +215,20 @@ export const repairIntrinsics = (options = {}) => {
215215
Fail`lockdown(): non supported option ${q(extraOptionsNames)}`;
216216

217217
const reporter = chooseReporter(reporting);
218+
const { warn } = reporter;
219+
220+
if (dateTaming !== undefined) {
221+
// eslint-disable-next-line no-console
222+
warn(
223+
`SES The 'dateTaming' option is deprecated and does nothing. In the future specifying it will be an error.`,
224+
);
225+
}
226+
if (mathTaming !== undefined) {
227+
// eslint-disable-next-line no-console
228+
warn(
229+
`SES The 'mathTaming' option is deprecated and does nothing. In the future specifying it will be an error.`,
230+
);
231+
}
218232

219233
priorRepairIntrinsics === undefined ||
220234
// eslint-disable-next-line @endo/no-polymorphic-call
@@ -289,9 +303,9 @@ export const repairIntrinsics = (options = {}) => {
289303

290304
addIntrinsics(tameFunctionConstructors());
291305

292-
addIntrinsics(tameDateConstructor(dateTaming));
306+
addIntrinsics(tameDateConstructor());
293307
addIntrinsics(tameErrorConstructor(errorTaming, stackFiltering));
294-
addIntrinsics(tameMathObject(mathTaming));
308+
addIntrinsics(tameMathObject());
295309
addIntrinsics(tameRegExpConstructor(regExpTaming));
296310
addIntrinsics(tameSymbolConstructor());
297311
addIntrinsics(shimArrayBufferTransfer());

packages/ses/src/tame-date-constructor.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ import {
88
defineProperties,
99
} from './commons.js';
1010

11-
export default function tameDateConstructor(dateTaming = 'safe') {
12-
if (dateTaming !== 'safe' && dateTaming !== 'unsafe') {
13-
throw TypeError(`unrecognized dateTaming ${dateTaming}`);
14-
}
11+
export default function tameDateConstructor() {
1512
const OriginalDate = Date;
1613
const DatePrototype = OriginalDate.prototype;
1714

packages/ses/src/tame-math-object.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ import {
66
objectPrototype,
77
} from './commons.js';
88

9-
export default function tameMathObject(mathTaming = 'safe') {
10-
if (mathTaming !== 'safe' && mathTaming !== 'unsafe') {
11-
throw TypeError(`unrecognized mathTaming ${mathTaming}`);
12-
}
9+
export default function tameMathObject() {
1310
const originalMath = Math;
1411
const initialMath = originalMath; // to follow the naming pattern
1512

packages/ses/test/_lockdown-unsafe.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
lockdown({
2-
dateTaming: 'unsafe',
3-
mathTaming: 'unsafe',
42
errorTaming: 'unsafe',
53
});

packages/ses/test/lockdown-options.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import { repairIntrinsics } from '../src/lockdown.js';
33

44
test('repairIntrinsics throws with non-recognized options', t => {
55
t.throws(
6-
() => repairIntrinsics({ mathTaming: 'unsafe', abc: true }),
6+
() => repairIntrinsics({ abc: true }),
77
undefined,
88
'throws with value true',
99
);
1010
t.throws(
11-
() => repairIntrinsics({ mathTaming: 'unsafe', abc: false }),
11+
() => repairIntrinsics({ abc: false }),
1212
undefined,
1313
'throws with value false',
1414
);

packages/ses/types.d.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@ export interface RepairOptions {
2727
reporting?: 'platform' | 'console' | 'none';
2828
unhandledRejectionTrapping?: 'report' | 'none';
2929
errorTaming?: 'safe' | 'unsafe' | 'unsafe-debug';
30-
dateTaming?: 'safe' | 'unsafe'; // deprecated
31-
mathTaming?: 'safe' | 'unsafe'; // deprecated
30+
/**
31+
* @deprecated Deprecated and does nothing. In the future specifying it will be an error.
32+
*/
33+
dateTaming?: 'safe' | 'unsafe';
34+
/**
35+
* @deprecated Deprecated and does nothing. In the future specifying it will be an error.
36+
*/
37+
mathTaming?: 'safe' | 'unsafe';
3238
evalTaming?: 'safeEval' | 'unsafeEval' | 'noEval';
3339
stackFiltering?: 'concise' | 'verbose';
3440
overrideTaming?: 'moderate' | 'min' | 'severe';

packages/ses/types.test-d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ lockdown();
1010
lockdown({});
1111
lockdown({ errorTaming: 'unsafe' });
1212
lockdown({
13-
mathTaming: 'unsafe',
14-
dateTaming: 'unsafe',
1513
errorTaming: 'unsafe',
1614
localeTaming: 'unsafe',
1715
consoleTaming: 'unsafe',

0 commit comments

Comments
 (0)