Skip to content

Commit a11fc2e

Browse files
committed
fixup! incorporate #2677
1 parent 3b56481 commit a11fc2e

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

packages/ses/src/intrinsics.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ function initProperty(obj, name, desc) {
4848
preDesc.enumerable !== desc.enumerable ||
4949
preDesc.configurable !== desc.configurable
5050
) {
51-
throw TypeError(`Conflicting definitions of ${name}`);
51+
if (name !== 'harden') {
52+
// In case there is a native hardener but we're not using it,
53+
// because we've opted into using the non-trapping shim.
54+
throw TypeError(`Conflicting definitions of ${name}`);
55+
}
5256
}
5357
}
5458
defineProperty(obj, name, desc);

packages/ses/src/make-hardener.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,15 @@ import { assert } from './error/assert.js';
6161
* Local alias of `freeze` to eventually be switched to whatever applies
6262
* the suppress-trapping integrity trait.
6363
*/
64-
export const freezeOrSuppressTrapping = optSuppressTrapping || freeze;
64+
const freezeOrSuppressTrapping = optSuppressTrapping || freeze;
65+
66+
/**
67+
* The current native hardened in question, from XS, does not suppress trapping.
68+
* So, it is only ok to use it if this vat has not opted into
69+
* shimming the non-trapping trait. If it has, and we therefore avoid the
70+
* native hardener, this is likely *expensive*.
71+
*/
72+
const okToUseNativeHardener = optSuppressTrapping === undefined;
6573

6674
/**
6775
* @import {Harden} from '../types.js'
@@ -139,14 +147,11 @@ const freezeTypedArray = array => {
139147
* @returns {Harden}
140148
*/
141149
export const makeHardener = () => {
142-
// TODO Get the native hardener to suppressTrapping at each step,
143-
// rather than freeze. Until then, we cannot use it, which is *expensive*!
144-
// TODO Comment out the following to skip the native hardener.
145-
//
146-
// Use a native hardener if possible.
147150
if (typeof globalThis.harden === 'function') {
148-
const safeHarden = globalThis.harden;
149-
return safeHarden;
151+
if (okToUseNativeHardener) {
152+
const safeHarden = globalThis.harden;
153+
return safeHarden;
154+
}
150155
}
151156

152157
const hardened = new WeakSet();

packages/ses/test/native-harden.test.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import { assertFakeFrozen } from './_lockdown-harden-unsafe.js';
44
// eslint-disable-next-line import/order
55
import test from 'ava';
66

7-
test('mocked globalThis.harden', t => {
7+
// Skipped in case there is a native harden but we're not using it
8+
// because we've opted into the non-trapping shim.
9+
test.skip('mocked globalThis.harden', t => {
810
t.is(harden, mockHarden);
911
t.is(harden.isFake, true);
1012

0 commit comments

Comments
 (0)