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

source-academy / js-slang / 24713997105

21 Apr 2026 09:09AM UTC coverage: 78.523% (+0.1%) from 78.391%
24713997105

Pull #1893

github

web-flow
Merge 6359230cf into 1402017f8
Pull Request #1893: Error Handling and Stringify Changes

3115 of 4184 branches covered (74.45%)

Branch coverage included in aggregate %.

793 of 967 new or added lines in 76 files covered. (82.01%)

20 existing lines in 11 files now uncovered.

7049 of 8760 relevant lines covered (80.47%)

173719.17 hits per line

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

81.63
/src/runner/sourceRunner.ts
1
import type { RawSourceMap } from 'source-map';
2

3
import { JSSLANG_PROPERTIES } from '../constants';
4
import { CSEResultPromise, evaluate as CSEvaluate } from '../cse-machine/interpreter';
5
import { ExceptionError } from '../errors/errors';
6
import { TimeoutError } from '../errors/timeoutErrors';
7
import { getSteps } from '../stepper/steppers';
8
import { sandboxedEval } from '../transpiler/evalContainer';
9
import { transpile } from '../transpiler/transpiler';
10
import { SourceErrorWithNode } from '../errors/base';
11
import { toSourceError } from './errors';
12
import fullJSRunner from './fullJSRunner';
13
import type { Runner } from './types';
14

15
let isPreviousCodeTimeoutError = false;
55✔
16
const runners = {
55✔
17
  fulljs: fullJSRunner,
18
  'cse-machine': (program, context, options) => {
19
    const value = CSEvaluate(program, context, options);
935✔
20
    return CSEResultPromise(context, value);
935✔
21
  },
22
  substitution: (program, context, options) => {
23
    const steps = getSteps(program, context, options);
×
24
    if (context.errors.length > 0) {
×
25
      return Promise.resolve({ status: 'error', context });
×
26
    }
27
    return Promise.resolve({
×
28
      status: 'finished',
29
      context,
30
      value: steps,
31
    });
32
  },
33
  native: async (program, context, options) => {
34
    if (!options.isPrelude) {
709✔
35
      if (context.shouldIncreaseEvaluationTimeout && isPreviousCodeTimeoutError) {
412✔
36
        context.nativeStorage.maxExecTime *= JSSLANG_PROPERTIES.factorToIncreaseBy;
3✔
37
      } else {
38
        context.nativeStorage.maxExecTime = options.originalMaxExecTime;
409✔
39
      }
40
    }
41

42
    let sourceMapJson: RawSourceMap | undefined;
43
    try {
709✔
44
      let transpiled: string;
45
      ({ transpiled, sourceMapJson } = transpile(program, context, options.isPrelude));
709✔
46

47
      let value = sandboxedEval(transpiled, context.nativeStorage);
709✔
48

49
      if (!options.isPrelude) {
709✔
50
        isPreviousCodeTimeoutError = false;
345✔
51
      }
52

53
      return {
642✔
54
        status: 'finished',
55
        context,
56
        value,
57
      };
58
    } catch (error) {
59
      if (error instanceof ExceptionError) {
67✔
60
        // if we know the location of the error, just throw it
61
        if (error.location.start.line !== -1) {
9!
UNCOV
62
          context.errors.push(error);
×
UNCOV
63
          return { status: 'error', context };
×
64
        } else {
65
          error = error.error; // else we try to get the location from source map
9✔
66
        }
67
      }
68

69
      if (error instanceof SourceErrorWithNode) {
67✔
70
        if (error instanceof TimeoutError) {
55✔
71
          isPreviousCodeTimeoutError = true;
7✔
72
        }
73

74
        context.errors.push(error);
55✔
75
        return { status: 'error', context };
55✔
76
      }
77

78
      const sourceError = await toSourceError(error, sourceMapJson);
12✔
79
      context.errors.push(sourceError);
12✔
80
      return { status: 'error', context };
12✔
81
    }
82
  },
83
} satisfies Record<string, Runner>;
84

85
export default runners;
86

87
export type RunnerTypes = keyof typeof runners;
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