-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: omg far classes starting to work
- Loading branch information
Showing
3 changed files
with
132 additions
and
79 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,54 @@ | ||
/* eslint-disable max-classes-per-file */ | ||
// @ts-check | ||
|
||
import { test } from '@agoric/swingset-vat/tools/prepare-test-env-ava.js'; | ||
import { passStyleOf } from '@endo/marshal'; | ||
|
||
import { I } from '../src/patterns/interface-tools.js'; | ||
import { defineHeapKind } from '../src/patterns/defineHeapKind.js'; | ||
import { I, defendClass } from '../src/patterns/interface-tools.js'; | ||
import { M } from '../src/patterns/patternMatchers.js'; | ||
|
||
const UniRawClass = class UniRawClass { | ||
state; | ||
|
||
self; | ||
}; | ||
|
||
// const MultiRawClass = class MultiRawClass { | ||
// state; | ||
// | ||
// facets; | ||
// }; | ||
|
||
test('how far-able is defineHeapKind', t => { | ||
const bobIFace = I.interface('bob', { | ||
const bobI = I.interface('bobI', { | ||
foo: I.call(M.number()).returns(M.undefined()), | ||
}); | ||
const makeBob = defineHeapKind(bobIFace, field => ({ field }), { | ||
foo: ({ state, self }, carol) => { | ||
|
||
const BobRawClass = class BobRawClass extends UniRawClass { | ||
// @ts-expect-error Purposely overriding the builtin function.name | ||
static name = 'Bob'; | ||
|
||
static init(field) { | ||
return { field }; | ||
} | ||
|
||
foo(carol) { | ||
const { state, self } = this; | ||
t.is(state.field, 8); | ||
t.is(typeof self.foo, 'function'); | ||
t.is(self.foo.name, 'foo'); | ||
t.is(self.foo.length, 1); | ||
t.is(carol, 77); | ||
state.field += carol; | ||
t.is(state.field, 85); | ||
}, | ||
}); | ||
const bob = makeBob(8); | ||
} | ||
}; | ||
|
||
const Bob = defendClass(bobI, BobRawClass); | ||
const bob = Bob(8); | ||
t.is(passStyleOf(bob), 'remotable'); | ||
bob.foo(77); | ||
t.throws(() => bob.foo(true), { | ||
message: /^bob.foo: args: \[0\]: boolean true - Must be a number$/, | ||
message: /^Bob.foo: args: \[0\]: boolean true - Must be a number$/, | ||
}); | ||
}); |