Skip to content

Commit

Permalink
fix(gems): use the correct captp option and fix customKind bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
kumavis committed Nov 6, 2024
1 parent e98bb51 commit a9e4441
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
8 changes: 8 additions & 0 deletions packages/gems/docs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
you need to defineClass every session. calling registerClass once ensures this happens every session. but if your code is running every session, just call defineClass

if it crosses a vat or is put in storage it needs to be durable so it needs to be defined

defineClass happens once
registerClass happens every start
incubate happens once
registerIncubation happens every start
1 change: 1 addition & 0 deletions packages/gems/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { makeKernel } from './src/kernel.js';
14 changes: 14 additions & 0 deletions packages/gems/src/custom-kind.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ export const makeCustomDurableKindWithContext = (
cleanup: customCleanup = undefined,
},
) => {
if (!customMake) {
throw new Error('makeCustomDurableKindWithContext - "make" function is required');
}
if (!customReanimate) {
throw new Error('makeCustomDurableKindWithContext - "reanimate" function is required');
}
const { vrm, fakeStuff } = fakeVomKit;
const store = zone.mapStore('controller');
const instanceData = zone.mapStore('data');
Expand Down Expand Up @@ -93,6 +99,13 @@ export const makeCustomDurableKindWithZone = (
cleanup: customCleanup = undefined,
},
) => {
if (!customMake) {
throw new Error('makeCustomDurableKindWithZone - "make" function is required');
}
if (!customReanimate) {
throw new Error('makeCustomDurableKindWithZone - "reanimate" function is required');
}

const { vrm, fakeStuff } = fakeVomKit;
const store = zone.mapStore('controller');
const dataZone = zone.subZone('instances');
Expand Down Expand Up @@ -126,6 +139,7 @@ export const makeCustomDurableKindWithZone = (
const value = customMake(instanceZone, ...args);
// register the slot with the value, so it can be stored
fakeStuff.registerEntry(instanceSlot, value, false);
return value;
};

const reanimate = instanceSlot => {
Expand Down
6 changes: 3 additions & 3 deletions packages/gems/src/extref-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const installExternalReferenceController = (
return exports.get(localSlot);
};

const makeCaptpImportExportTables = () => {
const makeCapTPImportExportTables = () => {
return {
makeSlotForValue: registerExport,
makeValueForSlot: (slot, iface) => {
Expand Down Expand Up @@ -108,13 +108,13 @@ export const installExternalReferenceController = (
registerExport,
unregisterExport,
lookupExport,
makeCaptpImportExportTables,
makeCapTPImportExportTables,
};
};

export const makeCaptpOptionsForExtRefController = controller => {
const captpOptions = {
makeCaptpImportExportTables: controller.makeCaptpImportExportTables,
makeCapTPImportExportTables: controller.makeCapTPImportExportTables,
};
return captpOptions;
};
1 change: 1 addition & 0 deletions packages/gems/src/vat-supervisor.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ export const makeVatSupervisor = (label, vatState) => {
incubate,
registerIncubation,
registerClass,
defineClass,
defineJsClass,
fakeStore,
fakeVomKit,
Expand Down

0 comments on commit a9e4441

Please sign in to comment.