Skip to content

Commit

Permalink
fixup! incorporate #2677
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Jan 27, 2025
1 parent 3b56481 commit a11fc2e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
6 changes: 5 additions & 1 deletion packages/ses/src/intrinsics.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ function initProperty(obj, name, desc) {
preDesc.enumerable !== desc.enumerable ||
preDesc.configurable !== desc.configurable
) {
throw TypeError(`Conflicting definitions of ${name}`);
if (name !== 'harden') {
// In case there is a native hardener but we're not using it,
// because we've opted into using the non-trapping shim.
throw TypeError(`Conflicting definitions of ${name}`);
}
}
}
defineProperty(obj, name, desc);
Expand Down
21 changes: 13 additions & 8 deletions packages/ses/src/make-hardener.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,15 @@ import { assert } from './error/assert.js';
* Local alias of `freeze` to eventually be switched to whatever applies
* the suppress-trapping integrity trait.
*/
export const freezeOrSuppressTrapping = optSuppressTrapping || freeze;
const freezeOrSuppressTrapping = optSuppressTrapping || freeze;

/**
* The current native hardened in question, from XS, does not suppress trapping.
* So, it is only ok to use it if this vat has not opted into
* shimming the non-trapping trait. If it has, and we therefore avoid the
* native hardener, this is likely *expensive*.
*/
const okToUseNativeHardener = optSuppressTrapping === undefined;

/**
* @import {Harden} from '../types.js'
Expand Down Expand Up @@ -139,14 +147,11 @@ const freezeTypedArray = array => {
* @returns {Harden}
*/
export const makeHardener = () => {
// TODO Get the native hardener to suppressTrapping at each step,
// rather than freeze. Until then, we cannot use it, which is *expensive*!
// TODO Comment out the following to skip the native hardener.
//
// Use a native hardener if possible.
if (typeof globalThis.harden === 'function') {
const safeHarden = globalThis.harden;
return safeHarden;
if (okToUseNativeHardener) {
const safeHarden = globalThis.harden;
return safeHarden;
}
}

const hardened = new WeakSet();
Expand Down
4 changes: 3 additions & 1 deletion packages/ses/test/native-harden.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { assertFakeFrozen } from './_lockdown-harden-unsafe.js';
// eslint-disable-next-line import/order
import test from 'ava';

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

Expand Down

0 comments on commit a11fc2e

Please sign in to comment.