@@ -61,7 +61,15 @@ import { assert } from './error/assert.js';
61
61
* Local alias of `freeze` to eventually be switched to whatever applies
62
62
* the suppress-trapping integrity trait.
63
63
*/
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 ;
65
73
66
74
/**
67
75
* @import {Harden} from '../types.js'
@@ -139,14 +147,11 @@ const freezeTypedArray = array => {
139
147
* @returns {Harden }
140
148
*/
141
149
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.
147
150
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
+ }
150
155
}
151
156
152
157
const hardened = new WeakSet ( ) ;
0 commit comments