Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ses): dont use native harden #2677

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/ses/src/intrinsics.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ function initProperty(obj, name, desc) {
preDesc.enumerable !== desc.enumerable ||
preDesc.configurable !== desc.configurable
) {
throw TypeError(`Conflicting definitions of ${name}`);
if (name !== 'harden') {
throw TypeError(`Conflicting definitions of ${name}`);
}
}
}
defineProperty(obj, name, desc);
Expand Down
19 changes: 12 additions & 7 deletions packages/ses/src/make-hardener.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
String,
TypeError,
WeakSet,
globalThis,
// globalThis, // if we suppress native harden
apply,
arrayForEach,
defineProperty,
Expand Down Expand Up @@ -128,11 +128,14 @@ const freezeTypedArray = array => {
* @returns {Harden}
*/
export const makeHardener = () => {
// Use a native hardener if possible.
if (typeof globalThis.harden === 'function') {
const safeHarden = globalThis.harden;
return safeHarden;
}
// TODO Get the native hardener to suppressTrapping at each step,
// rather than freeze. Until then, it is *expensive*!
//
// // Use a native hardener if possible.
// if (typeof globalThis.harden === 'function') {
// const safeHarden = globalThis.harden;
// return safeHarden;
// }

const hardened = new WeakSet();

Expand Down Expand Up @@ -238,7 +241,9 @@ export const makeHardener = () => {
// NOTE: Calls getter during harden, which seems dangerous.
// But we're only calling the problematic getter whose
// hazards we think we understand.
// @ts-expect-error TS should know FERAL_STACK_GETTER

// TODO either remove or at-ts-expect-error
// @ts-ignore-error TS should know FERAL_STACK_GETTER
// cannot be `undefined` here.
// See https://github.com/endojs/endo/pull/2232#discussion_r1575179471
value: apply(FERAL_STACK_GETTER, obj, []),
Expand Down
2 changes: 1 addition & 1 deletion packages/ses/test/native-harden.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { assertFakeFrozen } from './_lockdown-harden-unsafe.js';
// eslint-disable-next-line import/order
import test from 'ava';

test('mocked globalThis.harden', t => {
test.skip('mocked globalThis.harden', t => {
t.is(harden, mockHarden);
t.is(harden.isFake, true);

Expand Down
Loading