this repo has no description
1<!DOCTYPE html>
2<html>
3<head>
4 <meta charset="utf-8">
5 <title>JTW Eval Test</title>
6</head>
7<body>
8 <h1>JTW Eval Test</h1>
9 <div id="status">Loading...</div>
10 <pre id="log"></pre>
11 <script type="module">
12 import { OcamlWorker } from '/client/ocaml-worker.js';
13
14 const status = document.getElementById('status');
15 const logEl = document.getElementById('log');
16
17 function log(msg) {
18 logEl.textContent += msg + '\n';
19 console.log(msg);
20 }
21
22 const params = new URLSearchParams(window.location.search);
23 const universe = params.get('universe');
24 const compilerVersion = params.get('compiler') || '5.4.0';
25
26 if (!universe) {
27 status.textContent = 'Error: ?universe= parameter required';
28 status.dataset.error = 'universe parameter required';
29 throw new Error('universe parameter required');
30 }
31
32 status.textContent = 'Fetching findlib_index.json...';
33 const indexUrl = `/jtw-output/u/${universe}/findlib_index.json`;
34 const { worker, stdlib_dcs, findlib_index } = await OcamlWorker.fromIndex(
35 indexUrl, '/jtw-output', { timeout: 120000 });
36
37 try {
38 status.textContent = 'Initializing...';
39 await worker.init({
40 findlib_requires: [],
41 stdlib_dcs: stdlib_dcs,
42 findlib_index: findlib_index,
43 });
44
45 status.textContent = 'Ready';
46 status.dataset.ready = 'true';
47
48 // Expose eval/complete/require on window for Playwright
49 window.workerEval = async (code) => {
50 const result = await worker.eval(code);
51 return {
52 caml_ppf: result.caml_ppf || '',
53 stdout: result.stdout || '',
54 stderr: result.stderr || '',
55 };
56 };
57
58 window.workerComplete = async (source, pos) => {
59 const result = await worker.complete(source, pos);
60 const entries = result.completions?.entries || [];
61 return entries.map(e => e.name);
62 };
63
64 } catch (err) {
65 status.textContent = 'Error: ' + err.message;
66 status.dataset.error = err.message;
67 log('ERROR: ' + err.message);
68 }
69 </script>
70</body>
71</html>