Skip to content

Commit

Permalink
fix: repair remotable inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Aug 14, 2022
1 parent 747bd5e commit 60bc182
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
15 changes: 9 additions & 6 deletions packages/store/src/patterns/interface-tools.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { PASS_STYLE } from '@endo/marshal';
import { PASS_STYLE, assertRemotable } from '@endo/marshal';
import { E } from '@endo/eventual-send';
import { M, fit } from './patternMatchers.js';

const { details: X, quote: q } = assert;
const { apply, ownKeys } = Reflect;
const { fromEntries, entries, defineProperties } = Object;
const { fromEntries, entries, create, setPrototypeOf } = Object;

const makeMethodGuardMaker = (callKind, argGuards) =>
harden({
Expand All @@ -27,7 +27,7 @@ const isAwaitArgGuard = argGuard =>
argGuard && typeof argGuard === 'object' && argGuard.klass === 'awaitArg';

export const I = harden({
interface: (name, methodGuards) => {
interface: (farName, methodGuards) => {
for (const [_, methodGuard] of entries(methodGuards)) {
assert(
methodGuard.klass === 'methodGuard',
Expand All @@ -36,7 +36,7 @@ export const I = harden({
}
return harden({
klass: 'Interface',
name,
name: `Alleged: ${farName}`,
methodGuards,
});
},
Expand Down Expand Up @@ -152,10 +152,13 @@ export const defendVTable = (rawVTable, contextMapStore, iface) => {
// a fail-fast brand check on `this`, ensuring that the methods can only be
// applied to legitimate instances.
const defensiveVTable = fromEntries(defensiveMethodEntries);
defineProperties(defensiveVTable, {
const remotableProto = create(Object.prototype, {
[PASS_STYLE]: { value: 'remotable' },
[Symbol.toStringTag]: { value: name },
});
return harden(defensiveVTable);
setPrototypeOf(defensiveVTable, remotableProto);
harden(defensiveVTable);
assertRemotable(defensiveVTable);
return defensiveVTable;
};
harden(defendVTable);
3 changes: 1 addition & 2 deletions packages/store/test/test-interface-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ test('how far-able is defineHeapKind', t => {
foo: I.call(M.any()).returns(M.undefined()),
});
const makeBob = defineHeapKind(bobIFace, () => ({}), {
// @ts-ignore
foo: ({ _state, _self }, _carol) => console.log('got here'),
});
const bob = makeBob();
t.assert(passStyleOf(bob) === 'remotable');
t.is(passStyleOf(bob), 'remotable');
});
32 changes: 32 additions & 0 deletions patches/@endo+marshal+0.6.9.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
diff --git a/node_modules/@endo/marshal/src/helpers/remotable.js b/node_modules/@endo/marshal/src/helpers/remotable.js
index c19adca..aed24f8 100644
--- a/node_modules/@endo/marshal/src/helpers/remotable.js
+++ b/node_modules/@endo/marshal/src/helpers/remotable.js
@@ -77,6 +77,18 @@ const checkRemotableProtoOf = (original, check = x => x) => {
* }}
*/
const proto = getPrototypeOf(original);
+ const protoProto = getPrototypeOf(proto);
+ if (
+ typeof original === 'object' &&
+ proto !== objectPrototype &&
+ protoProto !== objectPrototype
+ ) {
+ return (
+ // eslint-disable-next-line no-use-before-define
+ RemotableHelper.canBeValid(proto, check) && checkRemotable(proto, check)
+ );
+ }
+
if (
!(
check(
@@ -95,8 +107,6 @@ const checkRemotableProtoOf = (original, check = x => x) => {
return false;
}

- const protoProto = getPrototypeOf(proto);
-
if (typeof original === 'object') {
if (
!check(

0 comments on commit 60bc182

Please sign in to comment.