Skip to content

Commit

Permalink
feat(ses): Anticipate a ModuleSource shared intrinsic
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal committed Sep 20, 2024
1 parent e8839a4 commit 2e47ef8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
14 changes: 14 additions & 0 deletions packages/ses/src/get-anonymous-intrinsics.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,19 @@ export const getAnonymousIntrinsics = () => {
);
}

if (globalThis.ModuleSource) {
const AbstractModuleSourcePrototype = getPrototypeOf(
globalThis.ModuleSource.prototype,
);
intrinsics['%AbstractModuleSourcePrototype%'] =
AbstractModuleSourcePrototype;
intrinsics['%AbstractModuleSource%'] =
AbstractModuleSourcePrototype.constructor;
}

if (globalThis.ModuleSource) {
intrinsics['%ModuleSourcePrototype%'] = globalThis.ModuleSource.prototype;
}

return intrinsics;
};
4 changes: 3 additions & 1 deletion packages/ses/src/permits-intrinsics.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ export default function whitelistIntrinsics(
}
}

throw TypeError(`Unexpected whitelist permit ${permit} at ${path}`);
throw TypeError(
`Unexpected property ${prop} with permit ${permit} at ${path}`,
);
}

/*
Expand Down
23 changes: 23 additions & 0 deletions packages/ses/src/permits.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,12 @@ export const universalPropertyNames = {

// ESNext

// https://github.com/tc39/proposal-source-phase-imports?tab=readme-ov-file#js-module-source
ModuleSource: 'ModuleSource',

lockdown: 'lockdown',
harden: 'harden',

HandledPromise: 'HandledPromise', // TODO: Until Promise.delegate (see below).
};

Expand Down Expand Up @@ -1505,6 +1509,25 @@ export const permitted = {
resolve: fn,
},

// https://github.com/tc39/proposal-source-phase-imports?tab=readme-ov-file#js-module-source
'%AbstractModuleSourcePrototype%': {
'@@toStringTag': getter,
constructor: '%AbstractModuleSource%',
},
'%AbstractModuleSource%': {
'[[Proto]]': '%FunctionPrototype%',
prototype: '%AbstractModuleSourcePrototype%',
},
'%ModuleSourcePrototype%': {
'[[Proto]]': '%AbstractModuleSourcePrototype%',
'@@toStringTag': getter,
constructor: 'ModuleSource',
},
ModuleSource: {
'[[Proto]]': '%FunctionPrototype%',
prototype: '%ModuleSourcePrototype%',
},

Promise: {
// Properties of the Promise Constructor
'[[Proto]]': '%FunctionPrototype%',
Expand Down
1 change: 1 addition & 0 deletions packages/ses/test/module-source.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ test('module source constructor', t => {

test('ModuleSource is a shared intrinsic', t => {
t.truthy(ModuleSource === new Compartment().globalThis.ModuleSource);
t.truthy(Object.isFrozen(ModuleSource));
});

0 comments on commit 2e47ef8

Please sign in to comment.