Skip to content

Commit

Permalink
fixup! partially thread proper reporter into intrinsics.js
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Nov 12, 2024
1 parent 9609166 commit 4f7a7fc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/ses/src/compartment-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const markVirtualizedNativeFunction = tameFunctionToString();
// @ts-ignore Compartment is definitely on globalThis.
globalThis.Compartment = makeCompartmentConstructor(
makeCompartmentConstructor,
// TODO pass a proper reporter as second arg to `getGlobalIntrinsics`?
getGlobalIntrinsics(globalThis),
markVirtualizedNativeFunction,
);
16 changes: 12 additions & 4 deletions packages/ses/src/intrinsics.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ import {
permitted,
} from './permits.js';

/**
* @import {Reporter} from './reporting-types.js'
*/

const isFunction = obj => typeof obj === 'function';

// Like defineProperty, but throws if it would modify an existing property.
Expand Down Expand Up @@ -72,7 +76,10 @@ function sampleGlobals(globalObject, newPropertyNames) {
return newIntrinsics;
}

export const makeIntrinsicsCollector = () => {
/**
* @param {Reporter} reporter
*/
export const makeIntrinsicsCollector = reporter => {
/** @type {Record<any, any>} */
const intrinsics = create(null);
let pseudoNatives;
Expand Down Expand Up @@ -106,7 +113,7 @@ export const makeIntrinsicsCollector = () => {
'prototype',
false,
`${name}.prototype`,
console, // TODO should be a proper Reporter
reporter,
);
// eslint-disable-next-line no-continue
continue;
Expand Down Expand Up @@ -173,9 +180,10 @@ export const makeIntrinsicsCollector = () => {
* *original* unsafe (feral, untamed) bindings of these global variables.
*
* @param {object} globalObject
* @param {Reporter} [reporter] defaults to `console`
*/
export const getGlobalIntrinsics = globalObject => {
const { addIntrinsics, finalIntrinsics } = makeIntrinsicsCollector();
export const getGlobalIntrinsics = (globalObject, reporter = console) => {
const { addIntrinsics, finalIntrinsics } = makeIntrinsicsCollector(reporter);

addIntrinsics(sampleGlobals(globalObject, sharedGlobalPropertyNames));

Expand Down
2 changes: 1 addition & 1 deletion packages/ses/src/lockdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export const repairIntrinsics = (options = {}) => {
const markVirtualizedNativeFunction = tameFunctionToString();

const { addIntrinsics, completePrototypes, finalIntrinsics } =
makeIntrinsicsCollector();
makeIntrinsicsCollector(reporter);

// @ts-expect-error __hardenTaming__ could be any string
const tamedHarden = tameHarden(safeHarden, __hardenTaming__);
Expand Down

0 comments on commit 4f7a7fc

Please sign in to comment.