Skip to content

Commit

Permalink
Fix null parameter message - #268
Browse files Browse the repository at this point in the history
  • Loading branch information
fdodino committed Oct 21, 2024
1 parent ed6d69b commit e541607
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/wre/lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,24 +421,28 @@ const lang: Natives = {
},

*['+'](self: RuntimeObject, other: RuntimeObject): Execution<RuntimeValue> {
other.assertIsNotNull('other')
other.assertIsNumber()

return yield* this.reify(self.innerNumber! + other.innerNumber)
},

*['-'](self: RuntimeObject, other: RuntimeObject): Execution<RuntimeValue> {
other.assertIsNotNull('other')
other.assertIsNumber()

return yield* this.reify(self.innerNumber! - other.innerNumber)
},

*['*'](self: RuntimeObject, other: RuntimeObject): Execution<RuntimeValue> {
other.assertIsNotNull('other')
other.assertIsNumber()

return yield* this.reify(self.innerNumber! * other.innerNumber)
},

*['/'](self: RuntimeObject, other: RuntimeObject): Execution<RuntimeValue> {
other.assertIsNotNull('other')
other.assertIsNumber()

if (other.innerNumber === 0) throw new RangeError('other')
Expand All @@ -447,12 +451,14 @@ const lang: Natives = {
},

*['**'](self: RuntimeObject, other: RuntimeObject): Execution<RuntimeValue> {
other.assertIsNotNull('other')
other.assertIsNumber()

return yield* this.reify(self.innerNumber! ** other.innerNumber)
},

*['%'](self: RuntimeObject, other: RuntimeObject): Execution<RuntimeValue> {
other.assertIsNotNull('other')
other.assertIsNumber()

return yield* this.reify(self.innerNumber! % other.innerNumber)
Expand All @@ -463,12 +469,14 @@ const lang: Natives = {
},

*['>'](self: RuntimeObject, other: RuntimeObject): Execution<RuntimeValue> {
other.assertIsNotNull('other')
other.assertIsNumber()

return yield* this.reify(self.innerNumber! > other.innerNumber)
},

*['<'](self: RuntimeObject, other: RuntimeObject): Execution<RuntimeValue> {
other.assertIsNotNull('other')
other.assertIsNumber()

return yield* this.reify(self.innerNumber! < other.innerNumber)
Expand All @@ -483,6 +491,7 @@ const lang: Natives = {
},

*roundUp(self: RuntimeObject, decimals: RuntimeObject): Execution<RuntimeValue> {
decimals.assertIsNotNull('decimals')
decimals.assertIsNumber()

if (decimals.innerNumber! < 0) throw new RangeError('decimals')
Expand All @@ -491,6 +500,7 @@ const lang: Natives = {
},

*truncate(self: RuntimeObject, decimals: RuntimeObject): Execution<RuntimeValue> {
decimals.assertIsNotNull('decimals')
decimals.assertIsNumber()

if (decimals.innerNumber < 0) throw new RangeError('decimals')
Expand All @@ -503,6 +513,7 @@ const lang: Natives = {
},

*randomUpTo(self: RuntimeObject, other: RuntimeObject): Execution<RuntimeValue> {
other.assertIsNotNull('other')
other.assertIsNumber()
return yield* this.reify(random() * (other.innerNumber! - self.innerNumber!) + self.innerNumber!)
},
Expand All @@ -512,6 +523,7 @@ const lang: Natives = {
},

*gcd(self: RuntimeObject, other: RuntimeObject): Execution<RuntimeValue> {
other.assertIsNotNull('other')
other.assertIsNumber()

const gcd = (a: number, b: number): number => b === 0 ? a : gcd(b, a % b)
Expand All @@ -533,6 +545,7 @@ const lang: Natives = {
},

*concat(self: RuntimeObject, other: RuntimeObject): Execution<RuntimeValue> {
other.assertIsNotNull('other')
return yield* this.reify(self.innerString! + (yield * this.send(TO_STRING_METHOD, other))!.innerString!)
},

Expand Down

0 comments on commit e541607

Please sign in to comment.