MCPcopy Create free account
hub / github.com/ICBNetwork/web3-Wallet / makeThirdPartyModuleInstance

Function makeThirdPartyModuleInstance

ses.cjs:8463–8547  ·  view source on GitHub ↗
(
  compartmentPrivateFields,
  staticModuleRecord,
  compartment,
  moduleAliases,
  moduleSpecifier,
  resolvedImports)

Source from the content-addressed store, hash-verified

8461const { quote: q}= assert;
8462
8463const makeThirdPartyModuleInstance= (
8464 compartmentPrivateFields,
8465 staticModuleRecord,
8466 compartment,
8467 moduleAliases,
8468 moduleSpecifier,
8469 resolvedImports)=>
8470 {
8471 const { exportsProxy, exportsTarget, activate}= getDeferredExports(
8472 compartment,
8473 weakmapGet(compartmentPrivateFields, compartment),
8474 moduleAliases,
8475 moduleSpecifier);
8476
8477
8478 const notifiers= create(null);
8479
8480 if( staticModuleRecord.exports) {
8481 if(
8482 !isArray(staticModuleRecord.exports)||
8483 arraySome(staticModuleRecord.exports, (name)=>typeof name!== 'string'))
8484 {
8485 throw TypeError(
8486 `SES third-party static module record "exports" property must be an array of strings for module ${moduleSpecifier}`);
8487
8488 }
8489 arrayForEach(staticModuleRecord.exports, (name)=>{
8490 let value= exportsTarget[name];
8491 const updaters= [];
8492
8493 const get= ()=> value;
8494
8495 const set= (newValue)=>{
8496 value= newValue;
8497 for( const updater of updaters) {
8498 updater(newValue);
8499 }
8500 };
8501
8502 defineProperty(exportsTarget, name, {
8503 get,
8504 set,
8505 enumerable: true,
8506 configurable: false});
8507
8508
8509 notifiers[name]= (update)=>{
8510 arrayPush(updaters, update);
8511 update(value);
8512 };
8513 });
8514 // This is enough to support import * from cjs - the '*' field doesn't need to be in exports nor exportsTarget because import will only ever access it via notifiers
8515 notifiers['*']= (update)=>{
8516 update(exportsTarget);
8517 };
8518 }
8519
8520 const localState= {

Callers 1

instantiateFunction · 0.85

Calls 3

getDeferredExportsFunction · 0.85
definePropertyFunction · 0.85
updateFunction · 0.85

Tested by

no test coverage detected