• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

source-academy / js-slang / 24834367427

23 Apr 2026 12:09PM UTC coverage: 78.541% (+0.2%) from 78.391%
24834367427

Pull #1893

github

web-flow
Merge ab101147d into 715603479
Pull Request #1893: Error Handling and Stringify Changes

3126 of 4197 branches covered (74.48%)

Branch coverage included in aggregate %.

801 of 975 new or added lines in 76 files covered. (82.15%)

20 existing lines in 11 files now uncovered.

7056 of 8767 relevant lines covered (80.48%)

173930.4 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

32.76
/src/stepper/builtins/misc.ts
1
import type { StepperExpression } from '../nodes';
2
import { StepperArrowFunctionExpression } from '../nodes/Expression/ArrowFunctionExpression';
3
import { StepperIdentifier } from '../nodes/Expression/Identifier';
4
import { StepperLiteral } from '../nodes/Expression/Literal';
5
import { GeneralRuntimeError } from '../../errors/base';
6
import { listBuiltinFunctions } from './lists';
7
import { isBuiltinFunction } from '.';
8

9
export const miscBuiltinFunctions = {
56✔
10
  arity: {
11
    definition: (args: StepperExpression[]): StepperExpression => {
12
      if (args[0] instanceof StepperArrowFunctionExpression) {
3!
13
        return new StepperLiteral(args[0].params.length);
×
14
      }
15

16
      if (args[0] instanceof StepperIdentifier) {
3✔
17
        if (args[0].name.startsWith('math_')) {
2!
18
          // Math builtins
19
          const func = Math[args[0].name.split('_')[1] as keyof typeof Math];
×
20
          if (typeof func !== 'function') {
×
NEW
21
            throw new GeneralRuntimeError('arity expects a function as argument');
×
22
          }
23
          return new StepperLiteral(func.length);
×
24
        }
25
        if (args[0].name in listBuiltinFunctions) {
2!
26
          return new StepperLiteral(
×
27
            listBuiltinFunctions[args[0].name as keyof typeof listBuiltinFunctions].arity,
28
          );
29
        }
30

31
        if (args[0].name in miscBuiltinFunctions) {
2!
32
          return new StepperLiteral(
2✔
33
            miscBuiltinFunctions[args[0].name as keyof typeof miscBuiltinFunctions].arity,
34
          );
35
        }
36
      }
37

38
      throw new GeneralRuntimeError('arity expects a function as argument');
1✔
39
    },
40
    arity: 1,
41
  },
42
  char_at: {
43
    definition: (args: StepperExpression[]): StepperExpression => {
44
      const str = (args[0] as StepperLiteral).value as string;
×
45
      const index = (args[1] as StepperLiteral).value as number;
×
46
      return new StepperLiteral(str.charAt(index));
×
47
    },
48
    arity: 2,
49
  },
50
  display: {
51
    definition: (args: StepperExpression[]): StepperExpression => {
52
      return args[0];
×
53
    },
54
    arity: 1,
55
  },
56
  error: {
57
    definition: (args: StepperExpression[]): StepperExpression => {
58
      const errorMessage = (args[0] as StepperLiteral).value as string;
×
59
      throw new Error(errorMessage);
×
60
    },
61
    arity: 1,
62
  },
63
  get_time: {
64
    definition: (_args: StepperExpression[]): StepperExpression => {
65
      return new StepperLiteral(Date.now());
×
66
    },
67
    arity: 0,
68
  },
69
  is_boolean: {
70
    definition: (args: StepperExpression[]): StepperExpression => {
71
      return new StepperLiteral(typeof (args[0] as StepperLiteral).value === 'boolean');
×
72
    },
73
    arity: 1,
74
  },
75
  is_function: {
76
    definition: (args: StepperExpression[]): StepperExpression => {
77
      return new StepperLiteral(
1✔
78
        args[0] instanceof StepperArrowFunctionExpression ||
3✔
79
          (args[0] instanceof StepperIdentifier && isBuiltinFunction(args[0].name)),
80
      );
81
    },
82
    arity: 1,
83
  },
84
  is_number: {
85
    definition: (args: StepperExpression[]): StepperExpression => {
86
      return new StepperLiteral(typeof (args[0] as StepperLiteral).value === 'number');
30✔
87
    },
88
    arity: 1,
89
  },
90
  is_string: {
91
    definition: (args: StepperExpression[]): StepperExpression => {
92
      return new StepperLiteral(typeof (args[0] as StepperLiteral).value === 'string');
×
93
    },
94
    arity: 1,
95
  },
96
  is_undefined: {
97
    definition: (args: StepperExpression[]): StepperExpression => {
98
      return new StepperLiteral((args[0] as StepperLiteral).value === undefined);
×
99
    },
100
    arity: 1,
101
  },
102
  parse_int: {
103
    definition: (args: StepperExpression[]): StepperExpression => {
104
      const str = (args[0] as StepperLiteral).value as string;
×
105
      const radix = args.length > 1 ? ((args[1] as StepperLiteral).value as number) : 10;
×
106
      return new StepperLiteral(parseInt(str, radix));
×
107
    },
108
    arity: 2,
109
  },
110
  prompt: {
111
    definition: (args: StepperExpression[]): StepperExpression => {
112
      const message = (args[0] as StepperLiteral).value as string;
×
113
      const result = window.prompt(message);
×
114
      return new StepperLiteral(result !== null ? result : null);
×
115
    },
116
    arity: 0,
117
  },
118
  stringify: {
119
    definition: (args: StepperExpression[]): StepperExpression => {
120
      const value = args[0];
×
121
      let stringified;
122

123
      if (value instanceof StepperLiteral) {
×
124
        stringified = JSON.stringify(value.value);
×
125
      } else {
126
        stringified = value.toString();
×
127
      }
128

129
      return new StepperLiteral(stringified);
×
130
    },
131
    arity: 1,
132
  },
133
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc