Skip to content

Commit

Permalink
assertIsNotNull enhanced + RangeErrors from runtimeModel enhanced
Browse files Browse the repository at this point in the history
  • Loading branch information
fdodino committed Oct 22, 2024
1 parent 93d85fc commit 6e42388
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 64 deletions.
4 changes: 2 additions & 2 deletions src/interpreter/runtimeModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ export class RuntimeObject extends Context {
}
}

assertIsNotNull(variableName?: string): asserts this is BasicRuntimeObject<Exclude<InnerValue, null>> {
if (this.innerValue === null) throw new RangeError(`${variableName ?? 'Object'} was not expected to be null`)
assertIsNotNull(message: string, variableName: string): asserts this is BasicRuntimeObject<Exclude<InnerValue, null>> {
if (this.innerValue === null) throw new RangeError(`${message}: ${variableName ?? 'parameter'} was not expected to be null`)
}

protected assertIs(moduleFQN: Name, innerValue?: InnerValue): void {
Expand Down
4 changes: 2 additions & 2 deletions src/wre/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { round } = Math
const game: Natives = {
game: {
*addVisual(self: RuntimeObject, visual: RuntimeObject): Execution<void> {
visual.assertIsNotNull()
visual.assertIsNotNull('addVisual', 'visual')
if (!visual.module.lookupMethod('position', 0)) throw new TypeError('position')

const visuals = self.get('visuals')!.innerCollection!
Expand Down Expand Up @@ -71,7 +71,7 @@ const game: Natives = {
},

*colliders(self: RuntimeObject, visual: RuntimeObject): Execution<RuntimeValue> {
visual.assertIsNotNull()
visual.assertIsNotNull('colliders', 'visual')

const position = (yield* this.send('position', visual))!
const visualsAtPosition: RuntimeObject = (yield* this.send('getObjectsIn', self, position))!
Expand Down
Loading

0 comments on commit 6e42388

Please sign in to comment.